Module: ActiveRecord::Timescale::SchemaMigration
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_record/timescale/schema_migration.rb
Defined Under Namespace
Classes: HyperTableOptions
Instance Method Summary collapse
- #add_retention_policy(relation, drop_after:, if_not_exists: false) ⇒ Object
-
#create_distributed_hyper_table(relation, **options, &block) ⇒ Object
See create_hyper_table for examples.
-
#create_hyper_table(relation, time_column_name: "created_at", **options, &block) ⇒ Object
Create a Hypertable from a postgres table An existing table can be used or, if given a block, a new table will be created.
Instance Method Details
#add_retention_policy(relation, drop_after:, if_not_exists: false) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/active_record/timescale/schema_migration.rb', line 57 def add_retention_policy(relation, drop_after:, if_not_exists: false) drop_after_string = if drop_after.is_a? String "INTERVAL '#{drop_after}'" else "BIGINT '#{drop_after}'" end args = [] args << quote_table_name(relation) args << drop_after_string args << "if_not_exists => TRUE" if if_not_exists execute "SELECT add_retention_policy(#{args.join(", ")})" end |
#create_distributed_hyper_table(relation, **options, &block) ⇒ Object
See create_hyper_table for examples. Works exactly the same but the distributed option is forced to TRUE
50 51 52 |
# File 'lib/active_record/timescale/schema_migration.rb', line 50 def create_distributed_hyper_table(relation, **, &block) create_hyper_table(relation, **.merge({distributed: true}), &block) end |
#create_hyper_table(relation, time_column_name: "created_at", **options, &block) ⇒ Object
Create a Hypertable from a postgres table An existing table can be used or, if given a block, a new table will be created.
Examples:
create_hyper_table :check_ins, time_column_name: ‘checked_in_at’, id: false do |t|
t.references :user
t.datetime :checked_in_at, null: false, index: true
t.
end
# check_ins table already exists create_hyper_table :check_ins, time_column_name: ‘checked_in_at’, migrate_data: true
# Simplest example create_hyper_table :check_ins
43 44 45 46 47 |
# File 'lib/active_record/timescale/schema_migration.rb', line 43 def create_hyper_table(relation, time_column_name: "created_at", **, &block) = HyperTableOptions.new(**) create_table(relation, **.args, &block) unless block.nil? execute "SELECT create_hyper_table(#{quote_table_name(relation)}, #{quote_column_name(time_column_name)}, #{.to_sql})" end |