"""create endpoint_auto_scaling_rules table

Revision ID: fb89f5d7817b
Revises: ef9a7960d234
Create Date: 2024-12-20 01:48:21.009056

"""

import sqlalchemy as sa
from alembic import op

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

# revision identifiers, used by Alembic.
revision = "fb89f5d7817b"
down_revision = "ef9a7960d234"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "endpoint_auto_scaling_rules",
        IDColumn(),
        sa.Column("metric_source", sa.VARCHAR(64), nullable=False),
        sa.Column("metric_name", sa.Text(), nullable=False),
        sa.Column("threshold", sa.Text(), nullable=False),
        sa.Column("comparator", sa.VARCHAR(64), nullable=False),
        sa.Column("step_size", sa.Integer(), nullable=False),
        sa.Column("cooldown_seconds", sa.Integer(), nullable=False),
        sa.Column("min_replicas", sa.Integer(), nullable=True),
        sa.Column("max_replicas", sa.Integer(), nullable=True),
        sa.Column(
            "created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column("last_triggered_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("endpoint", GUID(), nullable=False),
        sa.ForeignKeyConstraint(
            ["endpoint"],
            ["endpoints.id"],
            name=op.f("fk_endpoint_auto_scaling_rules_endpoint_endpoints"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_endpoint_auto_scaling_rules")),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("endpoint_auto_scaling_rules")
    # ### end Alembic commands ###
