diff --git a/sql/updates/1.5.1--1.6.0.sql b/sql/updates/1.5.1--1.6.0.sql index 688650d3f7c..1575daa7480 100644 --- a/sql/updates/1.5.1--1.6.0.sql +++ b/sql/updates/1.5.1--1.6.0.sql @@ -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'; diff --git a/sql/updates/1.7.5--2.0.0-rc1.sql b/sql/updates/1.7.5--2.0.0-rc1.sql index bfd9cd1e798..d7266343ae1 100644 --- a/sql/updates/1.7.5--2.0.0-rc1.sql +++ b/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 @@ -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; diff --git a/sql/updates/2.0.0-rc1--2.0.0-rc2.sql b/sql/updates/2.0.0-rc1--2.0.0-rc2.sql index c439e5c5cfd..bb067264b24 100644 --- a/sql/updates/2.0.0-rc1--2.0.0-rc2.sql +++ b/sql/updates/2.0.0-rc1--2.0.0-rc2.sql @@ -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 diff --git a/sql/updates/2.0.0-rc3--2.0.0-rc4.sql b/sql/updates/2.0.0-rc3--2.0.0-rc4.sql index 13e0d68c932..fd8ebc11b2d 100644 --- a/sql/updates/2.0.0-rc3--2.0.0-rc4.sql +++ b/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; diff --git a/sql/updates/pre-update.sql b/sql/updates/pre-update.sql index 3b0cb4f8713..9177140b83b 100644 --- a/sql/updates/pre-update.sql +++ b/sql/updates/pre-update.sql @@ -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;