phase12: disable RLS on audit_log and sessions (written during login)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Disable RLS on audit_log and sessions (written during login before tenant context).
|
||||
|
||||
Revision ID: 0080
|
||||
Revises: 0079
|
||||
"""
|
||||
from alembic import op
|
||||
from sqlalchemy import text
|
||||
|
||||
revision = "0080"
|
||||
down_revision = "0079"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
TABLES = ["audit_log", "sessions", "password_reset_tokens", "api_tokens"]
|
||||
|
||||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
for table in TABLES:
|
||||
exists = conn.execute(
|
||||
text(f"SELECT 1 FROM information_schema.tables WHERE table_name = '{table}'")
|
||||
).fetchone() is not None
|
||||
if not exists:
|
||||
continue
|
||||
policies = conn.execute(text(
|
||||
f"SELECT policyname FROM pg_policies WHERE tablename = '{table}'"
|
||||
)).fetchall()
|
||||
for (policyname,) in policies:
|
||||
conn.execute(text(f"DROP POLICY IF EXISTS {policyname} ON {table}"))
|
||||
conn.execute(text(f"ALTER TABLE {table} DISABLE ROW LEVEL SECURITY"))
|
||||
print(f" Disabled RLS on {table}")
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
Reference in New Issue
Block a user