durable-db 0.0.2 → 0.0.4
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/cli/bin.js +6 -6
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +6 -6
- package/dist/{cli-Cr9686BF.js → cli-AzoPlqMA.js} +6 -6
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +2 -2
- package/dist/{context-BuIiIQ6K.js → context-BcWMofTp.js} +1 -1
- package/dist/db/index.d.ts +3 -3
- package/dist/db/index.js +52 -11
- package/dist/{defineDatabase-jBv90-Pk.d.ts → defineDatabase-B8do9yYZ.d.ts} +1 -1
- package/dist/{defineDatabase-CONf4xFC.js → defineDatabase-C91B-LMQ.js} +1 -1
- package/dist/{generator-BUPP9scJ.js → generator-B4yBWHRz.js} +24 -2
- package/dist/{index-BFM5d0FP.d.ts → index-nm3-NwUh.d.ts} +23 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/migrations/generator.d.ts +1 -1
- package/dist/migrations/generator.js +2 -2
- package/dist/migrations/snapshot.d.ts +1 -1
- package/dist/migrations/snapshot.js +1 -1
- package/dist/out-CuoxKfaH.js +7446 -0
- package/dist/{push-BgQ5cnfH.js → push-BymAOkB9.js} +4 -4
- package/dist/push-CT2aX_AM.js +8 -0
- package/dist/registry.d.ts +3 -1
- package/dist/registry.js +3 -3
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/{state-BCcvNN-M.js → state-BUCIODvB.js} +1 -1
- package/dist/transport/protocol.js +1 -1
- package/dist/transport/websocket.js +1 -1
- package/dist/vite/durableDb.js +42 -12
- package/dist/{websocket-Dx1fqwnF.js → websocket-Cwc7933g.js} +1 -1
- package/package.json +1 -1
- package/dist/push-BkkaslPd.js +0 -8
- /package/dist/{index-CqVMaMYY.d.ts → index-DN2vKPw_.d.ts} +0 -0
- /package/dist/{parser-CbX54Flt.js → parser-qOiKNcYc.js} +0 -0
- /package/dist/{protocol-g_plhPOY.js → protocol-v7B4_9xU.js} +0 -0
- /package/dist/{schema-CpzTOfZ6.d.ts → schema-CjGvnsaZ.d.ts} +0 -0
- /package/dist/{schema-BOtrGnzM.js → schema-ou5L5I9Y.js} +0 -0
- /package/dist/{snapshot-D170nL7i.js → snapshot-CgEvcMZb.js} +0 -0
- /package/dist/{snapshot-C162qYoA.d.ts → snapshot-oD3wAJF2.d.ts} +0 -0
- /package/dist/{state-FOEjpgJ6.js → state-DDHYOyvD.js} +0 -0
package/dist/cli/bin.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "../debug-BZJbKybf.js";
|
|
3
|
-
import "../state-
|
|
4
|
-
import "../snapshot-
|
|
5
|
-
import "../generator-
|
|
6
|
-
import "../parser-
|
|
7
|
-
import "../push-
|
|
8
|
-
import { n as registerDbCommands } from "../cli-
|
|
3
|
+
import "../state-DDHYOyvD.js";
|
|
4
|
+
import "../snapshot-CgEvcMZb.js";
|
|
5
|
+
import "../generator-B4yBWHRz.js";
|
|
6
|
+
import "../parser-qOiKNcYc.js";
|
|
7
|
+
import "../push-BymAOkB9.js";
|
|
8
|
+
import { n as registerDbCommands } from "../cli-AzoPlqMA.js";
|
|
9
9
|
import { Command } from "commander";
|
|
10
10
|
|
|
11
11
|
//#region src/cli/bin.ts
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as Snapshot } from "../snapshot-
|
|
2
|
-
import { l as DatabaseInfo } from "../defineDatabase-
|
|
3
|
-
import "../index-
|
|
1
|
+
import { t as Snapshot } from "../snapshot-oD3wAJF2.js";
|
|
2
|
+
import { l as DatabaseInfo } from "../defineDatabase-B8do9yYZ.js";
|
|
3
|
+
import "../index-nm3-NwUh.js";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
6
|
//#region src/cli/command.d.ts
|
package/dist/cli/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "../debug-BZJbKybf.js";
|
|
2
|
-
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-
|
|
3
|
-
import "../snapshot-
|
|
4
|
-
import "../generator-
|
|
5
|
-
import "../parser-
|
|
6
|
-
import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-
|
|
7
|
-
import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-
|
|
2
|
+
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, f as loadDevMigrations, l as getInstanceKey, m as loadDevState, s as getDevEpoch } from "../state-DDHYOyvD.js";
|
|
3
|
+
import "../snapshot-CgEvcMZb.js";
|
|
4
|
+
import "../generator-B4yBWHRz.js";
|
|
5
|
+
import "../parser-qOiKNcYc.js";
|
|
6
|
+
import { a as loadSchema, i as discoverDatabases, n as pushOne, o as reportCliError, r as diffSchema, t as push } from "../push-BymAOkB9.js";
|
|
7
|
+
import { a as resetAndPush, c as generate, i as reset, l as generateOne, n as registerDbCommands, o as formatStatus, r as validate, s as status, t as createDbCommand } from "../cli-AzoPlqMA.js";
|
|
8
8
|
|
|
9
9
|
export { createDbCommand, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, push, pushOne, registerDbCommands, reportCliError, reset, resetAndPush, saveDevState, status, validate };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { i as init_debug, t as debugCli } from "./debug-BZJbKybf.js";
|
|
2
|
-
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, d as init_state, f as loadDevMigrations, m as loadDevState, t as clearDatabaseDevState } from "./state-
|
|
3
|
-
import { a as hashSnapshot } from "./snapshot-
|
|
4
|
-
import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-
|
|
5
|
-
import { a as resolveImportPath } from "./parser-
|
|
6
|
-
import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-
|
|
2
|
+
import { _ as saveDevState, a as generateEpoch, c as getDevPaths, d as init_state, f as loadDevMigrations, m as loadDevState, t as clearDatabaseDevState } from "./state-DDHYOyvD.js";
|
|
3
|
+
import { a as hashSnapshot } from "./snapshot-CgEvcMZb.js";
|
|
4
|
+
import { a as loadMigrationFiles, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, s as loadSnapshot, t as buildAndLoadSchema } from "./generator-B4yBWHRz.js";
|
|
5
|
+
import { a as resolveImportPath } from "./parser-qOiKNcYc.js";
|
|
6
|
+
import { a as loadSchema, i as discoverDatabases, o as reportCliError, r as diffSchema, t as push } from "./push-BymAOkB9.js";
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
import { Command } from "commander";
|
|
@@ -322,7 +322,7 @@ async function reset(ctx = {}, options = {}) {
|
|
|
322
322
|
* Convenience function that combines reset + push
|
|
323
323
|
*/
|
|
324
324
|
async function resetAndPush(ctx = {}, options = {}) {
|
|
325
|
-
const { push: push$1 } = await import("./push-
|
|
325
|
+
const { push: push$1 } = await import("./push-CT2aX_AM.js");
|
|
326
326
|
return {
|
|
327
327
|
reset: await reset(ctx, options),
|
|
328
328
|
push: await push$1(ctx)
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-
|
|
1
|
+
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../index-DN2vKPw_.js";
|
|
2
2
|
export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
|
package/dist/context/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../debug-BZJbKybf.js";
|
|
2
|
-
import "../state-
|
|
3
|
-
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-
|
|
2
|
+
import "../state-DDHYOyvD.js";
|
|
3
|
+
import { a as setTenantIdResolver, i as hasTenantId, n as getInstanceKey, r as getTenantId, t as getDevInstanceKeySuffix } from "../context-BcWMofTp.js";
|
|
4
4
|
|
|
5
5
|
export { getDevInstanceKeySuffix, getInstanceKey, getTenantId, hasTenantId, setTenantIdResolver };
|
package/dist/db/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-
|
|
2
|
-
import { _ as
|
|
3
|
-
export { Action, ActionConfig, ActionContext, ActionInfo, ArgsSchema, CamelCasePlugin, CompiledQuery, CreateKyselyOptions, DatabaseConfig, DatabaseDefinition, DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, DrizzleToKysely, InferArgs, Kysely, KyselyPlugin, Migration, MigrationAttemptInfo, Migrations, ParsedDatabaseFile, QueryResult, SchemaPlugin, SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
1
|
+
import { a as ActionInfo, c as DatabaseDefinition, d as InferArgs, f as ParsedDatabaseFile, i as ActionContext, l as DatabaseInfo, n as Action, o as ArgsSchema, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "../defineDatabase-B8do9yYZ.js";
|
|
2
|
+
import { _ as Migrations, a as QueryResult, b as createKyselyFromSql, c as DateSerializePlugin, d as createDrizzlePlugins, f as dateSerializers, g as MigrationSchemaConflictError, h as MigrationAttemptInfo, i as KyselyPlugin, l as DrizzleDefaultsPlugin, m as Migration, n as CompiledQuery, o as studio, p as CreateKyselyOptions, r as Kysely, s as type, t as CamelCasePlugin, u as SchemaPlugin, v as SqlExecutor, y as SqliteDurableObject } from "../index-nm3-NwUh.js";
|
|
3
|
+
export { Action, ActionConfig, ActionContext, ActionInfo, ArgsSchema, CamelCasePlugin, CompiledQuery, CreateKyselyOptions, DatabaseConfig, DatabaseDefinition, DatabaseInfo, DateSerializePlugin, DrizzleDefaultsPlugin, DrizzleToKysely, InferArgs, Kysely, KyselyPlugin, Migration, MigrationAttemptInfo, MigrationSchemaConflictError, Migrations, ParsedDatabaseFile, QueryResult, SchemaPlugin, SqlExecutor, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
package/dist/db/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as init_debug, n as debugMigrations } from "../debug-BZJbKybf.js";
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
2
|
+
import { t as type } from "../out-CuoxKfaH.js";
|
|
3
|
+
import { t as defineDatabase } from "../defineDatabase-C91B-LMQ.js";
|
|
4
4
|
import { SQLiteSyncDialect, getTableConfig } from "drizzle-orm/sqlite-core";
|
|
5
5
|
import { toCamelCase, toSnakeCase } from "drizzle-orm/casing";
|
|
6
6
|
import { DurableObject } from "cloudflare:workers";
|
|
@@ -394,6 +394,21 @@ function createKyselyFromSql(sqlStorage, options = {}) {
|
|
|
394
394
|
*/
|
|
395
395
|
const MAX_PITR_ATTEMPTS = 3;
|
|
396
396
|
/**
|
|
397
|
+
* Raised when a pending migration fails with "already exists": the storage
|
|
398
|
+
* holds schema objects the `__migrations` journal doesn't track. Common
|
|
399
|
+
* causes: migration files were renamed or regenerated after the storage was
|
|
400
|
+
* created, the storage was written by an older version of the database, or a
|
|
401
|
+
* previous attempt crashed partway through a chunk without PITR. Re-running
|
|
402
|
+
* can never succeed, so this carries recovery guidance instead of the raw
|
|
403
|
+
* SQLITE_ERROR.
|
|
404
|
+
*/
|
|
405
|
+
var MigrationSchemaConflictError = class extends Error {
|
|
406
|
+
constructor(message, options) {
|
|
407
|
+
super(message, options);
|
|
408
|
+
this.name = "MigrationSchemaConflictError";
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
397
412
|
* Truncate a SQL statement for logging. Collapses whitespace so multi-line
|
|
398
413
|
* statements render on one log line.
|
|
399
414
|
*/
|
|
@@ -573,17 +588,24 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
573
588
|
this.sql.exec(`
|
|
574
589
|
UPDATE __migration_attempts SET last_error = ? WHERE id = 'current'
|
|
575
590
|
`, errorMessage);
|
|
576
|
-
|
|
577
|
-
const remaining = Math.max(0, MAX_PITR_ATTEMPTS + 1 - attempts.attemptCount);
|
|
578
|
-
const pendingNames = Array.from(new Set(pending.map((p) => p.name))).join(", ");
|
|
579
|
-
console.error(`[database] Migration failed (attempt ${attempts.attemptCount}/${MAX_PITR_ATTEMPTS + 1}, ${remaining} PITR-protected retries remaining). Restoring to pre-migration bookmark. Pending: ${pendingNames || "(none)"}.`, error);
|
|
591
|
+
let restoreScheduled = false;
|
|
580
592
|
try {
|
|
581
593
|
await this.ctx.storage.onNextSessionRestoreBookmark(bookmark);
|
|
582
|
-
|
|
594
|
+
restoreScheduled = true;
|
|
583
595
|
} catch (pitrErr) {
|
|
584
596
|
const pitrMessage = pitrErr instanceof Error ? pitrErr.message : String(pitrErr);
|
|
585
|
-
if (
|
|
586
|
-
|
|
597
|
+
if (/does not (?:implement|support) point-in-time recovery/i.test(pitrMessage)) {
|
|
598
|
+
this.pitrAvailable = false;
|
|
599
|
+
this.pitrUnavailableReason = pitrMessage;
|
|
600
|
+
debugMigrations("PITR restore unsupported by this storage backend; disabling PITR (%s)", pitrMessage);
|
|
601
|
+
} else console.error(`[database] PITR restore failed (${pitrMessage}). Propagating the original migration error instead so you can fix the root cause.`);
|
|
602
|
+
}
|
|
603
|
+
if (restoreScheduled) {
|
|
604
|
+
const attempts = this.getMigrationAttempts();
|
|
605
|
+
const remaining = Math.max(0, MAX_PITR_ATTEMPTS + 1 - attempts.attemptCount);
|
|
606
|
+
const pendingNames = Array.from(new Set(pending.map((p) => p.name))).join(", ");
|
|
607
|
+
console.error(`[database] Migration failed (attempt ${attempts.attemptCount}/${MAX_PITR_ATTEMPTS + 1}, ${remaining} PITR-protected retries remaining). Restoring to pre-migration bookmark. Pending: ${pendingNames || "(none)"}.`, error);
|
|
608
|
+
this.ctx.abort("Restoring to pre-migration bookmark");
|
|
587
609
|
}
|
|
588
610
|
}
|
|
589
611
|
throw error;
|
|
@@ -634,11 +656,30 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
634
656
|
} catch (error) {
|
|
635
657
|
const location = currentStatement !== null ? ` stmt ${currentIndex}: ${formatStatementForLog(currentStatement)}` : " (while recording chunk as applied)";
|
|
636
658
|
console.error(`[database] Migration chunk failed: ${name}[${chunkIndex}]${location}`, error);
|
|
637
|
-
throw error;
|
|
659
|
+
throw this.toSchemaConflictError(error, name, chunkIndex) ?? error;
|
|
638
660
|
}
|
|
639
661
|
}
|
|
640
662
|
}
|
|
641
663
|
/**
|
|
664
|
+
* Translate an "already exists" failure on a pending migration into a
|
|
665
|
+
* {@link MigrationSchemaConflictError}. A chunk is only executed when the
|
|
666
|
+
* journal has no row for it, so "already exists" means storage and journal
|
|
667
|
+
* disagree about what has been applied — retrying can never succeed, and
|
|
668
|
+
* the raw SQLITE_ERROR doesn't tell the user how to get unstuck.
|
|
669
|
+
* Returns null when the error isn't this case.
|
|
670
|
+
*/
|
|
671
|
+
toSchemaConflictError(error, name, chunkIndex) {
|
|
672
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
673
|
+
if (!/already exists/i.test(message)) return null;
|
|
674
|
+
let journalNames = [];
|
|
675
|
+
try {
|
|
676
|
+
journalNames = this.sql.exec("SELECT DISTINCT name FROM __migrations").toArray().map((row) => row.name);
|
|
677
|
+
} catch {}
|
|
678
|
+
const known = new Set(Object.keys(this.migrations));
|
|
679
|
+
const untracked = journalNames.filter((n) => !known.has(n));
|
|
680
|
+
return new MigrationSchemaConflictError(`Migration "${name}" (chunk ${chunkIndex}) tried to create a schema object that already exists in storage, but the __migrations journal has no record of this migration being applied. ${untracked.length > 0 ? `The journal records migrations this build doesn't know about (${untracked.join(", ")}), which usually means the migration files were renamed or regenerated after this database's storage was created.` : "This usually means the storage was created by migrations under different names (renamed or regenerated migration files), by an older version of this database, or that a previous attempt crashed partway through a chunk."} To recover in local dev, run \`db reset\` to rotate to a fresh database (add --purge-local-storage to also delete the orphaned instance data, or wipe .wrangler/state yourself). In production, restore the original migration names, or baseline the journal by inserting rows into __migrations for the migrations whose schema is already present. Original error: ${message}`, { cause: error });
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
642
683
|
* Manually restore the DO to a specific PITR bookmark.
|
|
643
684
|
* The DO will restart on next access with the restored state.
|
|
644
685
|
*/
|
|
@@ -757,4 +798,4 @@ var SqliteDurableObject = class extends DurableObject {
|
|
|
757
798
|
};
|
|
758
799
|
|
|
759
800
|
//#endregion
|
|
760
|
-
export { CamelCasePlugin, DateSerializePlugin, DrizzleDefaultsPlugin, SchemaPlugin, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
801
|
+
export { CamelCasePlugin, DateSerializePlugin, DrizzleDefaultsPlugin, MigrationSchemaConflictError, SchemaPlugin, SqliteDurableObject, createDrizzlePlugins, createKyselyFromSql, dateSerializers, defineDatabase, studio, type };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { i as init_debug, n as debugMigrations } from "./debug-BZJbKybf.js";
|
|
2
|
-
import { i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "./snapshot-
|
|
2
|
+
import { i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "./snapshot-CgEvcMZb.js";
|
|
3
3
|
import * as fs from "node:fs";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
+
import * as os from "node:os";
|
|
5
6
|
import { pathToFileURL } from "node:url";
|
|
6
7
|
|
|
7
8
|
//#region src/migrations/generator.ts
|
|
@@ -139,6 +140,26 @@ async function loadSchemaModule(schemaPath, tableNames) {
|
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
/**
|
|
143
|
+
* Where to drop the transient transpiled-schema `.mjs`. We want a
|
|
144
|
+
* directory that (a) is on the app's node_modules resolution chain
|
|
145
|
+
* so the bundle's bare imports resolve, and (b) is NOT inside the
|
|
146
|
+
* watched `src/` tree (so dev-server watchers don't react to it).
|
|
147
|
+
* The app's `node_modules/.cache/durable-db/` satisfies both; if no
|
|
148
|
+
* node_modules is found walking up from the schema, fall back to the
|
|
149
|
+
* OS temp dir (the schema bundle's externals are usually resolvable
|
|
150
|
+
* relative to cwd in that case too).
|
|
151
|
+
*/
|
|
152
|
+
function resolveTempDir(schemaPath) {
|
|
153
|
+
let dir = path.dirname(path.resolve(schemaPath));
|
|
154
|
+
while (true) {
|
|
155
|
+
if (fs.existsSync(path.join(dir, "node_modules"))) return path.join(dir, "node_modules", ".cache", "durable-db");
|
|
156
|
+
const parent = path.dirname(dir);
|
|
157
|
+
if (parent === dir) break;
|
|
158
|
+
dir = parent;
|
|
159
|
+
}
|
|
160
|
+
return path.join(os.tmpdir(), "durable-db");
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
142
163
|
* Build schema module with esbuild and return the exports
|
|
143
164
|
* This is useful when the schema is TypeScript and needs transpilation
|
|
144
165
|
*/
|
|
@@ -153,7 +174,8 @@ async function buildAndLoadSchema(schemaPath, tableNames) {
|
|
|
153
174
|
target: "node18"
|
|
154
175
|
});
|
|
155
176
|
if (result.outputFiles?.length !== 1) throw new Error(`Unexpected esbuild output for ${schemaPath}`);
|
|
156
|
-
const tempDir =
|
|
177
|
+
const tempDir = resolveTempDir(schemaPath);
|
|
178
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
157
179
|
const tempFile = path.join(tempDir, `_schema_temp_${Date.now()}.mjs`);
|
|
158
180
|
try {
|
|
159
181
|
fs.writeFileSync(tempFile, result.outputFiles[0].text);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type as type$1 } from "arktype";
|
|
2
1
|
import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
|
|
3
2
|
import { DurableObject } from "cloudflare:workers";
|
|
4
3
|
import { CamelCasePlugin, CamelCasePlugin as CamelCasePlugin$1, CompiledQuery, Kysely, Kysely as Kysely$1, KyselyPlugin, KyselyPlugin as KyselyPlugin$1, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, QueryResult as QueryResult$1, RootOperationNode, UnknownRow } from "kysely";
|
|
5
4
|
import { Table } from "drizzle-orm";
|
|
6
5
|
import { studio } from "@outerbase/browsable-durable-object";
|
|
6
|
+
import { type as type$1 } from "arktype";
|
|
7
7
|
|
|
8
8
|
//#region src/db/SqliteDurableObject.d.ts
|
|
9
9
|
/**
|
|
@@ -78,6 +78,18 @@ interface MigrationStatus {
|
|
|
78
78
|
*/
|
|
79
79
|
pitrAttemptsRemaining: number;
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Raised when a pending migration fails with "already exists": the storage
|
|
83
|
+
* holds schema objects the `__migrations` journal doesn't track. Common
|
|
84
|
+
* causes: migration files were renamed or regenerated after the storage was
|
|
85
|
+
* created, the storage was written by an older version of the database, or a
|
|
86
|
+
* previous attempt crashed partway through a chunk without PITR. Re-running
|
|
87
|
+
* can never succeed, so this carries recovery guidance instead of the raw
|
|
88
|
+
* SQLITE_ERROR.
|
|
89
|
+
*/
|
|
90
|
+
declare class MigrationSchemaConflictError extends Error {
|
|
91
|
+
constructor(message: string, options?: ErrorOptions);
|
|
92
|
+
}
|
|
81
93
|
/**
|
|
82
94
|
* Base class for SQLite Durable Objects with migration support
|
|
83
95
|
*
|
|
@@ -179,6 +191,15 @@ declare abstract class SqliteDurableObject<Env = unknown> extends DurableObject<
|
|
|
179
191
|
* Apply a list of pending migration chunks.
|
|
180
192
|
*/
|
|
181
193
|
private applyMigrations;
|
|
194
|
+
/**
|
|
195
|
+
* Translate an "already exists" failure on a pending migration into a
|
|
196
|
+
* {@link MigrationSchemaConflictError}. A chunk is only executed when the
|
|
197
|
+
* journal has no row for it, so "already exists" means storage and journal
|
|
198
|
+
* disagree about what has been applied — retrying can never succeed, and
|
|
199
|
+
* the raw SQLITE_ERROR doesn't tell the user how to get unstuck.
|
|
200
|
+
* Returns null when the error isn't this case.
|
|
201
|
+
*/
|
|
202
|
+
private toSchemaConflictError;
|
|
182
203
|
/**
|
|
183
204
|
* Manually restore the DO to a specific PITR bookmark.
|
|
184
205
|
* The DO will restart on next access with the restored state.
|
|
@@ -325,4 +346,4 @@ declare class DateSerializePlugin implements KyselyPlugin {
|
|
|
325
346
|
*/
|
|
326
347
|
declare function createDrizzlePlugins(schema: Record<string, SQLiteTableWithColumns<any>>, camelCase?: boolean): KyselyPlugin[];
|
|
327
348
|
//#endregion
|
|
328
|
-
export {
|
|
349
|
+
export { Migrations as _, QueryResult$1 as a, createKyselyFromSql as b, DateSerializePlugin as c, createDrizzlePlugins as d, dateSerializers as f, MigrationSchemaConflictError as g, MigrationAttemptInfo as h, KyselyPlugin$1 as i, DrizzleDefaultsPlugin as l, Migration as m, CompiledQuery as n, studio as o, CreateKyselyOptions as p, Kysely$1 as r, type$1 as s, CamelCasePlugin$1 as t, SchemaPlugin as u, SqlExecutor as v, SqliteDurableObject as y };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-
|
|
2
|
-
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-
|
|
3
|
-
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-
|
|
4
|
-
import { type } from "arktype";
|
|
1
|
+
import { c as DatabaseDefinition, d as InferArgs, i as ActionContext, n as Action, r as ActionConfig, s as DatabaseConfig, t as defineDatabase, u as DrizzleToKysely } from "./defineDatabase-B8do9yYZ.js";
|
|
2
|
+
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./index-DN2vKPw_.js";
|
|
3
|
+
import { a as integer, c as real, d as uniqueIndex, i as index, l as table, n as blob, o as numeric, r as foreignKey, s as primaryKey, t as AnySQLiteColumn, u as text } from "./schema-CjGvnsaZ.js";
|
|
5
4
|
import { Kysely } from "kysely";
|
|
5
|
+
import { type } from "arktype";
|
|
6
6
|
export { type Action, type ActionConfig, type ActionContext, type AnySQLiteColumn, type DatabaseConfig, type DatabaseDefinition, type DrizzleToKysely, type InferArgs, type Kysely, blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./debug-BZJbKybf.js";
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import "./
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
2
|
+
import { t as type } from "./out-CuoxKfaH.js";
|
|
3
|
+
import { t as defineDatabase } from "./defineDatabase-C91B-LMQ.js";
|
|
4
|
+
import { a as numeric, c as table, i as integer, l as text, n as foreignKey, o as primaryKey, r as index, s as real, t as blob, u as uniqueIndex } from "./schema-ou5L5I9Y.js";
|
|
5
|
+
import "./state-DDHYOyvD.js";
|
|
6
|
+
import { a as setTenantIdResolver, i as hasTenantId, r as getTenantId } from "./context-BcWMofTp.js";
|
|
7
7
|
|
|
8
8
|
export { blob, defineDatabase, foreignKey, getTenantId, hasTenantId, index, integer, numeric, primaryKey, real, setTenantIdResolver, table, text, type, uniqueIndex };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../debug-BZJbKybf.js";
|
|
2
|
-
import "../snapshot-
|
|
3
|
-
import { a as loadMigrationFiles, c as parseSqlMigration, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, o as loadSchemaModule, r as generateMigration, s as loadSnapshot, t as buildAndLoadSchema } from "../generator-
|
|
2
|
+
import "../snapshot-CgEvcMZb.js";
|
|
3
|
+
import { a as loadMigrationFiles, c as parseSqlMigration, i as generateMigrationName, l as saveSnapshot, n as generateCreateTableSQL, o as loadSchemaModule, r as generateMigration, s as loadSnapshot, t as buildAndLoadSchema } from "../generator-B4yBWHRz.js";
|
|
4
4
|
|
|
5
5
|
export { buildAndLoadSchema, generateCreateTableSQL, generateMigration, generateMigrationName, loadMigrationFiles, loadSchemaModule, loadSnapshot, parseSqlMigration, saveSnapshot };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-
|
|
1
|
+
import { a as generateSnapshotId, i as generateSnapshotFromSchema, n as createEmptySnapshot, o as hashSnapshot, r as generateMigrationStatements, s as snapshotsEqual, t as Snapshot } from "../snapshot-oD3wAJF2.js";
|
|
2
2
|
export { Snapshot, createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema, generateSnapshotId, hashSnapshot, snapshotsEqual };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as hashSnapshot, i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-
|
|
1
|
+
import { a as hashSnapshot, i as generateSnapshotId, n as generateMigrationStatements, o as snapshotsEqual, r as generateSnapshotFromSchema, t as createEmptySnapshot } from "../snapshot-CgEvcMZb.js";
|
|
2
2
|
|
|
3
3
|
export { createEmptySnapshot, generateMigrationStatements, generateSnapshotFromSchema, generateSnapshotId, hashSnapshot, snapshotsEqual };
|