"""dev_tools saved queries

Revision ID: dev_tools_002
Revises: dev_tools_001
Create Date: 2026-03-10
"""
import sqlalchemy as sa

from alembic import op

revision = "dev_tools_002"
down_revision = "dev_tools_001"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "dev_tools_saved_queries",
        sa.Column("id", sa.Integer(), primary_key=True, index=True),
        sa.Column("name", sa.String(200), nullable=False, index=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("sql_text", sa.Text(), nullable=False),
        sa.Column(
            "created_by", sa.Integer(), sa.ForeignKey("users.id"), nullable=False
        ),
        sa.Column("last_run_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column(
            "run_count", sa.Integer(), nullable=False, server_default="0"
        ),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.func.now(),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.func.now(),
            nullable=False,
        ),
    )


def downgrade() -> None:
    op.drop_table("dev_tools_saved_queries")
