Module: Timescaledb::Database::SchemaStatements
- Included in:
- Timescaledb::Database
- Defined in:
- lib/timescaledb/database/schema_statements.rb
Instance Method Summary collapse
-
#add_compression_policy_sql(hypertable, compress_after, **options) ⇒ String
The add_compression_policy SQL statement.
-
#add_continuous_aggregate_policy_sql(continuous_aggregate, start_offset: nil, end_offset: nil, schedule_interval:, **options) ⇒ String
The add_continuous_aggregate_policy SQL statement.
-
#add_reorder_policy_sql(hypertable, index_name, **options) ⇒ String
The add_reorder_policy SQL statement.
-
#add_retention_policy_sql(hypertable, drop_after, **options) ⇒ String
The add_retention_policy SQL statement.
-
#create_continuous_aggregate_sql(continuous_aggregate, sql, **options) ⇒ String
The create materialized view SQL statement.
-
#create_hypertable_sql(relation, time_column_name, **options) ⇒ String
The create_hypertable SQL statement.
-
#disable_hypertable_compression_sql(hypertable) ⇒ String
The ALTER TABLE SQL to disable compression.
-
#drop_continuous_aggregate_sql(continuous_aggregate, cascade: false) ⇒ String
The drop materialized view SQL statement.
-
#enable_hypertable_compression_sql(hypertable, **options) ⇒ String
The ALTER TABLE SQL to enable compression.
-
#remove_compression_policy_sql(hypertable, **options) ⇒ String
The remove_compression_policy SQL statement.
-
#remove_continuous_aggregate_policy_sql(continuous_aggregate, **options) ⇒ String
The remove_continuous_aggregate_policy SQL statement.
-
#remove_reorder_policy_sql(hypertable, **options) ⇒ String
The remove_retention_policy SQL statement.
-
#remove_retention_policy_sql(hypertable, **options) ⇒ String
The remove_retention_policy SQL statement.
Instance Method Details
#add_compression_policy_sql(hypertable, compress_after, **options) ⇒ String
Returns The add_compression_policy SQL statement.
55 56 57 58 59 60 61 62 |
# File 'lib/timescaledb/database/schema_statements.rb', line 55 def add_compression_policy_sql(hypertable, compress_after, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable), interval_to_sql(compress_after)] arguments += () "SELECT add_compression_policy(#{arguments.join(', ')});" end |
#add_continuous_aggregate_policy_sql(continuous_aggregate, start_offset: nil, end_offset: nil, schedule_interval:, **options) ⇒ String
Returns The add_continuous_aggregate_policy SQL statement.
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/timescaledb/database/schema_statements.rb', line 175 def add_continuous_aggregate_policy_sql(continuous_aggregate, start_offset: nil, end_offset: nil, schedule_interval:, **) .transform_keys!(&:to_sym) arguments = [quote(continuous_aggregate)] arguments << named_notation_sql(name: :start_offset, value: interval_to_sql(start_offset)) arguments << named_notation_sql(name: :end_offset, value: interval_to_sql(end_offset)) arguments << named_notation_sql(name: :schedule_interval, value: interval_to_sql(schedule_interval)) arguments += () "SELECT add_continuous_aggregate_policy(#{arguments.join(', ')});" end |
#add_reorder_policy_sql(hypertable, index_name, **options) ⇒ String
Returns The add_reorder_policy SQL statement.
113 114 115 116 117 118 119 120 |
# File 'lib/timescaledb/database/schema_statements.rb', line 113 def add_reorder_policy_sql(hypertable, index_name, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable), quote(index_name)] arguments += () "SELECT add_reorder_policy(#{arguments.join(', ')});" end |
#add_retention_policy_sql(hypertable, drop_after, **options) ⇒ String
Returns The add_retention_policy SQL statement.
84 85 86 87 88 89 90 91 |
# File 'lib/timescaledb/database/schema_statements.rb', line 84 def add_retention_policy_sql(hypertable, drop_after, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable), interval_to_sql(drop_after)] arguments += () "SELECT add_retention_policy(#{arguments.join(', ')});" end |
#create_continuous_aggregate_sql(continuous_aggregate, sql, **options) ⇒ String
Returns The create materialized view SQL statement.
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/timescaledb/database/schema_statements.rb', line 141 def create_continuous_aggregate_sql(continuous_aggregate, sql, **) .transform_keys!(&:to_sym) with_data_opts = %w[WITH DATA] with_data_opts.insert(1, 'NO') if .key?(:with_no_data) <<~SQL CREATE MATERIALIZED VIEW #{continuous_aggregate} WITH (timescaledb.continuous) AS #{sql.strip} #{with_data_opts.join(' ')}; SQL end |
#create_hypertable_sql(relation, time_column_name, **options) ⇒ String
Returns The create_hypertable SQL statement.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/timescaledb/database/schema_statements.rb', line 10 def create_hypertable_sql(relation, time_column_name, **) .transform_keys!(&:to_sym) partitioning_column = .delete(:partitioning_column) number_partitions = .delete(:number_partitions) arguments = [quote(relation), quote(time_column_name)] arguments += [quote(partitioning_column), number_partitions] if partitioning_column && number_partitions arguments += () "SELECT create_hypertable(#{arguments.join(', ')});" end |
#disable_hypertable_compression_sql(hypertable) ⇒ String
Returns The ALTER TABLE SQL to disable compression.
45 46 47 |
# File 'lib/timescaledb/database/schema_statements.rb', line 45 def disable_hypertable_compression_sql(hypertable) "ALTER TABLE #{hypertable} SET (timescaledb.compress = FALSE);" end |
#drop_continuous_aggregate_sql(continuous_aggregate, cascade: false) ⇒ String
Returns The drop materialized view SQL statement.
160 161 162 163 164 165 |
# File 'lib/timescaledb/database/schema_statements.rb', line 160 def drop_continuous_aggregate_sql(continuous_aggregate, cascade: false) arguments = [continuous_aggregate] arguments << 'CASCADE' if cascade "DROP MATERIALIZED VIEW #{arguments.join(' ')};" end |
#enable_hypertable_compression_sql(hypertable, **options) ⇒ String
Returns The ALTER TABLE SQL to enable compression.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/timescaledb/database/schema_statements.rb', line 28 def enable_hypertable_compression_sql(hypertable, **) .transform_keys!(&:to_sym) compress_orderby = .delete(:compress_orderby) compress_segmentby = .delete(:compress_segmentby) arguments = ['timescaledb.compress'] arguments << "timescaledb.compress_orderby = #{quote(compress_orderby)}" if compress_orderby arguments << "timescaledb.compress_segmentby = #{quote(compress_segmentby)}" if compress_segmentby "ALTER TABLE #{hypertable} SET (#{arguments.join(', ')});" end |
#remove_compression_policy_sql(hypertable, **options) ⇒ String
Returns The remove_compression_policy SQL statement.
69 70 71 72 73 74 75 76 |
# File 'lib/timescaledb/database/schema_statements.rb', line 69 def remove_compression_policy_sql(hypertable, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable)] arguments += () "SELECT remove_compression_policy(#{arguments.join(', ')});" end |
#remove_continuous_aggregate_policy_sql(continuous_aggregate, **options) ⇒ String
Returns The remove_continuous_aggregate_policy SQL statement.
192 193 194 195 196 197 198 199 |
# File 'lib/timescaledb/database/schema_statements.rb', line 192 def remove_continuous_aggregate_policy_sql(continuous_aggregate, **) .transform_keys!(&:to_sym) arguments = [quote(continuous_aggregate)] arguments += () "SELECT remove_continuous_aggregate_policy(#{arguments.join(', ')});" end |
#remove_reorder_policy_sql(hypertable, **options) ⇒ String
Returns The remove_retention_policy SQL statement.
127 128 129 130 131 132 133 134 |
# File 'lib/timescaledb/database/schema_statements.rb', line 127 def remove_reorder_policy_sql(hypertable, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable)] arguments += () "SELECT remove_reorder_policy(#{arguments.join(', ')});" end |
#remove_retention_policy_sql(hypertable, **options) ⇒ String
Returns The remove_retention_policy SQL statement.
98 99 100 101 102 103 104 105 |
# File 'lib/timescaledb/database/schema_statements.rb', line 98 def remove_retention_policy_sql(hypertable, **) .transform_keys!(&:to_sym) arguments = [quote(hypertable)] arguments += () "SELECT remove_retention_policy(#{arguments.join(', ')});" end |