Skip to content

Commit 25224db

Browse files
authored
Merge pull request #128 from stevehill1981/fix/remove-finalized-parameter-from-schema-dump
Remove finalized parameter from schema dump and CREATE statement
2 parents 821c5a1 + 2e6d9bc commit 25224db

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

lib/timescaledb/migration_helpers.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def create_hypertable(table_name,
8484
# @option refresh_policies [String] schedule_interval: INTERVAL
8585
# @option materialized_only [Boolean] Override the WITH clause 'timescaledb.materialized_only'
8686
# @option create_group_indexes [Boolean] Override the WITH clause 'timescaledb.create_group_indexes'
87-
# @option finalized [Boolean] Override the WITH clause 'timescaledb.finalized'
87+
# @option finalized [Boolean] Set to false for legacy (non-finalized) format. Note: the finalized
88+
# parameter was removed in TimescaleDB 2.14+ where all aggregates are finalized by default.
89+
# Only use finalized: false on TimescaleDB 2.7-2.13 for legacy compatibility.
8890
#
8991
# @see https://docs.timescale.com/api/latest/continuous-aggregates/create_materialized_view/
9092
# @see https://docs.timescale.com/api/latest/continuous-aggregates/add_continuous_aggregate_policy/
@@ -99,13 +101,17 @@ def create_hypertable(table_name,
99101
# SQL
100102
#
101103
def create_continuous_aggregate(table_name, query, **options)
104+
# Only include finalized when explicitly false (legacy format).
105+
# The parameter was removed in TimescaleDB 2.14+ where all aggregates are finalized by default.
106+
finalized_clause = options[:finalized] == false ? ",timescaledb.finalized=false" : ""
107+
102108
execute <<~SQL
103109
CREATE MATERIALIZED VIEW #{table_name}
104110
WITH (
105111
timescaledb.continuous
106112
#{build_with_clause_option_string(:materialized_only, options)}
107113
#{build_with_clause_option_string(:create_group_indexes, options)}
108-
#{build_with_clause_option_string(:finalized, options)}
114+
#{finalized_clause}
109115
) AS
110116
#{query.respond_to?(:to_sql) ? query.to_sql : query}
111117
WITH #{'NO' unless options[:with_data]} DATA;

lib/timescaledb/schema_dumper.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ def timescale_continuous_aggregates(stream)
162162
""
163163
end
164164

165-
with_clause_opts = "materialized_only: #{aggregate[:materialized_only]}, finalized: #{aggregate[:finalized]}"
165+
# Only output finalized when false (legacy format) - the parameter was
166+
# removed in TimescaleDB 2.14+ where all aggregates are finalized by default
167+
with_clause_opts = "materialized_only: #{aggregate[:materialized_only]}"
168+
with_clause_opts += ", finalized: false" if aggregate[:finalized] == false
166169
stream.puts <<~AGG.indent(2)
167170
create_continuous_aggregate("#{aggregate.view_name}", <<-SQL, #{refresh_policies_opts}#{with_clause_opts})
168171
#{aggregate.view_definition.strip.gsub(/;$/, '')}

spec/timescaledb/migration_helper_spec.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@
136136
let(:options) do
137137
{
138138
materialized_only: true,
139-
create_group_indexes: true,
140-
finalized: true
139+
create_group_indexes: true
141140
}
142141
end
143142

@@ -178,15 +177,32 @@
178177
end
179178

180179
context 'when overriding WITH clause timescaledb.finalized' do
180+
# finalized: true is no longer output (deprecated in TimescaleDB 2.14+)
181+
# Only finalized: false is output for legacy compatibility with 2.7-2.13
181182
let(:options) do
182183
{
183-
finalized: true
184+
finalized: false
184185
}
185186
end
186187

187188
specify do
189+
skip "TimescaleDB 2.14+ no longer supports partial (non-finalized) continuous aggregates" if Gem::Version.new(Timescaledb.extension.version) >= Gem::Version.new("2.14")
190+
191+
create_caggs
192+
expect(ActiveRecord::Base.connection).to have_received(:execute).with(include('timescaledb.finalized=false'))
193+
end
194+
end
195+
196+
context 'when finalized: true (default)' do
197+
let(:options) do
198+
{
199+
finalized: true
200+
}
201+
end
202+
203+
specify 'does not include finalized parameter' do
188204
create_caggs
189-
expect(ActiveRecord::Base.connection).to have_received(:execute).with(include('timescaledb.finalized=true'))
205+
expect(ActiveRecord::Base.connection).not_to have_received(:execute).with(include('timescaledb.finalized'))
190206
end
191207
end
192208
end

spec/timescaledb/schema_dumper_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696
dump = dump_output
9797

9898
expect(dump).to include 'create_continuous_aggregate("event_counts"'
99-
expect(dump).to include 'materialized_only: true, finalized: true'
99+
# finalized: true is no longer output (deprecated in TimescaleDB 2.14+)
100+
expect(dump).to include 'materialized_only: true'
101+
expect(dump).not_to include 'finalized: true'
100102

101103
expect(dump).not_to include ', ,'
102104
expect(dump).not_to include 'create_view "event_counts"' # Verify Scenic ignored this view

0 commit comments

Comments
 (0)