Skip to content

Commit 9137edc

Browse files
committed
test
1 parent 229ad6a commit 9137edc

File tree

1 file changed

+25
-18
lines changed
  • ansible/files/admin_api_scripts/pg_upgrade_scripts

1 file changed

+25
-18
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ declare
323323
supabase_admin_rolpassword text := (select rolpassword from pg_authid where rolname = 'supabase_admin');
324324
postgres_role_settings text[] := (select setconfig from pg_db_role_setting where setdatabase = 0 and setrole = 'postgres'::regrole);
325325
supabase_admin_role_settings text[] := (select setconfig from pg_db_role_setting where setdatabase = 0 and setrole = 'supabase_admin'::regrole);
326-
schemas oid[] := (select coalesce(array_agg(oid), '{}') from pg_namespace where nspowner = 'postgres'::regrole);
327-
types oid[] := (
328-
select coalesce(array_agg(t.oid), '{}')
326+
schemas jsonb[] := (select coalesce(array_agg(jsonb_build_object('oid', oid, 'acl', nspacl::text)), '{}') from pg_namespace where nspowner = 'postgres'::regrole);
327+
types jsonb[] := (
328+
select coalesce(array_agg(jsonb_build_object('oid', t.oid, 'acl', t.typacl::text)), '{}')
329329
from pg_type t
330330
join pg_namespace n on n.oid = t.typnamespace
331331
join pg_authid a on a.oid = t.typowner
@@ -353,8 +353,8 @@ declare
353353
and el.typarray = t.oid
354354
)
355355
);
356-
routines oid[] := (
357-
select coalesce(array_agg(p.oid), '{}')
356+
routines jsonb[] := (
357+
select coalesce(array_agg(jsonb_build_object('oid', p.oid, 'acl', p.proacl::text)), '{}')
358358
from pg_proc p
359359
join pg_namespace n on n.oid = p.pronamespace
360360
join pg_authid a on a.oid = p.proowner
@@ -363,8 +363,8 @@ declare
363363
and not starts_with(n.nspname, 'pg_')
364364
and a.rolname = 'postgres'
365365
);
366-
relations oid[] := (
367-
select coalesce(array_agg(c.oid), '{}')
366+
relations jsonb[] := (
367+
select coalesce(array_agg(jsonb_build_object('oid', c.oid, 'acl', c.relacl::text)), '{}')
368368
from pg_class c
369369
join pg_namespace n on n.oid = c.relnamespace
370370
join pg_authid a on a.oid = c.relowner
@@ -375,7 +375,7 @@ declare
375375
and c.relkind not in ('c', 'i')
376376
);
377377
rec record;
378-
objid oid;
378+
obj jsonb;
379379
begin
380380
set local search_path = '';
381381
@@ -462,29 +462,36 @@ begin
462462
update pg_default_acl set defaclrole = 'supabase_admin'::regrole where defaclrole = 0;
463463
464464
-- schemas
465-
foreach objid in array schemas
465+
foreach obj in array schemas
466466
loop
467-
execute(format('alter schema %I owner to postgres;', objid::regnamespace));
467+
execute(format('alter schema %s owner to postgres;', (obj->>'oid')::regnamespace));
468+
-- TODO: don't modify system catalog directly
469+
update pg_namespace set nspacl = (obj->>'acl')::aclitem[] where nspname = obj->>'oid';
468470
end loop;
469471
470472
-- types
471-
foreach objid in array types
473+
foreach obj in array types
472474
loop
473-
execute(format('alter type %I owner to postgres;', objid::regtype));
475+
execute(format('alter type %s owner to postgres;', (obj->>'oid')::regtype));
476+
-- TODO: don't modify system catalog directly
477+
update pg_type set typacl = (obj->>'acl')::aclitem[] where oid = obj->>'oid';
474478
end loop;
475479
476480
-- functions
477-
for rec in
478-
select * from pg_proc where oid = any(routines)
481+
foreach obj in array routines
479482
loop
480-
execute(format('alter routine %I.%I(%s) owner to postgres;', rec.pronamespace::regnamespace, rec.proname, pg_get_function_identity_arguments(rec.oid)));
483+
execute(format('alter routine %s(%s) owner to postgres;', (obj->>'oid')::regproc, pg_get_function_identity_arguments((obj->>'oid')::regproc)));
484+
-- TODO: don't modify system catalog directly
485+
update pg_proc set proacl = (obj->>'acl')::aclitem[] where oid = (obj->>'oid')::regproc;
481486
end loop;
482487
483488
-- relations
484-
for rec in
485-
select * from pg_class where oid = any(relations)
489+
foreach obj in array relations
486490
loop
487-
execute(format('alter table %I.%I owner to postgres;', rec.relnamespace::regnamespace, rec.relname));
491+
-- obj->>'oid' (text) needs to be casted to oid first for some reason
492+
execute(format('alter table %s owner to postgres;', (obj->>'oid')::oid::regclass));
493+
-- TODO: don't modify system catalog directly
494+
update pg_class set relacl = (obj->>'acl')::aclitem[] where oid = (obj->>'oid')::oid::regclass;
488495
end loop;
489496
end
490497
$$;

0 commit comments

Comments
 (0)