sprint1: set_user_context + RLS policies on contacts + folder ACL migration 0051+0052
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Migrate contact_folder_permissions to universal entity_permissions table.
|
||||
|
||||
Revision ID: 0051
|
||||
Revises: 0050
|
||||
Create Date: 2026-07-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
||||
|
||||
revision = "0051"
|
||||
down_revision = "0050"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Migrate existing contact_folder_permissions to entity_permissions
|
||||
op.execute("""
|
||||
INSERT INTO entity_permissions (id, entity_type, entity_id, principal_type, principal_id, permission_level, tenant_id, created_at, updated_at)
|
||||
SELECT
|
||||
gen_random_uuid(),
|
||||
'contact_folder',
|
||||
folder_id,
|
||||
CASE
|
||||
WHEN user_id IS NOT NULL THEN 'user'
|
||||
WHEN group_id IS NOT NULL THEN 'group'
|
||||
END,
|
||||
COALESCE(user_id, group_id),
|
||||
permission_level,
|
||||
tenant_id,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM contact_folder_permissions
|
||||
ON CONFLICT DO NOTHING
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.execute("DELETE FROM entity_permissions WHERE entity_type = 'contact_folder'")
|
||||
Reference in New Issue
Block a user