"""add body and milestone to issues; description, open_issues_count, is_archived, topics to repos

Revision ID: b2c3d4e5f6a7
Revises: a1b2c3d4e5f7
Create Date: 2026-05-19 00:00:00.000000

"""

from __future__ import annotations

import sqlalchemy as sa
from alembic import op

revision = "b2c3d4e5f6a7"
down_revision = "a1b2c3d4e5f8"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # forgejo_issues — full body text and milestone JSON
    op.add_column(
        "forgejo_issues",
        sa.Column("body", sa.Text(), nullable=True),
    )
    op.add_column(
        "forgejo_issues",
        sa.Column("milestone", sa.JSON(), nullable=True),
    )

    # forgejo_repositories — remote metadata fields
    op.add_column(
        "forgejo_repositories",
        sa.Column("description", sa.String(), nullable=True),
    )
    op.add_column(
        "forgejo_repositories",
        sa.Column(
            "open_issues_count",
            sa.Integer(),
            nullable=False,
            server_default="0",
        ),
    )
    op.add_column(
        "forgejo_repositories",
        sa.Column(
            "is_archived",
            sa.Boolean(),
            nullable=False,
            server_default="false",
        ),
    )
    op.add_column(
        "forgejo_repositories",
        sa.Column(
            "topics",
            sa.JSON(),
            nullable=False,
            server_default="[]",
        ),
    )


def downgrade() -> None:
    op.drop_column("forgejo_repositories", "topics")
    op.drop_column("forgejo_repositories", "is_archived")
    op.drop_column("forgejo_repositories", "open_issues_count")
    op.drop_column("forgejo_repositories", "description")
    op.drop_column("forgejo_issues", "milestone")
    op.drop_column("forgejo_issues", "body")
