"""Add schema_change_log table

Revision ID: 009
Revises: 008
Create Date: 2026-04-23 20:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = "009"
down_revision: Union[str, None] = "008"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "schema_change_log",
        sa.Column("id", sa.Integer(), primary_key=True, index=True),
        sa.Column("source_id", sa.Integer(), sa.ForeignKey("data_source.id"), nullable=False),
        sa.Column("database_id", sa.Integer(), sa.ForeignKey("meta_database.id"), nullable=True),
        sa.Column("table_id", sa.Integer(), sa.ForeignKey("meta_table.id"), nullable=True),
        sa.Column("column_id", sa.Integer(), sa.ForeignKey("meta_column.id"), nullable=True),
        sa.Column("change_type", sa.String(20), nullable=False),
        sa.Column("old_value", sa.Text(), nullable=True),
        sa.Column("new_value", sa.Text(), nullable=True),
        sa.Column("detected_at", sa.DateTime(), default=sa.func.now()),
    )


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