"""Add updated_at to chapters.

Revision ID: 8c1d2e3f4a5b
Revises: 59a9198d4604
Create Date: 2026-06-28 00:00:00.000000
"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "8c1d2e3f4a5b"
down_revision: str | None = "59a9198d4604"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    op.add_column(
        "chapters",
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
    )
    op.execute("UPDATE chapters SET updated_at = created_at")


def downgrade() -> None:
    op.drop_column("chapters", "updated_at")
