harbor run -t datacurve/sqlite-utils-safe-import-checkpointsharbor download datacurve/sqlite-utils-safe-import-checkpointsBulk imports can partially fail, leaving databases inconsistent. Implement a "safe import" mode that creates rollback checkpoints, validates table invariants after writes, and commits only on success. On any safe-mode failure, rollback to the exact pre-operation state including schema changes (tables/columns/indexes/triggers).
Database API (sqlite_utils.Database)
Checkpoints
Checkpoint rules: commit/rollback finalizes an id (further commit/rollback => CheckpointNotActiveError); unknown/cleaned ids => CheckpointNotFoundError; cleanup_checkpoint removes the id; nested checkpoints supported.
Import invariants (persistent in DB)
Evaluation: if sql starts with SELECT, execute it and treat the first column of the first row as truthy/falsy; otherwise treat sql as an expression (aggregate expressions like COUNT/SUM/AVG/MIN/MAX/... evaluate once for the table, non-aggregate expressions must be true for every row).
Safe operations
Return (strict=False): {success: true} or {success: false, checkpoint_id: str, failures: list, error_report: str}; failures may be empty for non-invariant SQL/insert errors. Strict: rollback then raise; invariant failures must mention validation/invariants (contains "valid"/"validation"/"invariant").
CLI
Update CLI docs.
IMPORTANT: Please work on this in a new branch from main and commit everything when you are done.