"""add event log

Revision ID: 17ea44123131
Revises: 42998e8c8bb4
Create Date: 2025-05-18 13:03:27.299856

"""

import sqlalchemy as sa
from alembic import op

from ai.backend.manager.models.base import GUID

# revision identifiers, used by Alembic.
revision = "17ea44123131"
down_revision = "42998e8c8bb4"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "event_logs",
        sa.Column(
            "id",
            GUID(),
            server_default=sa.text("uuid_generate_v4()"),
            nullable=False,
        ),
        sa.Column("event_name", sa.String(), nullable=False),
        sa.Column("event_domain", sa.VARCHAR(length=64), nullable=False),
        sa.Column("domain_id", sa.String(), nullable=True),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column("duration", sa.Interval(), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_event_logs")),
    )
    op.create_index(op.f("ix_event_logs_created_at"), "event_logs", ["created_at"], unique=False)
    op.create_index(op.f("ix_event_logs_domain_id"), "event_logs", ["domain_id"], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_event_logs_domain_id"), table_name="event_logs")
    op.drop_index(op.f("ix_event_logs_created_at"), table_name="event_logs")
    op.drop_table("event_logs")
    # ### end Alembic commands ###
