Skip to content

Commit

Permalink
Fix cagg_migrate_to_time_bucket during update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabriziomello committed Feb 21, 2025
1 parent 1e1c15b commit b18e3ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 0 additions & 20 deletions sql/updates/2.14.2--2.15.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -427,23 +427,3 @@ DROP FUNCTION IF EXISTS _timescaledb_functions.policy_job_error_retention_check(
--
-- END bgw_job_stat_history
--

-- Migrate existing CAggs using time_bucket_ng to time_bucket
CREATE PROCEDURE _timescaledb_functions.cagg_migrate_to_time_bucket(cagg REGCLASS)
AS '@MODULE_PATHNAME@', 'ts_continuous_agg_migrate_to_time_bucket' LANGUAGE C;

DO $$
DECLARE
cagg_name regclass;
BEGIN
FOR cagg_name IN
SELECT pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass
FROM _timescaledb_catalog.continuous_agg cagg
JOIN _timescaledb_catalog.continuous_aggs_bucket_function AS bf ON (cagg.mat_hypertable_id = bf.mat_hypertable_id)
WHERE
bf.bucket_func::text LIKE '%time_bucket_ng%'
LOOP
CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name);
END LOOP;
END
$$;
19 changes: 19 additions & 0 deletions sql/updates/post-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,22 @@ $$;
-- Repair relations that have relacl entries for users that do not
-- exist in pg_authid
CALL _timescaledb_functions.repair_relation_acls();

-- Migrate existing CAggs using time_bucket_ng to time_bucket
DO $$
DECLARE
cagg_name regclass;
BEGIN
FOR cagg_name IN
SELECT
pg_catalog.format('%I.%I', user_view_schema, user_view_name)::regclass
FROM
_timescaledb_catalog.continuous_agg
JOIN _timescaledb_catalog.continuous_aggs_bucket_function USING (mat_hypertable_id)
WHERE
bucket_func::text LIKE '%time_bucket_ng%'
LOOP
CALL _timescaledb_functions.cagg_migrate_to_time_bucket(cagg_name);
END LOOP;
END
$$;

0 comments on commit b18e3ca

Please sign in to comment.