Skip to content

Commit

Permalink
Fix schema dumping for hypertables partitioned with integer chunk tim…
Browse files Browse the repository at this point in the history
…e interval (#67)
  • Loading branch information
spohlenz authored Jul 8, 2024
1 parent f1ac73b commit 88c5cfa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/timescaledb/migration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_hypertable(table_name,
original_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = Logger.new(STDOUT)

options = ["chunk_time_interval => INTERVAL '#{chunk_time_interval}'"]
options = ["chunk_time_interval => #{chunk_time_interval_clause(chunk_time_interval)}"]
options += hypertable_options.map { |k, v| "#{k} => #{quote(v)}" }

arguments = [
Expand Down Expand Up @@ -165,6 +165,14 @@ def build_with_clause_option_string(option_key, options)
value = options[option_key] ? 'true' : 'false'
",timescaledb.#{option_key}=#{value}"
end

def chunk_time_interval_clause(chunk_time_interval)
if chunk_time_interval.is_a?(Numeric)
chunk_time_interval
else
"INTERVAL '#{chunk_time_interval}'"
end
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/timescaledb/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def timescale_hypertable(hypertable, stream)

options = {
time_column: time.column_name,
chunk_time_interval: time.time_interval.inspect,
chunk_time_interval: time.time_interval ? time.time_interval.inspect : time.integer_interval,
**timescale_compression_settings_for(hypertable),
**timescale_space_partition_for(hypertable),
**timescale_index_options_for(hypertable)
Expand Down
5 changes: 5 additions & 0 deletions spec/support/active_record/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def setup_tables
options: { time_column: 'timestamp' }
)

create_table(:hypertable_with_id_partitioning, hypertable: {
time_column: 'id',
chunk_time_interval: 1_000_000
})

create_table(:non_hypertables) do |t|
t.string :name
end
Expand Down
11 changes: 11 additions & 0 deletions spec/timescaledb/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
expect(dump).to include "create_default_indexes: false"
end

it "extracts integer chunk_time_interval" do
options = { time_column: :id, chunk_time_interval: 10000 }
con.create_table :schema_tests, hypertable: options do |t|
t.timestamps
end

dump = dump_output

expect(dump).to include "chunk_time_interval: 10000"
end

context "compress_segmentby" do
before(:each) do
con.drop_table :segmentby_tests, force: :cascade if con.table_exists?(:segmentby_tests)
Expand Down

0 comments on commit 88c5cfa

Please sign in to comment.