@vibeorm/migrate 2.0.0-alpha.5 → 2.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/execute.d.ts +26 -1
- package/dist/execute.d.ts.map +1 -1
- package/dist/index.js +48 -19
- package/dist/index.js.map +4 -4
- package/dist/runner.d.ts +48 -22
- package/dist/runner.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/runner.d.ts
CHANGED
|
@@ -2,21 +2,40 @@
|
|
|
2
2
|
* Migration runner: generate named migrations from IR diffs, apply them with
|
|
3
3
|
* bookkeeping in `_vibe_migrations`, report status, and repair records.
|
|
4
4
|
*
|
|
5
|
-
* Concurrency: `applyMigrations`
|
|
6
|
-
* `pg_advisory_lock(1447645253)` on postgres ("VIBE" in
|
|
7
|
-
* released in a finally), `GET_LOCK('vibeorm_migrate', 60)`
|
|
8
|
-
* VIBE_MIGRATION on timeout). sqlite needs none: it is
|
|
9
|
-
* `BEGIN` serializes. Locks are session-scoped — the
|
|
10
|
-
* (types.ts) requires one session for the whole
|
|
5
|
+
* Concurrency: `applyMigrations` and `rollbackMigration` take an advisory lock
|
|
6
|
+
* for the whole run — `pg_advisory_lock(1447645253)` on postgres ("VIBE" in
|
|
7
|
+
* ASCII, blocking, released in a finally), `GET_LOCK('vibeorm_migrate', 60)`
|
|
8
|
+
* on mysql (throws VIBE_MIGRATION on timeout). sqlite needs none: it is
|
|
9
|
+
* single-writer and `BEGIN` serializes. Locks are session-scoped — the
|
|
10
|
+
* SqlExecutor contract (types.ts) requires one session for the whole
|
|
11
|
+
* operation.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
+
* Lock ORDER matters: the lock is taken BEFORE `ensureMigrationsTable`, never
|
|
14
|
+
* after. Two concurrent first-time runs against a fresh postgres database
|
|
15
|
+
* would otherwise both issue `CREATE TABLE IF NOT EXISTS _vibe_migrations`,
|
|
16
|
+
* which is a catalog race on postgres (a duplicate-key error on
|
|
17
|
+
* `pg_type_typname_nsp_index`, not a no-op). `migrationStatus` and
|
|
18
|
+
* `resolveMigration` deliberately take NO lock — wrapping reads in the
|
|
19
|
+
* migration lock would make `status` block behind a running migrate — so two
|
|
20
|
+
* concurrent FIRST-EVER `status`/`resolve` calls on a fresh database can still
|
|
21
|
+
* hit that race; retrying either is enough, since the table then exists.
|
|
22
|
+
*
|
|
23
|
+
* Execution strategy per dialect (`DIALECT_CAPABILITIES[dialect]`) AND per
|
|
24
|
+
* script:
|
|
13
25
|
*
|
|
14
26
|
* - transactionalDdl (postgres, sqlite): each migration runs inside
|
|
15
|
-
* BEGIN/COMMIT with its bookkeeping INSERT — atomic.
|
|
16
|
-
*
|
|
17
|
-
* (execute.ts `usesSelfManagedTransactions`)
|
|
18
|
-
*
|
|
19
|
-
*
|
|
27
|
+
* BEGIN/COMMIT with its bookkeeping INSERT — atomic.
|
|
28
|
+
* - EXCEPT sqlite scripts containing a table-rebuild block, which manage their
|
|
29
|
+
* own transactions (execute.ts `usesSelfManagedTransactions`) and therefore
|
|
30
|
+
* cannot be wrapped. Those take the SAME per-statement bookkeeping as mysql
|
|
31
|
+
* (below). They are NOT simply "re-runnable": a pure rebuild block is
|
|
32
|
+
* effectively idempotent, but any plain statement in the same script
|
|
33
|
+
* auto-commits on its own, so without a recorded statement_index a crash
|
|
34
|
+
* wedged the migration forever (every later run replayed statements that had
|
|
35
|
+
* already run). Resuming into a rebuild block rewinds to that block's
|
|
36
|
+
* `PRAGMA foreign_keys=OFF` (execute.ts `selfManagedResumeStart`): the block
|
|
37
|
+
* is transactional, so nothing of it survived, and the pragma is
|
|
38
|
+
* session-scoped and gone after a crash.
|
|
20
39
|
* - mysql (transactionalDdl: false — DDL auto-commits): the runner records
|
|
21
40
|
* PER-STATEMENT progress instead. The row is inserted up front
|
|
22
41
|
* (statement_index 0), advanced after every statement, and on failure the
|
|
@@ -26,6 +45,10 @@
|
|
|
26
45
|
* reaches the statement count (or its checksum is empty — resolveMigration
|
|
27
46
|
* records, which store statement_index 2147483647).
|
|
28
47
|
*
|
|
48
|
+
* `usesStatementBookkeeping` is the ONE predicate deciding which of the two
|
|
49
|
+
* regimes a (dialect, script) pair is in; apply, status and rollback all read
|
|
50
|
+
* it, so they can never disagree about whether a record is complete.
|
|
51
|
+
*
|
|
29
52
|
* Checksums (sha256 over the joined SQL) pin a migration's content:
|
|
30
53
|
* re-applying a renamed-or-edited migration is a VIBE_MIGRATION error, never
|
|
31
54
|
* a silent divergence.
|
|
@@ -61,7 +84,8 @@ export declare function generateMigration(params: {
|
|
|
61
84
|
* Apply migrations in order under an advisory lock (see module doc).
|
|
62
85
|
* Already-recorded migrations are checksum-verified and skipped; a mismatch
|
|
63
86
|
* throws VIBE_MIGRATION (a recorded migration whose SQL changed is
|
|
64
|
-
* corruption, not drift to paper over).
|
|
87
|
+
* corruption, not drift to paper over). Where progress is recorded per
|
|
88
|
+
* statement (mysql, and self-managed sqlite scripts), a partially-applied
|
|
65
89
|
* migration RESUMES from its recorded statement_index. Records created by
|
|
66
90
|
* `resolveMigration` (empty checksum) skip verification.
|
|
67
91
|
*/
|
|
@@ -101,15 +125,17 @@ export declare function resolveMigration(params: {
|
|
|
101
125
|
* the record pins a checksum — its up SQL must still match (rolling back with
|
|
102
126
|
* drifted files would run a down that no longer mirrors what was applied).
|
|
103
127
|
*
|
|
104
|
-
* Dialect behavior mirrors apply
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
128
|
+
* Dialect behavior mirrors apply exactly (same `usesStatementBookkeeping`
|
|
129
|
+
* predicate, read over the DOWN script): postgres/sqlite run the down inside
|
|
130
|
+
* BEGIN/COMMIT with the bookkeeping DELETE (atomic). mysql DDL auto-commits,
|
|
131
|
+
* and a sqlite down containing a table-rebuild block cannot be wrapped, so
|
|
132
|
+
* both record progress per-statement in the existing `statement_index`
|
|
133
|
+
* column, NEGATIVE to mark the rollback direction: after k down statements,
|
|
134
|
+
* the row stores -(k+1). A failed rollback resumes from the recorded
|
|
135
|
+
* statement on the next call; `applyMigrations` refuses a mid-rollback record
|
|
136
|
+
* (that check reads the sign only, so it holds for every dialect). A
|
|
137
|
+
* partially APPLIED migration cannot be rolled back — its down mirrors the
|
|
138
|
+
* full up; finish applying (apply resumes) or repair with `resolveMigration`.
|
|
113
139
|
*/
|
|
114
140
|
export declare function rollbackMigration(params: {
|
|
115
141
|
executor: SqlExecutor;
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgBxE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI7F,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,EAAE,MAA2B,CAAC;AAsChE,iDAAiD;AACjD,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,QAAQ,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhB;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAAG,MAAM,CAE5E;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE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": "@vibeorm/migrate",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "Migration engine for VibeORM v2 — IR differ, per-dialect DDL, migration runner, introspection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"orm",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"bun": ">=1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@vibeorm/schema": "2.0.0-alpha.
|
|
48
|
-
"@vibeorm/sql": "2.0.0-alpha.
|
|
47
|
+
"@vibeorm/schema": "2.0.0-alpha.5",
|
|
48
|
+
"@vibeorm/sql": "2.0.0-alpha.5"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|