fix: implement migration tracking and make 0002 idempotent

- Add schema_migrations table to track applied migrations
- Migrate() now checks if a migration was already applied before running
- 0002 rewritten to use SAVEPOINT+ROLLBACK per column, making it safe
  to run even if some columns were partially added previously
- Each migration runs in its own transaction; INSERT into schema_migrations
  only happens if the SQL executes without error
- Bump VERSION 0.1.8 -> 0.1.9
This commit is contained in:
2026-07-05 23:54:14 -04:00
parent 3d956d43c2
commit 9a9d4cc753
3 changed files with 91 additions and 10 deletions
+24 -5
View File
@@ -1,8 +1,27 @@
ALTER TABLE nfs_exports ADD COLUMN read_only INTEGER NOT NULL DEFAULT 0;
ALTER TABLE nfs_exports ADD COLUMN async_ INTEGER NOT NULL DEFAULT 0;
ALTER TABLE nfs_exports ADD COLUMN root_squash INTEGER NOT NULL DEFAULT 1;
SAVEPOINT sp1;
ALTER TABLE nfs_exports ADD COLUMN read_only INTEGER NOT NULL DEFAULT 0;
ROLLBACK TO sp1;
SAVEPOINT sp2;
ALTER TABLE nfs_exports ADD COLUMN async_ INTEGER NOT NULL DEFAULT 0;
ROLLBACK TO sp2;
SAVEPOINT sp3;
ALTER TABLE nfs_exports ADD COLUMN root_squash INTEGER NOT NULL DEFAULT 1;
ROLLBACK TO sp3;
SAVEPOINT sp4;
ALTER TABLE nfs_exports ADD COLUMN subtree_check INTEGER NOT NULL DEFAULT 0;
ALTER TABLE nfs_exports ADD COLUMN fsid INTEGER NOT NULL DEFAULT 0;
ALTER TABLE nfs_exports ADD COLUMN advanced TEXT NOT NULL DEFAULT '{}';
ROLLBACK TO sp4;
SAVEPOINT sp5;
ALTER TABLE nfs_exports ADD COLUMN fsid INTEGER NOT NULL DEFAULT 0;
ROLLBACK TO sp5;
SAVEPOINT sp6;
ALTER TABLE nfs_exports ADD COLUMN advanced TEXT NOT NULL DEFAULT '{}';
ROLLBACK TO sp6;
CREATE INDEX IF NOT EXISTS idx_nfs_exports_fsid ON nfs_exports(fsid);
INSERT INTO schema_migrations (name) VALUES ('0002_nfs_structured.sql');