Module: Footing::PGSchemaStatements
- Defined in:
- lib/extensions/schema_statements.rb
Instance Method Summary collapse
-
#add_timestamp_indexes(table_name) ⇒ Object
Adds indexes to the created_at and updated_at timestamp columns with ‘day’ granularity.
-
#remove_timestamp_indexes(table_name) ⇒ Object
Removes indexes to the created_at and updated_at timestamp columns with ‘day’ granularity.
Instance Method Details
#add_timestamp_indexes(table_name) ⇒ Object
Adds indexes to the created_at and updated_at timestamp columns with ‘day’ granularity. This method is available to ActiveRecord::Migration change, up, down methods.
14 15 16 17 18 19 |
# File 'lib/extensions/schema_statements.rb', line 14 def (table_name) %w(created_at updated_at).each do |column_name| name = "index_#{table_name}_on_#{column_name}" execute "create index #{name} on #{quote_table_name(table_name)} (date_trunc('day', #{quote_column_name(column_name)}))" end end |
#remove_timestamp_indexes(table_name) ⇒ Object
Removes indexes to the created_at and updated_at timestamp columns with ‘day’ granularity. This method is available to ActiveRecord::Migration change, up, down methods.
23 24 25 26 27 28 |
# File 'lib/extensions/schema_statements.rb', line 23 def (table_name) %w(created_at updated_at).each do |column_name| name = "index_#{table_name}_on_#{column_name}" execute "drop index if exists #{name}" end end |