Files
DumiFlex 17386f7990 feat(engine): atomic import commit + snapshot undo with 7-bucket dispatch
Adds engine/importer.py exposing commit_import / get_undo_entry /
undo_import. The committer applies a classified adds/replaces/renames
payload inside a single sqlite transaction, dispatching by `kind` to
the modules table (5 module types), bundles, or module_categories.
Module writes recompute snapshot_fingerprint; bundle writes recompute
payload_hash; categories use case-insensitive name-based merge
(matching the legacy import_bundle handler).

Every successful commit persists an import_undo row with enough
metadata (imported_records, replaced_snapshots, rename_map) to
reverse the commit. undo_import restores replaced rows bit-for-bit
(preserving original version + payload_hash + timestamps) and
deletes inserted rows, then evicts the undo entry.

Migration 007 creates the import_undo metadata table. Adds
17 importer tests covering adds across all 7 buckets, replace
snapshotting, rename with old→new mapping, collision rollback,
and undo restore/delete paths.
2026-05-22 21:52:11 +03:00

24 lines
1.1 KiB
SQL

-- Import undo metadata. Stores the snapshot bundle needed to reverse a
-- single `commit_import` call: which ids the commit inserted (so undo
-- deletes them) and the full pre-replace row for every id the commit
-- overwrote (so undo restores them).
--
-- One row per import. The row id is the `undo_id` returned by
-- `commit_import` and consumed by `undo_import`. There is no GC policy
-- in this migration — the wp_api layer (Task 14) decides when to evict
-- old undo entries (e.g. "keep last N" or "expire after T").
--
-- All three JSON columns are opaque to SQLite — the importer module
-- defines + reads the shapes. See `engine/importer.py` module docstring
-- for the schema.
CREATE TABLE IF NOT EXISTS import_undo (
id TEXT PRIMARY KEY,
created_at TEXT NOT NULL,
imported_records TEXT NOT NULL, -- JSON list[{kind, id}]
replaced_snapshots TEXT NOT NULL, -- JSON dict[id, {kind, row}]
rename_map TEXT NOT NULL -- JSON dict[old_id, new_id]
);
CREATE INDEX IF NOT EXISTS idx_import_undo_created_at ON import_undo(created_at DESC);