"""create networks table

Revision ID: 3215bc85dc45
Revises: 428215fddea3
Create Date: 2024-08-19 08:46:39.258404

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

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

# revision identifiers, used by Alembic.
revision = "3215bc85dc45"
down_revision = "428215fddea3"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "networks",
        sa.Column(
            "id",
            GUID(),
            server_default=sa.text("uuid_generate_v4()"),
            nullable=False,
        ),
        sa.Column("name", sa.String(length=128), nullable=False),
        sa.Column("ref_name", sa.String(length=128), nullable=False),
        sa.Column("driver", sa.String(length=64), nullable=False),
        sa.Column(
            "options", postgresql.JSONB(astext_type=sa.Text()), server_default="{}", nullable=False
        ),
        sa.Column("project", GUID(), nullable=False),
        sa.Column("domain_name", SlugType(length=64), nullable=False),
        sa.Column(
            "created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True
        ),
        sa.Column(
            "updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_networks")),
    )
    op.add_column(
        "sessions",
        sa.Column("network_type", sa.VARCHAR, nullable=True),
    )
    op.add_column("sessions", sa.Column("network_id", sa.String(length=128), nullable=True))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("sessions", "network_id")
    op.drop_column("sessions", "network_type")
    op.drop_table("networks")
    # ### end Alembic commands ###
