# type: ignore
"""test-refactoring

Revision ID: caf49b326612
Revises: 2df28a56f27b
Create Date: 2025-01-22 01:23:33.329298+00:00

"""

from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

import sqlalchemy as sa
from alembic import op
from advanced_alchemy.types import (
    EncryptedString,
    EncryptedText,
    GUID,
    ORA_JSONB,
    DateTimeUTC,
)
from sqlalchemy import Text  # noqa: F401

if TYPE_CHECKING:
    pass

__all__ = [
    "downgrade",
    "upgrade",
    "schema_upgrades",
    "schema_downgrades",
    "data_upgrades",
    "data_downgrades",
]

sa.GUID = GUID
sa.DateTimeUTC = DateTimeUTC
sa.ORA_JSONB = ORA_JSONB
sa.EncryptedString = EncryptedString
sa.EncryptedText = EncryptedText

# revision identifiers, used by Alembic.
revision = "caf49b326612"
down_revision = "2df28a56f27b"
branch_labels = None
depends_on = None


def upgrade() -> None:
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        with op.get_context().autocommit_block():
            schema_upgrades()
            data_upgrades()


def downgrade() -> None:
    with warnings.catch_warnings():
        warnings.filterwarnings("ignore", category=UserWarning)
        with op.get_context().autocommit_block():
            data_downgrades()
            schema_downgrades()


def schema_upgrades() -> None:
    """schema upgrade migrations go here."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("service", schema=None) as batch_op:
        batch_op.add_column(sa.Column("home_dir", sa.String(), nullable=True))
        batch_op.add_column(sa.Column("cache_dir", sa.String(), nullable=True))
        batch_op.add_column(sa.Column("scheduler", sa.String(), nullable=False))
        batch_op.add_column(sa.Column("provider", sa.String(), nullable=False))
        batch_op.add_column(sa.Column("grace_period", sa.Integer(), nullable=True))
        batch_op.add_column(sa.Column("mount", sa.String(), nullable=True))
        batch_op.drop_column("job_type")
        batch_op.drop_column("mounts")
        batch_op.drop_column("endpoints")

    # ### end Alembic commands ###


def schema_downgrades() -> None:
    """schema downgrade migrations go here."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("service", schema=None) as batch_op:
        batch_op.add_column(sa.Column("endpoints", sa.VARCHAR(), nullable=True))
        batch_op.add_column(sa.Column("mounts", sa.VARCHAR(), nullable=True))
        batch_op.add_column(sa.Column("job_type", sa.VARCHAR(), nullable=False))
        batch_op.drop_column("mount")
        batch_op.drop_column("grace_period")
        batch_op.drop_column("provider")
        batch_op.drop_column("scheduler")
        batch_op.drop_column("cache_dir")
        batch_op.drop_column("home_dir")

    # ### end Alembic commands ###


def data_upgrades() -> None:
    """Add any optional data upgrade migrations here!"""


def data_downgrades() -> None:
    """Add any optional data downgrade migrations here!"""
