Tasks: Legal Corpus Schema¶
Each task references one or more
FR-*/NFR-*/AC-*IDs from spec.md. CI'sspec_validator.pyenforces coverage.
Conventions¶
- Status:
[ ]todo /[~]in-progress /[x]done. - Owner:
@copilot. - Each task lists exact files to touch and how to verify.
T-001 — Add Cypher migrations 003–007¶
- Refs: FR-1, FR-2, FR-3, FR-4, NFR-MIGRATION-SAFETY-1, NFR-SEC-1, AC-1
- Owner: @copilot
- Status:
[x] - Files:
backend/law_ai/core/neo4j/migrations/003_statute_constraints.cypher(new)backend/law_ai/core/neo4j/migrations/004_ordinance_regulation.cypher(new)backend/law_ai/core/neo4j/migrations/005_temporal_indexes.cypher(new)backend/law_ai/core/neo4j/migrations/006_derived_document.cypher(new)backend/law_ai/core/neo4j/migrations/007_fulltext_indexes.cypher(new)- Steps:
- Author the five
.cypherfiles withCREATE CONSTRAINT … IF NOT EXISTS/CREATE INDEX … IF NOT EXISTS/CREATE FULLTEXT INDEX … IF NOT EXISTSstatements covering every label in spec §7. - Each file ends with a comment block explaining what it adds and why it is forward-only.
- Verify:
backend/tests/core/test_neo4j_migrations.py(T-004) passes.
T-002 — Pydantic models for legal documents¶
- Refs: FR-5, NFR-AUDIT-1, NFR-OSS-1, AC-2
- Owner: @copilot
- Status:
[x] - Files:
backend/law_ai/core/schemas/legal_documents.py(new)backend/law_ai/core/schemas/__init__.py(re-export)- Steps:
- Define a
LegalProvenancemixin Pydantic model carryingsource/source_url/confidence/ingest_timestamp/agent_version. - Define
Jurisdiction,Court,Code,Statute,StatuteSection,Ordinance,OrdinanceSection,Regulation,DerivedDocumentmodels inheriting the mixin. - Re-export from
core/schemas/__init__.py. - Verify:
backend/tests/models/test_legal_document_schemas.py(T-005) passes.cd backend && mypy law_ai/core/schemas --strictclean.
T-003 — Generalize PendingReview with kind¶
- Refs: FR-6, NFR-MIGRATION-SAFETY-1, AC-3
- Owner: @copilot
- Status:
[x] - Files:
backend/law_ai/ingestionapp/models.py(extend)backend/law_ai/ingestionapp/migrations/0002_pending_review_kind.py(new)backend/law_ai/ingestionapp/quarantine_kinds.py(new — constants)- Steps:
- Add
kind = models.CharField(max_length=32, default="case", db_index=True)toPendingReview. - Author migration
0002_pending_review_kind.pyusingSeparateDatabaseAndStatewith vendor-awareRunPython(PostgresADD COLUMN IF NOT EXISTS+CREATE INDEX IF NOT EXISTS, SQLite portableALTER TABLE). - Add
quarantine_kinds.pyexportingKIND_CASE,KIND_STATUTE,KIND_ORDINANCE,KIND_REGULATION,KIND_DERIVED. - Verify:
backend/tests/ingestion/test_pending_review_kind.py(T-006) passes.cd backend && python manage.py makemigrations --check --dry-runis a no-op.
T-004 — Test: Neo4j migration files are idempotent + complete¶
- Refs: FR-1, FR-2, FR-3, FR-4, NFR-MIGRATION-SAFETY-1, AC-1
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/core/test_neo4j_migrations.py(new)- Steps:
- Discover all
.cypherfiles underbackend/law_ai/core/neo4j/migrations/. - Assert every
CREATE CONSTRAINT|INDEX|FULLTEXT INDEXstatement containsIF NOT EXISTS. - Assert the union of declared constraint names covers the labels listed in spec FR-1.
- Verify:
cd backend && pytest tests/core/test_neo4j_migrations.py -q.
T-005 — Test: Pydantic schemas validate provenance + bounds¶
- Refs: FR-5, NFR-AUDIT-1, AC-2
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/models/test_legal_document_schemas.py(new)backend/tests/models/__init__.py(new, empty if needed)- Steps:
- Round-trip-instantiate each model with valid input.
- Assert
ValidationErrorwhenconfidenceis out of range or required provenance fields are missing. - Verify:
cd backend && pytest tests/models/test_legal_document_schemas.py -q.
T-006 — Test: PendingReview.kind column behavior¶
- Refs: FR-6, AC-3
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/ingestion/test_pending_review_kind.py(new)- Steps:
- Create
PendingReviewrows with explicitkind="statute"and default (omitted) — assert default ="case". - Insert via raw SQL without
kind(where the DB allows) and assert it back-fills to'case'. - Introspect connection constraints / indexes for
pending_review_kind. - Verify:
cd backend && pytest tests/ingestion/test_pending_review_kind.py -q.
T-007 — Update docs/data-model.md¶
- Refs: FR-7, AC-5
- Owner: @copilot
- Status:
[x] - Files:
docs/data-model.md(extend)- Steps:
- Add property tables for every new node label.
- Update the Edges section with the new relationships listed in spec §7.
- Add a "Quarantine kinds" subsection describing the new
kinddiscriminator. - Verify:
cd backend && pytest tests/test_docs.py -q(workspacetests/) — link checker still green.
T-008 — Update BACKLOG.md with follow-ups¶
- Refs: AC-4 (constitution §11), spec §13
- Owner: @copilot
- Status:
[x] - Files:
BACKLOG.md - Steps:
- Add follow-ups for the broken
init-db.shpaths and the missing migration runner. - Mirror them in
## Follow-ups Discoveredbelow. - Verify:
python scripts/backlog_lint.py && python scripts/spec_validator.py.
Done-When (Definition of Done)¶
- All tasks
[x]. cd backend && pytest tests/core tests/models tests/ingestion -qgreen.make lintgreen.- LegalBench delta: 0 pp (no reasoning changed) — recorded in PR.
## Follow-ups Discoveredpopulated below; mirrored inBACKLOG.md.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid.
- BL-20260509-01 — infra, high —
backend/scripts/init-db.shreferences the pre-rebrandapp/db/neo4j_migrationsandapp/db/postgres_migrationspaths; never picks upbackend/law_ai/core/neo4j/migrations/*.cypher. Fix path + add Postgres-side runner that complements Django migrations (only for Neo4j Cypher files now that all Postgres DDL lives in Django migrations). - BL-20260509-02 — infra, med — Add a real Cypher migration runner that records applied migrations in a
(:_Migration {id})Neo4j node so non-idempotent migrations become possible later (e.g. data back-fills). - BL-20260509-03 — test-gap, med — Docker-backed integration test that actually applies
001–007against a live Neo4j and runsSHOW CONSTRAINTS/SHOW INDEXESto confirm shape; the unit test added in T-004 only validates the file contents.