@@ -181,3 +181,98 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.calculate_chunk_interval(integer,
181181-- chunk_target_size is no longer used, so its check constraint is dropped.
182182ALTER TABLE _timescaledb_catalog .hypertable
183183 DROP CONSTRAINT IF EXISTS hypertable_chunk_target_size_check;
184+
185+ -- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` to add the
186+ -- `schema_change_timestamp` column.
187+
188+ -- Drop views and foreign keys that depend on the catalog table.
189+ DROP VIEW IF EXISTS timescaledb_experimental .policies ;
190+ DROP VIEW IF EXISTS timescaledb_information .hypertables ;
191+ DROP VIEW IF EXISTS timescaledb_information .continuous_aggregates ;
192+ DROP VIEW IF EXISTS timescaledb_information .jobs ;
193+
194+ ALTER TABLE _timescaledb_catalog .continuous_aggs_watermark
195+ DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey;
196+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_invalidation_log
197+ DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey;
198+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_ranges
199+ DROP CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey;
200+ ALTER TABLE _timescaledb_catalog .continuous_aggs_jobs_refresh_ranges
201+ DROP CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey;
202+
203+ ALTER EXTENSION timescaledb
204+ DROP TABLE _timescaledb_catalog .continuous_agg ;
205+
206+ CREATE TABLE _timescaledb_catalog ._tmp_continuous_agg AS
207+ SELECT
208+ mat_hypertable_id,
209+ raw_hypertable_id,
210+ parent_mat_hypertable_id,
211+ user_view_schema,
212+ user_view_name,
213+ partial_view_schema,
214+ partial_view_name,
215+ direct_view_schema,
216+ direct_view_name,
217+ materialized_only
218+ FROM
219+ _timescaledb_catalog .continuous_agg
220+ ORDER BY
221+ mat_hypertable_id;
222+
223+ DROP TABLE _timescaledb_catalog .continuous_agg ;
224+
225+ CREATE TABLE _timescaledb_catalog .continuous_agg (
226+ mat_hypertable_id integer NOT NULL ,
227+ raw_hypertable_id integer NOT NULL ,
228+ parent_mat_hypertable_id integer ,
229+ user_view_schema name NOT NULL ,
230+ user_view_name name NOT NULL ,
231+ partial_view_schema name NOT NULL ,
232+ partial_view_name name NOT NULL ,
233+ direct_view_schema name NOT NULL ,
234+ direct_view_name name NOT NULL ,
235+ materialized_only bool NOT NULL DEFAULT FALSE,
236+ schema_change_timestamp bigint ,
237+ -- table constraints
238+ CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id),
239+ CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name),
240+ CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name),
241+ CONSTRAINT continuous_agg_mat_hypertable_id_fkey FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog .hypertable (id) ON DELETE CASCADE ,
242+ CONSTRAINT continuous_agg_raw_hypertable_id_fkey FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog .hypertable (id) ON DELETE CASCADE ,
243+ CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey FOREIGN KEY (parent_mat_hypertable_id)
244+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE
245+ );
246+
247+ INSERT INTO _timescaledb_catalog .continuous_agg
248+ (mat_hypertable_id, raw_hypertable_id, parent_mat_hypertable_id, user_view_schema,
249+ user_view_name, partial_view_schema, partial_view_name, direct_view_schema,
250+ direct_view_name, materialized_only)
251+ SELECT * FROM _timescaledb_catalog ._tmp_continuous_agg ;
252+ DROP TABLE _timescaledb_catalog ._tmp_continuous_agg ;
253+
254+ CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog .continuous_agg (raw_hypertable_id);
255+
256+ SELECT pg_catalog .pg_extension_config_dump (' _timescaledb_catalog.continuous_agg' , ' ' );
257+
258+ GRANT SELECT ON TABLE _timescaledb_catalog .continuous_agg TO PUBLIC;
259+
260+ ALTER TABLE _timescaledb_catalog .continuous_aggs_watermark
261+ ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey
262+ FOREIGN KEY (mat_hypertable_id)
263+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
264+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_invalidation_log
265+ ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey
266+ FOREIGN KEY (materialization_id)
267+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
268+ ALTER TABLE _timescaledb_catalog .continuous_aggs_materialization_ranges
269+ ADD CONSTRAINT continuous_aggs_materialization_ranges_materialization_id_fkey
270+ FOREIGN KEY (materialization_id)
271+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
272+ ALTER TABLE _timescaledb_catalog .continuous_aggs_jobs_refresh_ranges
273+ ADD CONSTRAINT continuous_aggs_jobs_refresh_ranges_materialization_id_fkey
274+ FOREIGN KEY (materialization_id)
275+ REFERENCES _timescaledb_catalog .continuous_agg (mat_hypertable_id) ON DELETE CASCADE ;
276+
277+ ANALYZE _timescaledb_catalog .continuous_agg ;
278+ -- end rebuild _timescaledb_catalog.continuous_agg --
0 commit comments