"""add external credentials model Revision ID: 36b5dbf670e4 Revises: c7c56dd36b21 Create Date: 2025-12-22 05:29:31.061141 """ from typing import Sequence, Union import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = "36b5dbf670e4" down_revision: Union[str, None] = "c7c56dd36b21" branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### sa.Enum( "none", "api_key", "bearer_token", "basic_auth", "custom_header", name="webhook_credential_type", ).create(op.get_bind()) op.create_table( "external_credentials", sa.Column("id", sa.Integer(), nullable=False), sa.Column("credential_uuid", sa.String(length=36), nullable=False), sa.Column("organization_id", sa.Integer(), nullable=False), sa.Column("name", sa.String(), nullable=False), sa.Column("description", sa.String(), nullable=True), sa.Column( "credential_type", postgresql.ENUM( "none", "api_key", "bearer_token", "basic_auth", "custom_header", name="webhook_credential_type", create_type=False, ), nullable=False, ), sa.Column("credential_data", sa.JSON(), nullable=False), sa.Column("created_by", sa.Integer(), nullable=False), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), sa.Column("is_active", sa.Boolean(), nullable=False), sa.ForeignKeyConstraint( ["created_by"], ["users.id"], ), sa.ForeignKeyConstraint( ["organization_id"], ["organizations.id"], ondelete="CASCADE" ), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint( "organization_id", "name", name="unique_org_credential_name" ), ) op.create_index( op.f("ix_external_credentials_credential_uuid"), "external_credentials", ["credential_uuid"], unique=True, ) op.create_index( "ix_webhook_credentials_organization_id", "external_credentials", ["organization_id"], unique=False, ) op.create_index( "ix_webhook_credentials_uuid", "external_credentials", ["credential_uuid"], unique=False, ) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index("ix_webhook_credentials_uuid", table_name="external_credentials") op.drop_index( "ix_webhook_credentials_organization_id", table_name="external_credentials" ) op.drop_index( op.f("ix_external_credentials_credential_uuid"), table_name="external_credentials", ) op.drop_table("external_credentials") sa.Enum( "none", "api_key", "bearer_token", "basic_auth", "custom_header", name="webhook_credential_type", ).drop(op.get_bind()) # ### end Alembic commands ###