From 6cf918ad79e6086d596d4f22f79307508f6edbc0 Mon Sep 17 00:00:00 2001 From: Chaim Date: Sun, 12 Apr 2026 23:47:11 +0000 Subject: [PATCH] Add DB schema V4: methodology alignment columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New columns for methodology-aware decision pipeline: claims table: - claim_handling (address/bundle/skip) — per-claim handling mode - bundle_group — group name for bundled claims - handling_reason — explanation for skip/bundle cases table: - standard_of_review — review standard (independent discretion / etc.) - subject_categories — JSONB array of topics in the appeal case_law table: - precedent_level — hierarchy (supreme/administrative/national/district) - is_binding — binding holding vs. obiter dictum - creac_role — how it serves reasoning (rule/explanation/analogy) decisions table: - issue_order — JSONB array of ordered issues with type - claim_handling — JSONB overrides from chair_directions Migration tested and applied successfully on production DB. Co-Authored-By: Claude Opus 4.6 (1M context) --- mcp-server/src/legal_mcp/services/db.py | 48 ++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/mcp-server/src/legal_mcp/services/db.py b/mcp-server/src/legal_mcp/services/db.py index cb3df66..3f65e64 100644 --- a/mcp-server/src/legal_mcp/services/db.py +++ b/mcp-server/src/legal_mcp/services/db.py @@ -397,6 +397,51 @@ CREATE INDEX IF NOT EXISTS idx_case_law_embeddings_vec """ +# ── Phase 4: Methodology alignment ────────────────────────────── + +SCHEMA_V4_SQL = """ + +-- ═══════════════════════════════════════════════════════════════════ +-- V4: Methodology alignment (decision-methodology.md) +-- ═══════════════════════════════════════════════════════════════════ + +-- claims: טיפול בטענות (bundle/skip) + סוג טענה +ALTER TABLE claims ADD COLUMN IF NOT EXISTS claim_type TEXT DEFAULT 'claim'; + -- claim / response / reply +ALTER TABLE claims ADD COLUMN IF NOT EXISTS claim_handling TEXT DEFAULT 'address'; + -- address (דיון מלא) / bundle (קיבוץ) / skip (דילוג) +ALTER TABLE claims ADD COLUMN IF NOT EXISTS bundle_group TEXT DEFAULT ''; + -- שם הקבוצה לקיבוץ (למשל "פגמים פרוצדורליים") +ALTER TABLE claims ADD COLUMN IF NOT EXISTS handling_reason TEXT DEFAULT ''; + -- נימוק לדילוג/קיבוץ (למשל "נבחנה ולא מצאנו ממש") + +-- cases: תקן ביקורת + קטגוריות נושא +ALTER TABLE cases ADD COLUMN IF NOT EXISTS standard_of_review TEXT DEFAULT ''; + -- "שיקול דעת תכנוני עצמאי" / "בחינת שומה מכרעת" / ... +ALTER TABLE cases ADD COLUMN IF NOT EXISTS subject_categories JSONB DEFAULT '[]'; + -- ["חניה", "קווי בניין", "גובה", "שימוש חורג", ...] + +-- case_law: רמת תקדים + מעמד +ALTER TABLE case_law ADD COLUMN IF NOT EXISTS precedent_level TEXT DEFAULT ''; + -- עליון / מנהלי / ועדת ערר ארצית / ועדת ערר מחוזית +ALTER TABLE case_law ADD COLUMN IF NOT EXISTS is_binding BOOLEAN DEFAULT TRUE; + -- הלכה מחייבת (true) / אמרת אגב (false) +ALTER TABLE case_law ADD COLUMN IF NOT EXISTS creac_role TEXT DEFAULT ''; + -- rule (הנחה עליונה) / explanation (הרחבה) / analogy (אנלוגיה) + +-- decisions: סדר סוגיות + תקן ביקורת +ALTER TABLE decisions ADD COLUMN IF NOT EXISTS issue_order JSONB DEFAULT '[]'; + -- סדר הסוגיות שנקבע ע"י המנצח: [{"title": "...", "type": "threshold/dispositive/secondary"}] +ALTER TABLE decisions ADD COLUMN IF NOT EXISTS claim_handling JSONB DEFAULT '{}'; + -- {"overrides": [{"claim_id": "...", "handling": "bundle", "group": "..."}]} + +-- indexes +CREATE INDEX IF NOT EXISTS idx_claims_handling ON claims(claim_handling); +CREATE INDEX IF NOT EXISTS idx_claims_type ON claims(claim_type); +CREATE INDEX IF NOT EXISTS idx_case_law_level ON case_law(precedent_level); +""" + + async def init_schema() -> None: pool = await get_pool() async with pool.acquire() as conn: @@ -404,7 +449,8 @@ async def init_schema() -> None: await conn.execute(MIGRATIONS_SQL) await conn.execute(SCHEMA_V2_SQL) await conn.execute(SCHEMA_V3_SQL) - logger.info("Database schema initialized (v1 + v2 + v3)") + await conn.execute(SCHEMA_V4_SQL) + logger.info("Database schema initialized (v1 + v2 + v3 + v4)") # ── Case CRUD ───────────────────────────────────────────────────────