"""Create alerts models

Revision ID: 0d7bea8f4d60
Revises: fc391d505594
Create Date: 2025-08-04 22:33:08.875952

"""

from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "0d7bea8f4d60"
down_revision: Union[str, None] = "fc391d505594"
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(
        "alert_definition",
        sa.Column("properties", postgresql.JSON(astext_type=sa.Text()), nullable=True),
        sa.Column("type", sa.SmallInteger(), nullable=True),
        sa.Column("level", sa.SmallInteger(), nullable=True),
        sa.Column("device_name", sa.Text(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id"),
    )
    # ### end Alembic commands ###


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