45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
|
|
"""Add tenant_plugin_activation table for per-tenant plugin activation.
|
||
|
|
|
||
|
|
Revision ID: 0066
|
||
|
|
Revises: 0065
|
||
|
|
Create Date: 2026-07-29
|
||
|
|
|
||
|
|
Currently plugins are activated globally. This migration creates a
|
||
|
|
table for per-tenant plugin activation so that different tenants can
|
||
|
|
enable/disable plugins independently.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from sqlalchemy.dialects.postgresql import UUID
|
||
|
|
|
||
|
|
revision = "0066"
|
||
|
|
down_revision = "0065"
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.create_table(
|
||
|
|
"tenant_plugin_activation",
|
||
|
|
sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||
|
|
sa.Column("tenant_id", UUID(as_uuid=True), sa.ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False, index=True),
|
||
|
|
sa.Column("plugin_name", sa.String(100), nullable=False, index=True),
|
||
|
|
sa.Column("is_active", sa.Boolean, nullable=False, default=True),
|
||
|
|
sa.Column("activated_by", UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
|
||
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()"), nullable=False),
|
||
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("NOW()"), nullable=False),
|
||
|
|
sa.UniqueConstraint("tenant_id", "plugin_name", name="uq_tenant_plugin"),
|
||
|
|
)
|
||
|
|
op.execute("ALTER TABLE tenant_plugin_activation ENABLE ROW LEVEL SECURITY")
|
||
|
|
op.execute("""
|
||
|
|
CREATE POLICY tenant_plugin_activation_tenant_isolation ON tenant_plugin_activation
|
||
|
|
FOR ALL
|
||
|
|
USING (tenant_id = current_setting('app.current_tenant_id', true)::uuid)
|
||
|
|
WITH CHECK (tenant_id = current_setting('app.current_tenant_id', true)::uuid)
|
||
|
|
""")
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.drop_table("tenant_plugin_activation")
|