@b9g/zen 0.1.4 → 0.1.5

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/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.5] - 2025-12-28
9
+
10
+ ### Fixed
11
+
12
+ - `ensureTable()`, `ensureView()`, `ensureConstraints()`, `copyColumn()` no longer throw "cannot start a transaction within a transaction" when called inside `upgradeneeded` handler (#12)
13
+
8
14
  ## [0.1.4] - 2025-12-28
9
15
 
10
16
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b9g/zen",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Define Zod tables. Write raw SQL. Get typed objects.",
5
5
  "keywords": [
6
6
  "database",
package/src/zen.js CHANGED
@@ -1236,6 +1236,7 @@ var Database = class extends EventTarget {
1236
1236
  #version = 0;
1237
1237
  #opened = false;
1238
1238
  #tables = [];
1239
+ #inMigrationLock = false;
1239
1240
  constructor(driver, options) {
1240
1241
  super();
1241
1242
  this.#driver = driver;
@@ -1282,9 +1283,19 @@ var Database = class extends EventTarget {
1282
1283
  }
1283
1284
  };
1284
1285
  if (this.#driver.withMigrationLock) {
1285
- await this.#driver.withMigrationLock(runMigration);
1286
+ this.#inMigrationLock = true;
1287
+ try {
1288
+ await this.#driver.withMigrationLock(runMigration);
1289
+ } finally {
1290
+ this.#inMigrationLock = false;
1291
+ }
1286
1292
  } else {
1287
- await this.#driver.transaction(runMigration);
1293
+ this.#inMigrationLock = true;
1294
+ try {
1295
+ await this.#driver.transaction(runMigration);
1296
+ } finally {
1297
+ this.#inMigrationLock = false;
1298
+ }
1288
1299
  }
1289
1300
  this.#version = version;
1290
1301
  this.#opened = true;
@@ -2071,6 +2082,9 @@ var Database = class extends EventTarget {
2071
2082
  );
2072
2083
  }
2073
2084
  const doEnsure = () => this.#driver.ensureTable(table2);
2085
+ if (this.#inMigrationLock) {
2086
+ return await doEnsure();
2087
+ }
2074
2088
  if (this.#driver.withMigrationLock) {
2075
2089
  return await this.#driver.withMigrationLock(doEnsure);
2076
2090
  }
@@ -2094,6 +2108,9 @@ var Database = class extends EventTarget {
2094
2108
  );
2095
2109
  }
2096
2110
  const doEnsure = () => this.#driver.ensureView(viewObj);
2111
+ if (this.#inMigrationLock) {
2112
+ return await doEnsure();
2113
+ }
2097
2114
  if (this.#driver.withMigrationLock) {
2098
2115
  return await this.#driver.withMigrationLock(doEnsure);
2099
2116
  }
@@ -2128,6 +2145,9 @@ var Database = class extends EventTarget {
2128
2145
  );
2129
2146
  }
2130
2147
  const doEnsure = () => this.#driver.ensureConstraints(table2);
2148
+ if (this.#inMigrationLock) {
2149
+ return await doEnsure();
2150
+ }
2131
2151
  if (this.#driver.withMigrationLock) {
2132
2152
  return await this.#driver.withMigrationLock(doEnsure);
2133
2153
  }
@@ -2163,6 +2183,9 @@ var Database = class extends EventTarget {
2163
2183
  }
2164
2184
  if (this.#driver.copyColumn) {
2165
2185
  const doCopy2 = () => this.#driver.copyColumn(table2, fromField, toField);
2186
+ if (this.#inMigrationLock) {
2187
+ return await doCopy2();
2188
+ }
2166
2189
  if (this.#driver.withMigrationLock) {
2167
2190
  return await this.#driver.withMigrationLock(doCopy2);
2168
2191
  }
@@ -2200,6 +2223,9 @@ var Database = class extends EventTarget {
2200
2223
  );
2201
2224
  }
2202
2225
  };
2226
+ if (this.#inMigrationLock) {
2227
+ return await doCopy();
2228
+ }
2203
2229
  if (this.#driver.withMigrationLock) {
2204
2230
  return await this.#driver.withMigrationLock(doCopy);
2205
2231
  }