@@ -158,3 +158,97 @@ ALTER EXTENSION timescaledb DROP SEQUENCE _timescaledb_catalog.chunk_constraint_
158158DROP TABLE _timescaledb_catalog .chunk_constraint ;
159159DROP SEQUENCE _timescaledb_catalog .chunk_constraint_name ;
160160
161+ -- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` to add the
162+ -- `schema_change_timestamp` column.
163+
164+ -- Drop views and foreign keys that depend on the catalog table.
165+ DROP VIEW IF EXISTS timescaledb_experimental .policies ;
166+ DROP VIEW IF EXISTS timescaledb_information .hypertables ;
167+ DROP VIEW IF EXISTS timescaledb_information .continuous_aggregates ;
168+ DROP VIEW IF EXISTS timescaledb_information .jobs ;
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 --
0 commit comments