@gobing-ai/ts-db 0.5.26 → 0.5.27

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.
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,yDAAyD;IACzD,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AA+ED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDnG"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,SAAS,EAAa,MAAM,WAAW,CAAC;AAGtD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,yDAAyD;IACzD,MAAM,CAAC,EAAE,eAAe,CAAC;CAC5B;AAkFD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDnG"}
package/dist/migrate.js CHANGED
@@ -24,7 +24,9 @@ function validateMigrationTableName(table) {
24
24
  * Apply migrations from embedded SQL strings (for compiled binaries).
25
25
  *
26
26
  * Checks the journal table and applies only migrations that haven't run yet.
27
- * Each migration is executed with adapter.exec() for file-based or adapter.run() for journal tracking.
27
+ * Each migration's SQL statements and its journal INSERT run as one
28
+ * `adapter.batch` call — a single SQLite transaction, atomic per migration
29
+ * (task 0113): a journal failure rolls the schema changes back with it.
28
30
  */
29
31
  async function applyEmbeddedMigrations(adapter, journalTable, logger) {
30
32
  // The caller (`applyMigrations`) already ran the journal name through
@@ -48,16 +50,18 @@ async function applyEmbeddedMigrations(adapter, journalTable, logger) {
48
50
  if (appliedHashes.has(migration.hash))
49
51
  continue;
50
52
  logger.info(`Applying embedded migration: ${migration.tag}`);
51
- // Split on semicolons and execute each non-empty statement
53
+ // Split on semicolons; batch the migration's statements with its journal
54
+ // INSERT so they commit or roll back together (task 0113, ADR-020 seam).
52
55
  const statements = migration.sql
53
56
  .split(';')
54
57
  .map((s) => s.trim())
55
58
  .filter((s) => s.length > 0);
56
- for (const stmt of statements) {
57
- await adapter.exec(stmt);
58
- }
59
- // Record in journal
60
- await adapter.run(`INSERT INTO "${journalTable}" (hash, created_at) VALUES (?, ?)`, migration.hash, Date.now());
59
+ const ops = statements.map((sql) => ({ sql, params: [] }));
60
+ ops.push({
61
+ sql: `INSERT INTO "${journalTable}" (hash, created_at) VALUES (?, ?)`,
62
+ params: [migration.hash, Date.now()],
63
+ });
64
+ await adapter.batch(ops);
61
65
  applied++;
62
66
  }
63
67
  if (applied > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-db",
3
- "version": "0.5.26",
3
+ "version": "0.5.27",
4
4
  "description": "@gobing-ai/ts-db — a drizzle-free database facade: typed DAOs over Bun SQLite / Cloudflare D1, a small predicate query spec, single-source-of-truth tables, and migrations. Drizzle stays an internal detail.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -66,8 +66,8 @@
66
66
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-db-v<version> && git push --tags' && exit 1"
67
67
  },
68
68
  "dependencies": {
69
- "@gobing-ai/ts-runtime": "^0.5.26",
70
- "@gobing-ai/ts-utils": "^0.5.26"
69
+ "@gobing-ai/ts-runtime": "^0.5.27",
70
+ "@gobing-ai/ts-utils": "^0.5.27"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "drizzle-orm": ">=0.38.0",
package/src/migrate.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { FileSystem } from '@gobing-ai/ts-runtime';
2
2
  import { getProcessCwd, resolvePath } from '@gobing-ai/ts-runtime';
3
3
 
4
- import type { DbAdapter } from './adapter';
4
+ import type { DbAdapter, DbBatchOp } from './adapter';
5
5
  import { embeddedMigrations } from './embedded-migrations';
6
6
 
7
7
  /**
@@ -59,7 +59,9 @@ function validateMigrationTableName(table: string): string {
59
59
  * Apply migrations from embedded SQL strings (for compiled binaries).
60
60
  *
61
61
  * Checks the journal table and applies only migrations that haven't run yet.
62
- * Each migration is executed with adapter.exec() for file-based or adapter.run() for journal tracking.
62
+ * Each migration's SQL statements and its journal INSERT run as one
63
+ * `adapter.batch` call — a single SQLite transaction, atomic per migration
64
+ * (task 0113): a journal failure rolls the schema changes back with it.
63
65
  */
64
66
  async function applyEmbeddedMigrations(
65
67
  adapter: DbAdapter,
@@ -88,18 +90,19 @@ async function applyEmbeddedMigrations(
88
90
 
89
91
  logger.info(`Applying embedded migration: ${migration.tag}`);
90
92
 
91
- // Split on semicolons and execute each non-empty statement
93
+ // Split on semicolons; batch the migration's statements with its journal
94
+ // INSERT so they commit or roll back together (task 0113, ADR-020 seam).
92
95
  const statements = migration.sql
93
96
  .split(';')
94
97
  .map((s) => s.trim())
95
98
  .filter((s) => s.length > 0);
96
99
 
97
- for (const stmt of statements) {
98
- await adapter.exec(stmt);
99
- }
100
-
101
- // Record in journal
102
- await adapter.run(`INSERT INTO "${journalTable}" (hash, created_at) VALUES (?, ?)`, migration.hash, Date.now());
100
+ const ops: DbBatchOp[] = statements.map((sql) => ({ sql, params: [] }));
101
+ ops.push({
102
+ sql: `INSERT INTO "${journalTable}" (hash, created_at) VALUES (?, ?)`,
103
+ params: [migration.hash, Date.now()],
104
+ });
105
+ await adapter.batch(ops);
103
106
  applied++;
104
107
  }
105
108