Skip to content

Commit

Permalink
Fix update tests to handle sequences
Browse files Browse the repository at this point in the history
The post-update script was handling preserving initprivs for newly
added catalog tables and views. However, newly added catalog sequences
need separate handling otherwise update tests start failing. We also
now grant privileges for all future sequences in the update tests.

In passing, default the PG_VERSION in the update tests to 12 since we
don't work with PG11 anymore.
  • Loading branch information
nikkhils committed Jun 16, 2021
1 parent c4c0c3d commit 1a94cbb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/test_updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST_VERSION=${TEST_VERSION:-}
GIT_ID=$(git -C ${BASE_DIR} describe --dirty --always | sed -e "s|/|_|g")
UPDATE_TO_IMAGE=${UPDATE_TO_IMAGE:-update_test}
UPDATE_TO_TAG=${UPDATE_TO_TAG:-${GIT_ID}}
PG_VERSION=${PG_VERSION:-11.0}
PG_VERSION=${PG_VERSION:-12.0}

# This will propagate to the test_update_from_tags.sh script
export TEST_REPAIR
Expand Down
16 changes: 15 additions & 1 deletion sql/updates/post-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,21 @@ INSERT INTO saved_privs
WHERE tmpnsp = '_timescaledb_catalog' AND tmpname = 'chunk')
FROM pg_class JOIN pg_namespace ns ON ns.oid = relnamespace
LEFT JOIN saved_privs ON tmpnsp = nspname AND tmpname = relname
WHERE nspname IN ('_timescaledb_catalog', '_timescaledb_config')
WHERE relkind IN ('r', 'v') AND nspname IN ('_timescaledb_catalog', '_timescaledb_config')
OR nspname = '_timescaledb_internal'
AND relname IN ('hypertable_chunk_local_size', 'compressed_chunk_stats',
'bgw_job_stat', 'bgw_policy_chunk_stats')
ON CONFLICT DO NOTHING;

-- The above is good enough for tables and views. However sequences need to
-- use the "chunk_id_seq" catalog sequence as a template
INSERT INTO saved_privs
SELECT nspname, relname, relacl,
(SELECT tmpini FROM saved_privs
WHERE tmpnsp = '_timescaledb_catalog' AND tmpname = 'chunk_id_seq')
FROM pg_class JOIN pg_namespace ns ON ns.oid = relnamespace
LEFT JOIN saved_privs ON tmpnsp = nspname AND tmpname = relname
WHERE relkind IN ('S') AND nspname IN ('_timescaledb_catalog', '_timescaledb_config')
OR nspname = '_timescaledb_internal'
AND relname IN ('hypertable_chunk_local_size', 'compressed_chunk_stats',
'bgw_job_stat', 'bgw_policy_chunk_stats')
Expand Down
4 changes: 4 additions & 0 deletions test/sql/updates/setup.catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ ALTER DEFAULT PRIVILEGES IN SCHEMA _timescaledb_catalog
GRANT SELECT ON TABLES TO tsdbadmin;
ALTER DEFAULT PRIVILEGES IN SCHEMA _timescaledb_config
GRANT SELECT ON TABLES TO tsdbadmin;
ALTER DEFAULT PRIVILEGES IN SCHEMA _timescaledb_catalog
GRANT SELECT ON SEQUENCES TO tsdbadmin;
ALTER DEFAULT PRIVILEGES IN SCHEMA _timescaledb_config
GRANT SELECT ON SEQUENCES TO tsdbadmin;

0 comments on commit 1a94cbb

Please sign in to comment.