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
"""Generates a list of databases privileges statements."""
315
+
statements= []
316
+
ifrelations_accessing_this_database==1:
317
+
statements.append(
318
+
sql.SQL(
319
+
"""DO $$
320
+
DECLARE r RECORD;
321
+
BEGIN
322
+
FOR r IN (SELECT statement FROM (SELECT 1 AS index,'ALTER TABLE '|| schemaname || '."' || tablename ||'" OWNER TO {};' AS statement
323
+
FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema')
324
+
UNION SELECT 2 AS index,'ALTER SEQUENCE '|| sequence_schema || '."' || sequence_name ||'" OWNER TO {};' AS statement
325
+
FROM information_schema.sequences WHERE NOT sequence_schema IN ('pg_catalog', 'information_schema')
326
+
UNION SELECT 3 AS index,'ALTER FUNCTION '|| nsp.nspname || '."' || p.proname ||'"('||pg_get_function_identity_arguments(p.oid)||') OWNER TO {};' AS statement
327
+
FROM pg_proc p JOIN pg_namespace nsp ON p.pronamespace = nsp.oid WHERE NOT nsp.nspname IN ('pg_catalog', 'information_schema')
328
+
UNION SELECT 4 AS index,'ALTER VIEW '|| schemaname || '."' || viewname ||'" OWNER TO {};' AS statement
329
+
FROM pg_catalog.pg_views WHERE NOT schemaname IN ('pg_catalog', 'information_schema')) AS statements ORDER BY index) LOOP
330
+
EXECUTE format(r.statement);
331
+
END LOOP;
332
+
END; $$;"""
333
+
).format(
334
+
sql.Identifier(user),
335
+
sql.Identifier(user),
336
+
sql.Identifier(user),
337
+
sql.Identifier(user),
338
+
)
339
+
)
340
+
else:
341
+
forschemainschemas:
342
+
schema=sql.Identifier(schema)
343
+
statements.append(
344
+
sql.SQL("GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA {} TO {};").format(
345
+
schema, sql.Identifier(user)
346
+
)
347
+
)
348
+
statements.append(
349
+
sql.SQL("GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA {} TO {};").format(
350
+
schema, sql.Identifier(user)
351
+
)
352
+
)
353
+
statements.append(
354
+
sql.SQL("GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA {} TO {};").format(
0 commit comments