Skip to content

Commit

Permalink
Use function to save commits
Browse files Browse the repository at this point in the history
  • Loading branch information
mkindahl committed Apr 14, 2021
1 parent cc18fae commit 9f25430
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
6 changes: 2 additions & 4 deletions sql/updates/1.5.1--1.6.0.sql
Expand Up @@ -23,10 +23,8 @@ BEGIN
END
$BODY$;

INSERT INTO saved_acl SELECT oid, relnamespace, relacl FROM pg_class
WHERE oid IN ('_timescaledb_catalog.continuous_aggs_hypertable_invalidation_log'::regclass,
'_timescaledb_catalog.continuous_aggs_materialization_invalidation_log'::regclass)
ON CONFLICT DO NOTHING;
CALL save_acls_for('_timescaledb_catalog', 'continuous_aggs_hypertable_invalidation_log');
CALL save_acls_for('_timescaledb_catalog', 'continuous_aggs_materialization_invalidation_log');

ALTER TABLE _timescaledb_catalog.continuous_agg
ADD COLUMN ignore_invalidation_older_than BIGINT NOT NULL DEFAULT BIGINT '9223372036854775807';
Expand Down
16 changes: 6 additions & 10 deletions sql/updates/1.7.5--2.0.0-rc1.sql
@@ -1,9 +1,7 @@
-- Save away ACL for objects being re-created
INSERT INTO saved_acl SELECT oid, relnamespace, relacl FROM pg_class
WHERE oid IN ('_timescaledb_config.bgw_job'::regclass,
'_timescaledb_catalog.continuous_agg'::regclass,
'_timescaledb_config.bgw_job_id_seq'::regclass)
ON CONFLICT DO NOTHING;
CALL save_acls_for('_timescaledb_config', 'bgw_job');
CALL save_acls_for('_timescaledb_catalog', 'continuous_agg');
CALL save_acls_for('_timescaledb_config', 'bgw_job_id_seq');

--Drop functions in size_utils and dependencies, ordering matters.
-- Do not reorder
Expand Down Expand Up @@ -269,11 +267,9 @@ DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;
DROP VIEW IF EXISTS timescaledb_information.continuous_aggregate_stats;
ALTER TABLE IF EXISTS _timescaledb_catalog.continuous_agg DROP COLUMN IF EXISTS job_id;

INSERT INTO saved_acl SELECT oid, relnamespace, relacl FROM pg_class
WHERE oid IN ('_timescaledb_config.bgw_job'::regclass,
'_timescaledb_catalog.continuous_agg'::regclass,
'_timescaledb_config.bgw_job_id_seq'::regclass)
ON CONFLICT DO NOTHING;
CALL save_acls_for('_timescaledb_config', 'bgw_job');
CALL save_acls_for('_timescaledb_catalog', 'continuous_agg');
CALL save_acls_for('_timescaledb_config', 'bgw_job_id_seq');

-- rebuild bgw_job table
CREATE TABLE _timescaledb_config.bgw_job_tmp AS SELECT * FROM _timescaledb_config.bgw_job;
Expand Down
6 changes: 2 additions & 4 deletions sql/updates/2.0.0-rc1--2.0.0-rc2.sql
Expand Up @@ -6,10 +6,8 @@ DROP PROCEDURE IF EXISTS refresh_continuous_aggregate(regclass,"any","any");

DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;

INSERT INTO saved_acl SELECT oid, relnamespace, relacl FROM pg_class
WHERE oid IN ('_timescaledb_catalog.continuous_aggs_hypertable_invalidation_log'::regclass,
'_timescaledb_catalog.continuous_aggs_materialization_invalidation_log'::regclass)
ON CONFLICT DO NOTHING;
CALL save_acls_for('_timescaledb_catalog', 'continuous_aggs_hypertable_invalidation_log');
CALL save_acls_for('_timescaledb_catalog', 'continuous_aggs_materialization_invalidation_log');

-- Rebuild hypertable invalidation log
CREATE TABLE _timescaledb_catalog.continuous_aggs_hypertable_invalidation_log_tmp AS
Expand Down
10 changes: 4 additions & 6 deletions sql/updates/2.0.0-rc3--2.0.0-rc4.sql
@@ -1,10 +1,8 @@
-- Save away ACL for objects being re-created
INSERT INTO saved_acl SELECT oid, relnamespace, relacl FROM pg_class
WHERE oid IN ('_timescaledb_catalog.hypertable'::regclass,
'_timescaledb_catalog.hypertable_id_seq'::regclass,
'_timescaledb_internal.hypertable_chunk_local_size'::regclass,
'_timescaledb_internal.compressed_chunk_stats'::regclass)
ON CONFLICT DO NOTHING;
CALL save_acls_for('_timescaledb_catalog', 'hypertable');
CALL save_acls_for('_timescaledb_catalog', 'hypertable_id_seq');
CALL save_acls_for('_timescaledb_internal', 'hypertable_chunk_local_size');
CALL save_acls_for('_timescaledb_internal', 'compressed_chunk_stats');

DROP VIEW IF EXISTS timescaledb_information.continuous_aggregates;
DROP VIEW IF EXISTS timescaledb_information.job_stats;
Expand Down
9 changes: 9 additions & 0 deletions sql/updates/pre-update.sql
Expand Up @@ -33,3 +33,12 @@ SELECT _timescaledb_internal.restart_background_workers();
-- Each update should populate this with whatever tables are being
-- re-built and the post-restore file will copy back the permissions.
CREATE TABLE saved_acl(tmpoid oid, tmpns oid, tmpacl aclitem[], UNIQUE (tmpoid, tmpns));

-- Since objects might not exist, we look them up by name and only add
-- them if they exist.
CREATE PROCEDURE save_acls_for(text, text) AS $$
INSERT INTO saved_acl SELECT cl.oid, relnamespace, relacl
FROM pg_class cl JOIN pg_namespace ns ON ns.oid = relnamespace
WHERE nspname = $1 AND relname = $2
ON CONFLICT DO NOTHING
$$ LANGUAGE sql;

0 comments on commit 9f25430

Please sign in to comment.