Files
leocrm/alembic/versions/0046_plugin_allowlist.py
T
2026-07-31 19:16:11 +02:00

41 lines
1.7 KiB
Python

"""Create plugin_allowlist table for authorized external plugins.
Revision ID: 0046
Revises: 0045
Create Date: 2026-07-26
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID as PGUUID
revision = "0046"
down_revision = "0045"
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
"plugin_allowlist",
sa.Column("id", PGUUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
sa.Column("plugin_name", sa.String(80), nullable=False),
sa.Column("allowed_hash", sa.String(64), nullable=True),
sa.Column("allowed_signature", sa.Text, nullable=True),
sa.Column("public_key", sa.Text, nullable=True),
sa.Column("added_by", PGUUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
sa.Column("is_active", sa.Boolean, nullable=False, server_default=sa.text("true")),
sa.Column("notes", sa.Text, nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
)
op.execute('CREATE INDEX IF NOT EXISTS ix_plugin_allowlist_plugin_name ON plugin_allowlist (plugin_name)')
op.execute('CREATE INDEX IF NOT EXISTS ix_plugin_allowlist_hash ON plugin_allowlist (allowed_hash)')
def downgrade():
op.drop_index("ix_plugin_allowlist_hash", table_name="plugin_allowlist")
op.drop_index("ix_plugin_allowlist_plugin_name", table_name="plugin_allowlist")
op.drop_table("plugin_allowlist")