"""add source column to dre_publications (dre | mj)

Revision ID: 0011
Revises: 0010
Create Date: 2026-04-17

Extends the existing dre_publications table to also hold historical MJ
(meu.registo.justica.gov.pt) publications scraped via Playwright. Same shape
so the UI can render a unified timeline; only the origin label differs.
"""
from alembic import op


revision = "0011"
down_revision = "0010"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute(
        "ALTER TABLE dre_publications "
        "ADD COLUMN source TEXT NOT NULL DEFAULT 'dre' "
        "CHECK (source IN ('dre','mj'))"
    )
    op.execute(
        "CREATE INDEX ix_pubs_source ON dre_publications(company_id, source, date DESC)"
    )


def downgrade() -> None:
    op.execute("DROP INDEX IF EXISTS ix_pubs_source")
    op.execute("ALTER TABLE dre_publications DROP COLUMN source")
