-
Notifications
You must be signed in to change notification settings - Fork 0
Migration Guide
Nick edited this page Nov 21, 2025
·
1 revision
This migration adds two new columns to the rule_evaluations table:
-
f1_score: F1-score metric (harmonic mean of precision and recall) -
previous_precision: Previous precision value for drift detection
make migrate-dbpoetry run python scripts/migrate_add_evaluation_metrics.pyTo verify that the migration was successful:
make check-db-schemaOr directly:
poetry run python scripts/check_db_schema.py-
Checks existing columns: Verifies if
f1_scoreandprevious_precisionalready exist - Adds missing columns: Adds columns only if they don't exist (idempotent)
- Supports both SQLite and PostgreSQL: Automatically detects database type and uses appropriate SQL
- Idempotent: Safe to run multiple times
- Non-destructive: Only adds columns, doesn't modify existing data
- Backward compatible: Existing code continues to work (columns are nullable)
Once migration is complete:
- New evaluations will automatically include
f1_scoreandprevious_precision - Existing evaluations will have
NULLvalues for these fields (which is fine) - Drift detection will work for new evaluations
Error: "table rule_evaluations does not exist"
- Run
init_db()first to create tables - Or ensure your database is properly initialized
Error: "column already exists"
- This is normal if migration was already run
- Migration is idempotent and handles this case
PostgreSQL permission errors
- Ensure database user has
ALTER TABLEpermissions - Check database connection settings
If automatic migration fails, you can run SQL manually:
SQLite:
ALTER TABLE rule_evaluations ADD COLUMN f1_score REAL;
ALTER TABLE rule_evaluations ADD COLUMN previous_precision REAL;PostgreSQL:
ALTER TABLE rule_evaluations ADD COLUMN f1_score FLOAT;
ALTER TABLE rule_evaluations ADD COLUMN previous_precision FLOAT;