diff --git a/mcp-server/src/legal_mcp/services/db.py b/mcp-server/src/legal_mcp/services/db.py index d737ecb..5964f78 100644 --- a/mcp-server/src/legal_mcp/services/db.py +++ b/mcp-server/src/legal_mcp/services/db.py @@ -1690,6 +1690,19 @@ EXCEPTION WHEN duplicate_object THEN NULL; END $$; """ +SCHEMA_V43_SQL = """ +-- חיפה (Haifa) is a distinct planning district, separate from הצפון (North). +-- A bug in _district_from_court mapped "חיפה" -> "צפון", and the service-layer +-- _VALID_DISTRICTS omitted "חיפה" entirely, so Haifa committee decisions were +-- mis-filed under צפון. Both fixed in internal_decisions.py; this reclassifies +-- the legacy rows at the source (G1) by their court text. Idempotent. +UPDATE case_law SET district = 'חיפה' + WHERE source_kind = 'internal_committee' + AND district = 'צפון' + AND court ILIKE '%חיפה%'; +""" + + # Stable, arbitrary key for the session-level advisory lock that serialises # schema DDL across processes. Every short-lived process (cron drains, services) # re-runs the idempotent migrations on startup; without this lock two processes @@ -1707,7 +1720,7 @@ async def _run_schema_migrations(pool: asyncpg.Pool) -> None: await _apply_schema_ddl(conn) finally: await conn.execute("SELECT pg_advisory_unlock($1)", _MIGRATION_LOCK_KEY) - logger.info("Database schema initialized (v1-v42)") + logger.info("Database schema initialized (v1-v43)") async def _apply_schema_ddl(conn: asyncpg.Connection) -> None: @@ -1754,6 +1767,7 @@ async def _apply_schema_ddl(conn: asyncpg.Connection) -> None: await conn.execute(SCHEMA_V40_SQL) await conn.execute(SCHEMA_V41_SQL) await conn.execute(SCHEMA_V42_SQL) + await conn.execute(SCHEMA_V43_SQL) async def init_schema() -> None: diff --git a/mcp-server/src/legal_mcp/services/internal_decisions.py b/mcp-server/src/legal_mcp/services/internal_decisions.py index 248ed7e..79ffe1b 100644 --- a/mcp-server/src/legal_mcp/services/internal_decisions.py +++ b/mcp-server/src/legal_mcp/services/internal_decisions.py @@ -28,14 +28,14 @@ logger = logging.getLogger(__name__) INTERNAL_DECISIONS_DIR = Path(config.DATA_DIR) / "internal-decisions" _VALID_PRACTICE_AREAS = frozenset({"", "rishuy_uvniya", "betterment_levy", "compensation_197"}) -_VALID_DISTRICTS = frozenset({"", "ירושלים", "מרכז", "תל אביב", "צפון", "דרום", "ארצי"}) +_VALID_DISTRICTS = frozenset({"", "ירושלים", "מרכז", "תל אביב", "חיפה", "צפון", "דרום", "ארצי"}) _COURT_TO_DISTRICT = [ ("ירושלים", "ירושלים"), ("תל אביב", "תל אביב"), ('ת"א', "תל אביב"), ("מרכז", "מרכז"), - ("חיפה", "צפון"), + ("חיפה", "חיפה"), ("צפון", "צפון"), ("דרום", "דרום"), ("ארצי", "ארצי"),