Remove superuser-only session_replication_role from factory reset

This commit is contained in:
Mondo Diaz
2026-02-03 11:19:50 -06:00
parent 2ae479146f
commit cf2fe5151f

View File

@@ -7465,6 +7465,8 @@ def factory_reset(
try:
# Step 1: Drop all tables in public schema
# Note: CASCADE handles foreign key constraints without needing
# superuser privileges (session_replication_role requires superuser)
logger.info("Dropping all database tables...")
drop_result = db.execute(
text("""
@@ -7473,12 +7475,10 @@ def factory_reset(
r RECORD;
table_count INT := 0;
BEGIN
SET session_replication_role = 'replica';
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public') LOOP
EXECUTE 'DROP TABLE IF EXISTS public.' || quote_ident(r.tablename) || ' CASCADE';
table_count := table_count + 1;
END LOOP;
SET session_replication_role = 'origin';
RAISE NOTICE 'Dropped % tables', table_count;
END $$;
""")