"""accounts: add last-searched address cache (map_search_lat/lng/address)

Revision ID: 0044
Revises: 0043
Create Date: 2026-07-02

Owned by INDL-49. Purely a "last searched location" cache (AC-19) for the
Cemetery Map tab's address-search box — never used for occupancy/reporting math,
and superseded by the real boundary/centroid once one is drawn. All nullable,
no backfill needed. (PRD refers to this as 0042; renumbered to the next genuinely
available integer per the PRD's own numbering note.)

Changes:
  - accounts: add map_search_lat NUMERIC(10,7) NULL
  - accounts: add map_search_lng NUMERIC(10,7) NULL
  - accounts: add map_search_address VARCHAR(500) NULL
"""
from alembic import op
import sqlalchemy as sa

revision = "0049"
down_revision = "0048"
branch_labels = None
depends_on = None


def upgrade() -> None:
    conn = op.get_bind()
    conn.execute(sa.text("ALTER TABLE accounts ADD COLUMN IF NOT EXISTS map_search_lat NUMERIC(10,7) NULL"))
    conn.execute(sa.text("ALTER TABLE accounts ADD COLUMN IF NOT EXISTS map_search_lng NUMERIC(10,7) NULL"))
    conn.execute(sa.text("ALTER TABLE accounts ADD COLUMN IF NOT EXISTS map_search_address VARCHAR(500) NULL"))


def downgrade() -> None:
    conn = op.get_bind()
    for col in ("map_search_address", "map_search_lng", "map_search_lat"):
        conn.execute(sa.text(f"ALTER TABLE accounts DROP COLUMN IF EXISTS {col}"))
