-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58da8f5
commit dba6dd6
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,121 @@ DROP FOREIGN DATA WRAPPER IF EXISTS timescaledb_fdw; | |
DROP FUNCTION IF EXISTS @[email protected]_fdw_handler(); | ||
DROP FUNCTION IF EXISTS @[email protected]_fdw_validator(text[], oid); | ||
|
||
-- | ||
-- Rebuild the catalog table `_timescaledb_catalog.continuous_agg` | ||
-- | ||
DROP VIEW IF EXISTS timescaledb_experimental.policies; | ||
DROP VIEW IF EXISTS timescaledb_information.hypertables; | ||
DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates; | ||
|
||
DROP PROCEDURE IF EXISTS @[email protected]_migrate (REGCLASS, BOOLEAN, BOOLEAN); | ||
DROP FUNCTION IF EXISTS _timescaledb_internal.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); | ||
DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_pre_validation (TEXT, TEXT, TEXT); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_create_plan (_timescaledb_catalog.continuous_agg, TEXT, BOOLEAN, BOOLEAN); | ||
|
||
DROP FUNCTION IF EXISTS _timescaledb_functions.cagg_migrate_plan_exists (INTEGER); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_plan (_timescaledb_catalog.continuous_agg); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_create_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_disable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_enable_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_policies (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_refresh_new_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_copy_data (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_override_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_internal.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
DROP PROCEDURE IF EXISTS _timescaledb_functions.cagg_migrate_execute_drop_old_cagg (_timescaledb_catalog.continuous_agg, _timescaledb_catalog.continuous_agg_migrate_plan_step); | ||
|
||
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log | ||
DROP CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey; | ||
|
||
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark | ||
DROP CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey; | ||
|
||
ALTER EXTENSION timescaledb | ||
DROP TABLE _timescaledb_catalog.continuous_agg; | ||
|
||
CREATE TABLE _timescaledb_catalog._tmp_continuous_agg AS | ||
SELECT | ||
mat_hypertable_id, | ||
raw_hypertable_id, | ||
parent_mat_hypertable_id, | ||
user_view_schema, | ||
user_view_name, | ||
partial_view_schema, | ||
partial_view_name, | ||
bucket_width, | ||
NULL::interval AS bucket_offset, | ||
NULL::timestamptz AS bucket_origin, | ||
direct_view_schema, | ||
direct_view_name, | ||
materialized_only, | ||
finalized | ||
FROM | ||
_timescaledb_catalog.continuous_agg | ||
ORDER BY | ||
mat_hypertable_id; | ||
|
||
DROP TABLE _timescaledb_catalog.continuous_agg; | ||
|
||
CREATE TABLE _timescaledb_catalog.continuous_agg ( | ||
mat_hypertable_id integer NOT NULL, | ||
raw_hypertable_id integer NOT NULL, | ||
parent_mat_hypertable_id integer, | ||
user_view_schema name NOT NULL, | ||
user_view_name name NOT NULL, | ||
partial_view_schema name NOT NULL, | ||
partial_view_name name NOT NULL, | ||
bucket_width bigint NOT NULL, | ||
bucket_offset interval, | ||
bucket_origin TIMESTAMPTZ, | ||
direct_view_schema name NOT NULL, | ||
direct_view_name name NOT NULL, | ||
materialized_only bool NOT NULL DEFAULT FALSE, | ||
finalized bool NOT NULL DEFAULT TRUE, | ||
-- table constraints | ||
CONSTRAINT continuous_agg_pkey PRIMARY KEY (mat_hypertable_id), | ||
CONSTRAINT continuous_agg_partial_view_schema_partial_view_name_key UNIQUE (partial_view_schema, partial_view_name), | ||
CONSTRAINT continuous_agg_user_view_schema_user_view_name_key UNIQUE (user_view_schema, user_view_name), | ||
CONSTRAINT continuous_agg_mat_hypertable_id_fkey | ||
FOREIGN KEY (mat_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, | ||
CONSTRAINT continuous_agg_raw_hypertable_id_fkey | ||
FOREIGN KEY (raw_hypertable_id) REFERENCES _timescaledb_catalog.hypertable (id) ON DELETE CASCADE, | ||
CONSTRAINT continuous_agg_parent_mat_hypertable_id_fkey | ||
FOREIGN KEY (parent_mat_hypertable_id) | ||
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE | ||
); | ||
|
||
INSERT INTO _timescaledb_catalog.continuous_agg | ||
SELECT * FROM _timescaledb_catalog._tmp_continuous_agg; | ||
DROP TABLE _timescaledb_catalog._tmp_continuous_agg; | ||
|
||
CREATE INDEX continuous_agg_raw_hypertable_id_idx ON _timescaledb_catalog.continuous_agg (raw_hypertable_id); | ||
|
||
SELECT pg_catalog.pg_extension_config_dump('_timescaledb_catalog.continuous_agg', ''); | ||
|
||
GRANT SELECT ON TABLE _timescaledb_catalog.continuous_agg TO PUBLIC; | ||
|
||
ALTER TABLE _timescaledb_catalog.continuous_aggs_materialization_invalidation_log | ||
ADD CONSTRAINT continuous_aggs_materialization_invalid_materialization_id_fkey | ||
FOREIGN KEY (materialization_id) | ||
REFERENCES _timescaledb_catalog.continuous_agg(mat_hypertable_id) ON DELETE CASCADE; | ||
|
||
ALTER TABLE _timescaledb_catalog.continuous_aggs_watermark | ||
ADD CONSTRAINT continuous_aggs_watermark_mat_hypertable_id_fkey | ||
FOREIGN KEY (mat_hypertable_id) | ||
REFERENCES _timescaledb_catalog.continuous_agg (mat_hypertable_id) ON DELETE CASCADE; | ||
|
||
ANALYZE _timescaledb_catalog.continuous_agg; | ||
|
||
-- | ||
-- END Rebuild the catalog table `_timescaledb_catalog.continuous_agg` | ||
-- |