content: """UTC Timestamps and Indexing
  
  Revision ID: 20240812211350_bcc569077106
  Revises: 20240812190934_5ceb460ac3ef
  Create Date: 2024-08-12 21:13:50.136975
  
  """
  
  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 = "20240812211350_bcc569077106"
  down_revision: Union[str, None] = "20240812190934_5ceb460ac3ef"
  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(
          "conversations",
          sa.Column("id", sa.String(length=255), nullable=False),
          sa.Column("user_id", sa.String(length=255), nullable=False),
          sa.Column("title", sa.String(length=255), nullable=False),
          sa.Column(
              "status",
              sa.Enum("ACTIVE", "ARCHIVED", "DELETED", name="conversationstatus"),
              nullable=False,
          ),
          sa.Column("project_ids", postgresql.ARRAY(sa.String()), nullable=False),
          sa.Column("agent_ids", postgresql.ARRAY(sa.String()), nullable=False),
          sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
          sa.Column("updated_at", sa.TIMESTAMP(timezone=True), nullable=False),
          sa.ForeignKeyConstraint(
              ["user_id"],
              ["users.uid"],
          ),
          sa.PrimaryKeyConstraint("id"),
      )
      op.create_index(op.f("ix_conversations_id"), "conversations", ["id"], unique=False)
      op.create_index(
          op.f("ix_conversations_user_id"), "conversations", ["user_id"], unique=False
      )
      op.create_table(
          "messages",
          sa.Column("id", sa.String(length=255), nullable=False),
          sa.Column("conversation_id", sa.String(length=255), nullable=False),
          sa.Column("content", sa.Text(), nullable=False),
          sa.Column("sender_id", sa.String(length=255), nullable=True),
          sa.Column(
              "type", sa.Enum("AI_GENERATED", "HUMAN", name="messagetype"), nullable=False
          ),
          sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
          sa.CheckConstraint(
              "(type = 'HUMAN' AND sender_id IS NOT NULL) OR (type = 'AI_GENERATED' AND sender_id IS NULL)",
              name="check_sender_id_for_type",
          ),
          sa.ForeignKeyConstraint(
              ["conversation_id"],
              ["conversations.id"],
          ),
          sa.PrimaryKeyConstraint("id"),
      )
      op.create_index(
          op.f("ix_messages_conversation_id"),
          "messages",
          ["conversation_id"],
          unique=False,
      )
      op.alter_column(
          "projects",
          "created_at",
          existing_type=postgresql.TIMESTAMP(),
          type_=sa.TIMESTAMP(timezone=True),
          nullable=False,
      )
      op.alter_column(
          "users",
          "created_at",
          existing_type=postgresql.TIMESTAMP(),
          type_=sa.TIMESTAMP(timezone=True),
          nullable=False,
      )
      # ### end Alembic commands ###
  
  
  def downgrade() -> None:
      # ### commands auto generated by Alembic - please adjust! ###
      op.alter_column(
          "users",
          "created_at",
          existing_type=sa.TIMESTAMP(timezone=True),
          type_=postgresql.TIMESTAMP(),
          nullable=True,
      )
      op.alter_column(
          "projects",
          "created_at",
          existing_type=sa.TIMESTAMP(timezone=True),
          type_=postgresql.TIMESTAMP(),
          nullable=True,
      )
      op.drop_index(op.f("ix_messages_conversation_id"), table_name="messages")
      op.drop_table("messages")
      op.drop_index(op.f("ix_conversations_user_id"), table_name="conversations")
      op.drop_index(op.f("ix_conversations_id"), table_name="conversations")
      op.drop_table("conversations")
      # ### end Alembic commands ###
  