"""add secrets dbe model

Revision ID: 3dc71d61f764
Revises: 0f086ebc2f83
Create Date: 2025-02-13 08:45:00.986714

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from oss.src.dbs.postgres.secrets.custom_fields import PGPString


# revision identifiers, used by Alembic.
revision: str = "3dc71d61f764"
down_revision: Union[str, None] = "0f086ebc2f83"
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! ###
    op.execute("CREATE EXTENSION IF NOT EXISTS pgcrypto;")
    op.create_table(
        "secrets",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("kind", sa.Enum("PROVIDER_KEY", name="secretkind"), nullable=True),
        sa.Column("data", PGPString(), nullable=True),
        sa.Column("project_id", sa.UUID(), nullable=False),
        sa.Column(
            "created_at",
            sa.TIMESTAMP(timezone=True),
            server_default=sa.text("CURRENT_TIMESTAMP"),
            nullable=False,
        ),
        sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("updated_by_id", sa.UUID(), nullable=True),
        sa.Column("name", sa.String(), nullable=True),
        sa.Column("description", sa.String(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("secrets")
    op.execute("DROP TYPE IF EXISTS secretkind;")
    op.execute("DROP EXTENSION IF EXISTS pgcrypto;")
    # ### end Alembic commands ###
