content: """Prompt Tables
  
  Revision ID: 20240902105155_6b44dc81d95d
  Revises: 20240828094302_48240c0ce09e
  Create Date: 2024-09-02 10:51:55.205130
  
  """
  
  from typing import Sequence, Union
  
  import sqlalchemy as sa
  from alembic import op
  
  # revision identifiers, used by Alembic.
  revision: str = "20240902105155_6b44dc81d95d"
  down_revision: Union[str, None] = "20240828094302_48240c0ce09e"
  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.create_table(
          "prompts",
          sa.Column("id", sa.String(), nullable=False),
          sa.Column("text", sa.Text(), nullable=False),
          sa.Column(
              "type", sa.Enum("SYSTEM", "HUMAN", name="prompttype"), nullable=False
          ),
          sa.Column("version", sa.Integer(), nullable=False, server_default="1"),
          sa.Column(
              "status",
              sa.Enum("ACTIVE", "INACTIVE", name="promptstatustype"),
              nullable=False,
              server_default="ACTIVE",
          ),
          sa.Column("created_by", sa.String(), nullable=True),
          sa.Column(
              "created_at",
              sa.TIMESTAMP(timezone=True),
              server_default=sa.func.now(),
              nullable=False,
          ),
          sa.Column(
              "updated_at",
              sa.TIMESTAMP(timezone=True),
              server_default=sa.func.now(),
              onupdate=sa.func.now(),
              nullable=False,
          ),
          sa.ForeignKeyConstraint(
              ["created_by"],
              ["users.uid"],
          ),
          sa.PrimaryKeyConstraint("id"),
          sa.UniqueConstraint(
              "text", "version", "created_by", name="unique_text_version_user"
          ),
          sa.CheckConstraint("version > 0", name="check_version_positive"),
          sa.CheckConstraint("created_at <= updated_at", name="check_timestamps"),
      )
      op.create_table(
          "agent_prompt_mappings",
          sa.Column("id", sa.String(), nullable=False),
          sa.Column("agent_id", sa.String(), nullable=False),
          sa.Column("prompt_id", sa.String(), nullable=False),
          sa.Column("prompt_stage", sa.Integer(), nullable=False),
          sa.ForeignKeyConstraint(["prompt_id"], ["prompts.id"], ondelete="CASCADE"),
          sa.PrimaryKeyConstraint("id"),
          sa.UniqueConstraint(
              "agent_id", "prompt_stage", name="unique_agent_prompt_stage"
          ),
      )
      # ### end Alembic commands ###
  
  
  def downgrade() -> None:
      # ### commands auto generated by Alembic - please adjust! ###
      op.drop_table("prompts")
      op.drop_table("agent_prompt_mappings")
      # ### end Alembic commands ###
  