You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when rec.key in ('local_preload_libraries', 'search_path', 'session_preload_libraries', 'shared_preload_libraries', 'temp_tablespaces', 'unix_socket_directories')
when rec.key in ('local_preload_libraries', 'search_path', 'session_preload_libraries', 'shared_preload_libraries', 'temp_tablespaces', 'unix_socket_directories')
280
-
then rec.value
281
-
else quote_literal(rec.value)
282
-
end
283
-
));
284
-
end loop;
285
-
end loop;
286
-
287
-
reassign owned by postgres to supabase_admin;
302
+
if exists (select from pg_extension where extname = 'timescaledb') then
303
+
execute(format('select %s.timescaledb_pre_restore()', (select pronamespace::regnamespace from pg_proc where proname = 'timescaledb_pre_restore')));
304
+
end if;
288
305
289
306
-- databases
290
307
for rec in
@@ -352,10 +369,7 @@ begin
352
369
loop
353
370
if obj->>'role' in ('postgres', 'supabase_admin') or rec.grantee::regrole in ('postgres', 'supabase_admin') then
354
371
execute(format('alter default privileges for role %I %s revoke %s on %s from %s'
355
-
, case when obj->>'role' = 'postgres' then 'supabase_admin'
356
-
when obj->>'role' = 'supabase_admin' then 'postgres'
357
-
else obj->>'role'
358
-
end
372
+
, obj->>'role'
359
373
, case when obj->>'schema' is null then ''
360
374
else format('in schema %I', obj->>'schema')
361
375
end
@@ -366,16 +380,11 @@ begin
366
380
when obj->>'objtype' = 'T' then 'types'
367
381
when obj->>'objtype' = 'n' then 'schemas'
368
382
end
369
-
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin'
370
-
when rec.grantee = 'supabase_admin'::regrole then 'postgres'
371
-
when rec.grantee = 0 then 'public'
372
-
else rec.grantee::regrole::text
373
-
end
383
+
, case when rec.grantee = 0 then 'public' else rec.grantee::regrole::text end
374
384
));
375
385
end if;
376
386
end loop;
377
387
end loop;
378
-
379
388
foreach obj in array default_acls
380
389
loop
381
390
for rec in
@@ -384,7 +393,10 @@ begin
384
393
loop
385
394
if obj->>'role' in ('postgres', 'supabase_admin') or rec.grantee::regrole in ('postgres', 'supabase_admin') then
386
395
execute(format('alter default privileges for role %I %s grant %s on %s to %s %s'
387
-
, obj->>'role'
396
+
, case when obj->>'role' = 'postgres' then 'supabase_admin'
397
+
when obj->>'role' = 'supabase_admin' then 'postgres'
398
+
else obj->>'role'
399
+
end
388
400
, case when obj->>'schema' is null then ''
389
401
else format('in schema %I', obj->>'schema')
390
402
end
@@ -395,7 +407,11 @@ begin
395
407
when obj->>'objtype' = 'T' then 'types'
396
408
when obj->>'objtype' = 'n' then 'schemas'
397
409
end
398
-
, case when rec.grantee = 0 then 'public' else rec.grantee::regrole::text end
410
+
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin'
411
+
when rec.grantee = 'supabase_admin'::regrole then 'postgres'
412
+
when rec.grantee = 0 then 'public'
413
+
else rec.grantee::regrole::text
414
+
end
399
415
, case when rec.is_grantable then 'with grant option' else '' end
400
416
));
401
417
end if;
@@ -405,15 +421,15 @@ begin
405
421
-- schemas
406
422
foreach obj in array schemas
407
423
loop
408
-
if obj->>'owner' = 'postgres' then
424
+
if obj->>'owner' = 'supabase_admin' then
409
425
execute(format('alter schema %s owner to postgres;', (obj->>'oid')::regnamespace));
where grantee::regrole in ('postgres', 'supabase_admin')
415
431
loop
416
-
execute(format('revoke %s on schema %s from %I', rec.privilege_type, (obj->>'oid')::regnamespace, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end));
432
+
execute(format('revoke %s on schema %s from %I', rec.privilege_type, (obj->>'oid')::regnamespace, rec.grantee::regrole));
417
433
end loop;
418
434
end loop;
419
435
foreach obj in array schemas
@@ -423,22 +439,26 @@ begin
423
439
from aclexplode((obj->>'acl')::aclitem[])
424
440
where grantee::regrole in ('postgres', 'supabase_admin')
425
441
loop
426
-
execute(format('grant %s on schema %s to %s %s', rec.privilege_type, (obj->>'oid')::regnamespace, rec.grantee::regrole, case when rec.is_grantable then 'with grant option' else '' end));
442
+
execute(format('grant %s on schema %s to %s %s'
443
+
, rec.privilege_type
444
+
, (obj->>'oid')::regnamespace
445
+
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end
446
+
, case when rec.is_grantable then 'with grant option' else '' end));
427
447
end loop;
428
448
end loop;
429
449
430
450
-- types
431
451
foreach obj in array types
432
452
loop
433
-
if obj->>'owner' = 'postgres' then
453
+
if obj->>'owner' = 'supabase_admin' then
434
454
execute(format('alter type %s owner to postgres;', (obj->>'oid')::regtype));
where grantee::regrole in ('postgres', 'supabase_admin')
440
460
loop
441
-
execute(format('revoke %s on type %s from %I', rec.privilege_type, (obj->>'oid')::regtype, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end));
461
+
execute(format('revoke %s on type %s from %I', rec.privilege_type, (obj->>'oid')::regtype, rec.grantee::regrole));
442
462
end loop;
443
463
end loop;
444
464
foreach obj in array types
@@ -448,14 +468,18 @@ begin
448
468
from aclexplode((obj->>'acl')::aclitem[])
449
469
where grantee::regrole in ('postgres', 'supabase_admin')
450
470
loop
451
-
execute(format('grant %s on type %s to %s %s', rec.privilege_type, (obj->>'oid')::regtype, rec.grantee::regrole, case when rec.is_grantable then 'with grant option' else '' end));
471
+
execute(format('grant %s on type %s to %s %s'
472
+
, rec.privilege_type
473
+
, (obj->>'oid')::regtype
474
+
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end
475
+
, case when rec.is_grantable then 'with grant option' else '' end));
452
476
end loop;
453
477
end loop;
454
478
455
479
-- functions
456
480
foreach obj in array functions
457
481
loop
458
-
if obj->>'owner' = 'postgres' then
482
+
if obj->>'owner' = 'supabase_admin' then
459
483
execute(format('alter routine %s(%s) owner to postgres;', (obj->>'oid')::regproc, pg_get_function_identity_arguments((obj->>'oid')::regproc)));
where grantee::regrole in ('postgres', 'supabase_admin')
511
535
loop
512
-
execute(format('revoke %s on table %s from %I', rec.privilege_type, (obj->>'oid')::oid::regclass, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end));
536
+
execute(format('revoke %s on table %s from %I', rec.privilege_type, (obj->>'oid')::oid::regclass, rec.grantee::regrole));
513
537
end loop;
514
538
end loop;
515
539
foreach obj in array relations
@@ -521,35 +545,25 @@ begin
521
545
from aclexplode((obj->>'acl')::aclitem[])
522
546
where grantee::regrole in ('postgres', 'supabase_admin')
523
547
loop
524
-
execute(format('grant %s on table %s to %s %s', rec.privilege_type, (obj->>'oid')::oid::regclass, rec.grantee::regrole, case when rec.is_grantable then 'with grant option' else '' end));
548
+
execute(format('grant %s on table %s to %s %s'
549
+
, rec.privilege_type
550
+
, (obj->>'oid')::oid::regclass
551
+
, case when rec.grantee = 'postgres'::regrole then 'supabase_admin' else 'postgres' end
552
+
, case when rec.is_grantable then 'with grant option' else '' end));
525
553
end loop;
526
554
end loop;
527
555
528
-
if exists (select from pg_event_trigger where evtname = 'pgsodium_trg_mask_update') then
529
-
alter event trigger pgsodium_trg_mask_update enable;
530
-
end if;
531
-
end
532
-
$$;
533
-
534
-
do $$
535
-
begin
536
556
if exists (select from pg_extension where extname = 'timescaledb') then
537
557
execute(format('select %s.timescaledb_post_restore()', (select pronamespace::regnamespace from pg_proc where proname = 'timescaledb_post_restore')));
0 commit comments