From ee4acdf4b7ac0db7279d99c5f94a6b34d595fc62 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Thu, 19 Dec 2024 09:49:58 -0600 Subject: [PATCH] ensure sequences owned by supabase_admin are xfered to postgres on restore --- .../20241215003910_backfill_pgmq_metadata.sql | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/migrations/db/migrations/20241215003910_backfill_pgmq_metadata.sql b/migrations/db/migrations/20241215003910_backfill_pgmq_metadata.sql index 59ff0bf3a..8c27d9e01 100644 --- a/migrations/db/migrations/20241215003910_backfill_pgmq_metadata.sql +++ b/migrations/db/migrations/20241215003910_backfill_pgmq_metadata.sql @@ -30,9 +30,9 @@ begin case when c.relpersistence = 'u' then true else false end as is_unlogged, now() as created_at from - pg_catalog.pg_class c - join pg_catalog.pg_namespace n - on c.relnamespace = n.oid + pg_catalog.pg_class c + join pg_catalog.pg_namespace n + on c.relnamespace = n.oid where n.nspname = 'pgmq' and c.relname like 'q_%' @@ -41,4 +41,23 @@ begin end if; end $$; +do $$ +declare + rec record; +begin + for rec in + select n.nspname as sequence_schema, c.relname as sequence_name + from pg_catalog.pg_class c + join pg_catalog.pg_namespace n on n.oid = c.relnamespace + join pg_catalog.pg_roles r on r.oid = c.relowner + where + c.relkind = 'S' + and n.nspname = 'pgmq' + and r.rolname = 'supabase_admin' + loop + execute format('alter sequence %I.%I owner to postgres', rec.sequence_schema, rec.sequence_name); + end loop; +end; +$$; + -- migrate:down