"""Add incremental scan fields to meta tables

Revision ID: 005
Revises: 004
Create Date: 2026-04-23 16:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

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


def upgrade() -> None:
    for table in ["meta_database", "meta_table", "meta_column"]:
        op.add_column(table, sa.Column("last_scanned_at", sa.DateTime(), nullable=True))
        op.add_column(table, sa.Column("checksum", sa.String(64), nullable=True))
        op.add_column(table, sa.Column("is_deleted", sa.Boolean(), nullable=False, server_default=sa.text("false")))
        op.add_column(table, sa.Column("deleted_at", sa.DateTime(), nullable=True))


def downgrade() -> None:
    for table in ["meta_database", "meta_table", "meta_column"]:
        op.drop_column(table, "deleted_at")
        op.drop_column(table, "is_deleted")
        op.drop_column(table, "checksum")
        op.drop_column(table, "last_scanned_at")
