"""add WorkflowDraftVariable model

Revision ID: 2adcbe1f5dfb
Revises: d28f2004b072
Create Date: 2025-05-15 15:31:03.128680

"""

import sqlalchemy as sa
from alembic import op

import models as models


def _is_pg(conn):
    return conn.dialect.name == "postgresql"

# revision identifiers, used by Alembic.
revision = "2adcbe1f5dfb"
down_revision = "d28f2004b072"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    
    if _is_pg(conn):
        op.create_table(
            "workflow_draft_variables",
            sa.Column("id", models.types.StringUUID(), server_default=sa.text("uuid_generate_v4()"), nullable=False),
            sa.Column("created_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
            sa.Column("updated_at", sa.DateTime(), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False),
            sa.Column("app_id", models.types.StringUUID(), nullable=False),
            sa.Column("last_edited_at", sa.DateTime(), nullable=True),
            sa.Column("node_id", sa.String(length=255), nullable=False),
            sa.Column("name", sa.String(length=255), nullable=False),
            sa.Column("description", sa.String(length=255), nullable=False),
            sa.Column("selector", sa.String(length=255), nullable=False),
            sa.Column("value_type", sa.String(length=20), nullable=False),
            sa.Column("value", sa.Text(), nullable=False),
            sa.Column("visible", sa.Boolean(), nullable=False),
            sa.Column("editable", sa.Boolean(), nullable=False),
            sa.PrimaryKeyConstraint("id", name=op.f("workflow_draft_variables_pkey")),
            sa.UniqueConstraint("app_id", "node_id", "name", name=op.f("workflow_draft_variables_app_id_key")),
        )
    else:
        op.create_table(
            "workflow_draft_variables",
            sa.Column("id", models.types.StringUUID(), nullable=False),
            sa.Column("created_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
            sa.Column("updated_at", sa.DateTime(), server_default=sa.func.current_timestamp(), nullable=False),
            sa.Column("app_id", models.types.StringUUID(), nullable=False),
            sa.Column("last_edited_at", sa.DateTime(), nullable=True),
            sa.Column("node_id", sa.String(length=255), nullable=False),
            sa.Column("name", sa.String(length=255), nullable=False),
            sa.Column("description", sa.String(length=255), nullable=False),
            sa.Column("selector", sa.String(length=255), nullable=False),
            sa.Column("value_type", sa.String(length=20), nullable=False),
            sa.Column("value", models.types.LongText(), nullable=False),
            sa.Column("visible", sa.Boolean(), nullable=False),
            sa.Column("editable", sa.Boolean(), nullable=False),
            sa.PrimaryKeyConstraint("id", name=op.f("workflow_draft_variables_pkey")),
            sa.UniqueConstraint("app_id", "node_id", "name", name=op.f("workflow_draft_variables_app_id_key")),
        )

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    # Dropping `workflow_draft_variables` also drops any index associated with it.
    op.drop_table("workflow_draft_variables")

    # ### end Alembic commands ###
