1111END;
1212$$;
1313
14- -- Drop obsolete chunk_constraint rows for inherited CHECK constraints on
15- -- OSM chunks; PG inheritance handles propagation now.
16- DELETE FROM _timescaledb_catalog .chunk_constraint cc
17- USING _timescaledb_catalog .chunk c
18- WHERE cc .chunk_id = c .id
19- AND c .osm_chunk
20- AND cc .dimension_slice_id IS NULL
21- AND cc .hypertable_constraint_name IS NOT NULL
22- AND cc .constraint_name = cc .hypertable_constraint_name ;
23-
2414-- Rename legacy chunk-side constraints to the names the new code recomputes:
2515-- FKs use the parent's name; unique/PK/exclusion/trigger use the deterministic
2616-- "<chunk_id>_<parent>" form
5242END
5343$$;
5444
55- -- Remove the chunk_constraint rows that mirrored non-dimensional constraints.
56- -- FK chunk-side constraints are now located by name through the event-trigger
57- -- hooks; unique/PK/exclusion/trigger constraints through the deterministic
58- -- "<chunk_id>_<parent>" name pattern.
59- DELETE FROM _timescaledb_catalog .chunk_constraint
60- WHERE dimension_slice_id IS NULL
61- AND hypertable_constraint_name IS NOT NULL ;
62-
6345ALTER TABLE _timescaledb_catalog .hypertable SET (user_catalog_table = true);
6446ALTER TABLE _timescaledb_catalog .chunk SET (user_catalog_table = true);
6547
@@ -72,8 +54,6 @@ CREATE TABLE _timescaledb_internal.tmp_dimension_slice_seq_value AS
7254ALTER TABLE _timescaledb_catalog .chunk_constraint
7355 DROP CONSTRAINT IF EXISTS chunk_constraint_dimension_slice_id_fkey;
7456
75- DROP VIEW IF EXISTS timescaledb_information .chunks ;
76-
7757ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog .dimension_slice;
7858ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog .dimension_slice_id_seq ;
7959
@@ -163,7 +143,6 @@ DROP FUNCTION _timescaledb_functions.chunk_constraint_add_table_constraint(
163143 _timescaledb_catalog .chunk_constraint );
164144DROP FUNCTION IF EXISTS _timescaledb_internal .chunk_constraint_add_table_constraint (
165145 _timescaledb_catalog .chunk_constraint );
166- DROP VIEW IF EXISTS timescaledb_information .chunks ;
167146
168147ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog .chunk_constraint;
169148ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog .chunk_constraint_name ;
@@ -181,3 +160,100 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.calculate_chunk_interval(integer,
181160-- chunk_target_size is no longer used, so its check constraint is dropped.
182161ALTER TABLE _timescaledb_catalog .hypertable
183162 DROP CONSTRAINT IF EXISTS hypertable_chunk_target_size_check;
163+
164+ -- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` to add the
165+ -- `schema_change_timestamp` column.
166+
167+ -- Drop views and foreign keys that depend on the catalog table.
168+ DROP VIEW IF EXISTS timescaledb_experimental .policies ;
169+
170+ ALTER TABLE _timescaledb_catalog .continuous_aggs_watermark
171+ DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey;
172+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_invalidation_log
173+ DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey;
174+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_ranges
175+ DROP CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey;
176+ ALTER TABLE _timescaledb_catalog .continuous_aggs_jobs_refresh_ranges
177+ DROP CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey;
178+
179+ ALTER EXTENSION timescaledb
180+ DROP TABLE _timescaledb_catalog .continuous_agg ;
181+
182+ CREATE TABLE _timescaledb_catalog ._tmp_continuous_agg AS
183+ SELECT
184+ mat_hypertable_id,
185+ raw_hypertable_id,
186+ parent_mat_hypertable_id,
187+ user_view_schema,
188+ user_view_name,
189+ partial_view_schema,
190+ partial_view_name,
191+ direct_view_schema,
192+ direct_view_name,
193+ materialized_only
194+ FROM
195+ _timescaledb_catalog .continuous_agg
196+ ORDER BY
197+ mat_hypertable_id;
198+
199+ DROP TABLE _timescaledb_catalog .continuous_agg ;
200+
201+ CREATE TABLE _timescaledb_catalog .continuous_agg (
202+ mat_hypertable_id integer NOT NULL ,
203+ raw_hypertable_id integer NOT NULL ,
204+ parent_mat_hypertable_id integer ,
205+ user_view_schema name NOT NULL ,
206+ user_view_name name NOT NULL ,
207+ partial_view_schema name NOT NULL ,
208+ partial_view_name name NOT NULL ,
209+ direct_view_schema name NOT NULL ,
210+ direct_view_name name NOT NULL ,
211+ materialized_only bool NOT NULL DEFAULT FALSE,
212+ schema_change_timestamp bigint ,
213+ -- table constraints
214+ CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id),
215+ CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name),
216+ CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name),
217+ CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog .hypertable (id) ON DELETE CASCADE ,
218+ CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog .hypertable (id) ON DELETE CASCADE ,
219+ CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey FOREIGN KEY (parent_mat_hypertable_id)
220+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE
221+ );
222+
223+ INSERT INTO _timescaledb_catalog .continuous_agg
224+ (mat_hypertable_id, raw_hypertable_id, parent_mat_hypertable_id, user_view_schema,
225+ user_view_name, partial_view_schema, partial_view_name, direct_view_schema,
226+ direct_view_name, materialized_only)
227+ SELECT * FROM _timescaledb_catalog ._tmp_continuous_agg ;
228+ DROP TABLE _timescaledb_catalog ._tmp_continuous_agg ;
229+
230+ CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog .continuous_agg (raw_hypertable_id);
231+
232+ SELECT pg_catalog .pg_extension_config_dump (' _timescaledb_catalog.continuous_agg' , ' ' );
233+
234+ GRANT SELECT ON TABLE _timescaledb_catalog .continuous_agg TO PUBLIC;
235+
236+ ALTER TABLE _timescaledb_catalog .continuous_aggs_watermark
237+ ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey
238+ FOREIGN KEY (mat_hypertable_id)
239+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
240+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_invalidation_log
241+ ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey
242+ FOREIGN KEY (materialization_id)
243+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
244+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_ranges
245+ ADD CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey
246+ FOREIGN KEY (materialization_id)
247+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
248+ ALTER TABLE _timescaledb_catalog .continuous_aggs_jobs_refresh_ranges
249+ ADD CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey
250+ FOREIGN KEY (materialization_id)
251+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
252+
253+ ANALYZE _timescaledb_catalog .continuous_agg ;
254+ -- end rebuild _timescaledb_catalog.continuous_agg --
255+
256+ -- drop telemetry_event
257+ ALTER EXTENSION timescaledb DROP TABLE _timescaledb_catalog .telemetry_event;
258+ DROP TABLE _timescaledb_catalog .telemetry_event ;
259+
0 commit comments