LEAD-ENGINE-001.2 · Persistent lead intelligence schema
Отдельный файл отчёта для этой задачи не найден или не указан. Показан сохранённый результат задачи.
I added the safe migrations and ran them on the live data/leads.db. The seven imported cards and the reviews table are unchanged: a hash of the original leads, reviews and companies rows was identical before and after. All 22 tests in python3 -m unittest tests.test_migrations -v pass, and so does the full suite (68 tests, including the existing campaign-config tests).
Files
app/migrations.py: the migration runner. Run it with python3 -m app.migrations [db] [--no-backup].tests/test_migrations.py: the acceptance tests.docs/storage-schema.md: a short reference for the next tasks, including how to roll back.
How the migration stays safe
- Additive only. It creates new tables and adds new columns. The existing tables
campaigns, companies, leads, reviews and imports keep every original value. - All or nothing. Every pending migration runs in one transaction. If any original row changes, a column is lost or a link between tables breaks, everything is undone.
- A bug found during testing: Python's
executescript() quietly commits mid-migration, which would have broken this. The runner now runs statements one at a time instead. - Backup first. A copy of the database is saved before anything runs. Today's copy is
data/backups/leads-20261009T120123613158Z-pre-v2.db. - Factory DB is never touched. The runner refuses any file named
factory.db, anything under /home/iovon/ai-factory, and any database that contains Factory tables. Tests cover all three cases. - Safe to re-run. A second run applies nothing and adds no rows (tested).
New tables: campaign_configs, research_runs, signals, evidence, assessments, provenance, dedup_keys, schema_migrations. New columns were added to the five existing tables, e.g. normalized name and domain for companies, and reviewer fields for reviews.
Rules the database itself enforces
- No automatic VERIFIED:
- A record can't be inserted as VERIFIED.
- It can only move to VERIFIED from SUPPORTED, by a named human reviewer.
- VERIFIED evidence must have a source URL.
- Inferences can never become SUPPORTED or VERIFIED.
- A source URL must say where it came from (fetched in a run or supplied by a human). Generated URLs are rejected.
- Source records can't be edited or deleted.
- Review history can only grow: verdicts and notes can't be changed or deleted.
- Saved campaign config versions can't be changed.
- Duplicate companies, leads, signals and evidence are rejected via unique keys.
What the live database now holds
- The 7 cards were copied into the new tables as 7 signals, 7 evidence records and 7 assessments, all UNVERIFIED.
- The new tables add no URLs, dates, scores or classifications to these records.
- 35 source records point each item back to the original import (task LEAD-003.3, execution 24, with its checksum).
- There were 0 reviews in the database, so there was no review history to carry over. The tests do check that reviews survive, using sample review data.
- The app's existing database queries still work (tested). The live app wasn't started, because FastAPI isn't installed in the system Python I tested with.
For the next task
- Contacts and manual field corrections (overrides) weren't in this task's instruction, so they have no tables yet. They are listed under LEAD-ENGINE-001.2 in the roadmap.
- The pilot config has not been loaded into
campaign_configs.
[truncated]
Материалы