30 lines
986 B
Python
30 lines
986 B
Python
"""Add owner_id to mail_accounts for row-level permissions.
|
|
|
|
Revision ID: 0053
|
|
Revises: 0052
|
|
Create Date: 2026-07-29
|
|
|
|
This migration adds owner_id to mail_accounts so that the universal
|
|
visibility/permission system (apply_visibility_filter, check_single_entity_access)
|
|
can be used for mail accounts.
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
revision = "0053"
|
|
down_revision = "0052"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
op.execute("ALTER TABLE IF EXISTS mail_accounts ADD COLUMN IF NOT EXISTS owner_id UUID REFERENCES users(id) ON DELETE SET NULL")
|
|
op.execute("DO $$ BEGIN IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'mail_accounts') THEN CREATE INDEX IF NOT EXISTS ix_mail_accounts_owner ON mail_accounts (owner_id); END IF; END $$")
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index("ix_mail_accounts_owner", table_name="mail_accounts")
|
|
op.drop_column("mail_accounts", "owner_id")
|