Skip to content

Commit 8cfacf1

Browse files
committed
Fix cagg_migrate_to_time_bucket during update
In #6837 we added a migration for CAggs using `time_bucket_ng` to use the new version of `time_bucket` that support orign and/or offset. We made a mistake because we place the code to migrate existing CAggs using `time_bucket_ng` to `time_bucket` in the update script but this code should be placed instead on post-update.sql script where we can call functions from the new extension version loaded.
1 parent 41841b6 commit 8cfacf1

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

sql/updates/2.14.2--2.15.0.sql

-20
Original file line numberDiff line numberDiff line change
@@ -427,23 +427,3 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention_check(
427427
--
428428
-- END bgw_job_stat_history
429429
--
430-
431-
-- Migrate existing CAggs using time_bucket_ng to time_bucket
432-
CREATE PROCEDURE _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS)
433-
AS '@MODULE_PATHNAME@', 'ts_continuous_agg_migrate_to_time_bucket' LANGUAGE C;
434-
435-
DO $$
436-
DECLARE
437-
cagg_name regclass;
438-
BEGIN
439-
FOR cagg_name IN
440-
SELECT pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass
441-
FROM _timescaledb_catalog.continuous_agg cagg
442-
JOIN _timescaledb_catalog.continuous_aggs_bucket_function AS bf ON (cagg.mat_hypertable_id = bf.mat_hypertable_id)
443-
WHERE
444-
bf.bucket_func::text LIKE '%time_bucket_ng%'
445-
LOOP
446-
CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name);
447-
END LOOP;
448-
END
449-
$$;

sql/updates/post-update.sql

+19
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,22 @@ $$;
171171
-- Repair relations that have relacl entries for users that do not
172172
-- exist in pg_authid
173173
CALL _timescaledb_functions.repair_relation_acls();
174+
175+
-- Migrate existing CAggs using time_bucket_ng to time_bucket
176+
DO $$
177+
DECLARE
178+
cagg_name regclass;
179+
BEGIN
180+
FOR cagg_name IN
181+
SELECT
182+
pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass
183+
FROM
184+
_timescaledb_catalog.continuous_agg
185+
JOIN _timescaledb_catalog.continuous_aggs_bucket_function USING (mat_hypertable_id)
186+
WHERE
187+
bucket_func::text LIKE '%time_bucket_ng%'
188+
LOOP
189+
CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name);
190+
END LOOP;
191+
END
192+
$$;

0 commit comments

Comments
 (0)