Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schema dump for hypertables partitioned with integer chunk time interval #67

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading