Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix downgrade files for 2.3.1 #3443

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion sql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ set(MOD_FILES
updates/2.2.1--2.3.0.sql
updates/2.3.0--2.3.1.sql)

# Files for downgrade scripts.
# Files for downgrade scripts. This should only include files for downgrade to
# previous version since we do not support skipping versions when downgrading
set(REV_FILES)

set(MODULE_PATHNAME "$libdir/timescaledb-${PROJECT_VERSION_MOD}")
Expand Down
28 changes: 28 additions & 0 deletions sql/updates/2.3.1--2.3.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- We need to rewrite all continuous aggregates to make sure that the
-- queries do not contain qualification. They will be re-written in
-- the post-update script as well, but the previous version does not
-- process all continuous aggregates, leaving some with qualification
-- for the standard functions. To make this work, we need to
-- temporarily set the update stage to the post-update stage, which
-- will allow the ALTER MATERIALIZED VIEW to rewrite the query. If
-- that is not done, the TimescaleDB-specific hooks will not be used
-- and you will get an error message saying that, for example,
-- `conditions_summary` is not a materialized view.
SET timescaledb.update_script_stage TO 'post';
DO $$
DECLARE
vname regclass;
materialized_only bool;
altercmd text;
ts_version TEXT;
BEGIN
FOR vname, materialized_only IN select format('%I.%I', cagg.user_view_schema, cagg.user_view_name)::regclass, cagg.materialized_only from _timescaledb_catalog.continuous_agg cagg
LOOP
altercmd := format('ALTER MATERIALIZED VIEW %s SET (timescaledb.materialized_only=%L) ', vname::text, materialized_only);
EXECUTE altercmd;
END LOOP;
EXCEPTION WHEN OTHERS THEN RAISE;
END
$$;
RESET timescaledb.update_script_stage;

29 changes: 0 additions & 29 deletions sql/updates/reverse-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,3 @@ DROP SCHEMA IF EXISTS timescaledb_experimental CASCADE;
DROP FUNCTION IF EXISTS _timescaledb_internal.block_new_chunks;
DROP FUNCTION IF EXISTS _timescaledb_internal.allow_new_chunks;
DROP FUNCTION IF EXISTS _timescaledb_internal.refresh_continuous_aggregate;

-- We need to rewrite all continuous aggregates to make sure that the
-- queries do not contain qualification. They will be re-written in
-- the post-update script as well, but the previous version does not
-- process all continuous aggregates, leaving some with qualification
-- for the standard functions. To make this work, we need to
-- temporarily set the update stage to the post-update stage, which
-- will allow the ALTER MATERIALIZED VIEW to rewrite the query. If
-- that is not done, the TimescaleDB-specific hooks will not be used
-- and you will get an error message saying that, for example,
-- `conditions_summary` is not a materialized view.
SET timescaledb.update_script_stage TO 'post';
DO $$
DECLARE
vname regclass;
materialized_only bool;
altercmd text;
ts_version TEXT;
BEGIN
FOR vname, materialized_only IN select format('%I.%I', cagg.user_view_schema, cagg.user_view_name)::regclass, cagg.materialized_only from _timescaledb_catalog.continuous_agg cagg
LOOP
altercmd := format('ALTER MATERIALIZED VIEW %s SET (timescaledb.materialized_only=%L) ', vname::text, materialized_only);
EXECUTE altercmd;
END LOOP;
EXCEPTION WHEN OTHERS THEN RAISE;
END
$$;
RESET timescaledb.update_script_stage;