@prisma/orm-target-sqlite 8.0.0-rc.16-dev.6 → 8.0.0-rc.16-dev.8
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/{adapter-Cy1Xx1rP-CJcOoS_O.mjs → adapter-Cfp6xn4m-C6mXiIUR.mjs} +8 -11
- package/dist/adapter-Cfp6xn4m-C6mXiIUR.mjs.map +1 -0
- package/dist/adapter.mjs +2 -2
- package/dist/adapter__adapter.mjs +1 -1
- package/dist/adapter__control.mjs +3 -3
- package/dist/adapter__control.mjs.map +1 -1
- package/dist/adapter__runtime.mjs +1 -1
- package/dist/adapter__runtime.mjs.map +1 -1
- package/dist/adapter__sql-renderer.mjs +1 -1
- package/dist/{contract-free-CH8tBLLe.mjs → contract-free-CEPqytba.mjs} +2 -2
- package/dist/{contract-free-CH8tBLLe.mjs.map → contract-free-CEPqytba.mjs.map} +1 -1
- package/dist/{control-CtIPKwqL.mjs → control-L6vqj4xm.mjs} +6 -5
- package/dist/control-L6vqj4xm.mjs.map +1 -0
- package/dist/{ddl-CXduXyOT-nlDP6DGx.mjs → ddl-CDoa1Ehx-BOT670XL.mjs} +40 -3
- package/dist/ddl-CDoa1Ehx-BOT670XL.mjs.map +1 -0
- package/dist/{migration-Ccuxti02.d.mts → migration-CGyA6YVp.d.mts} +2 -2
- package/dist/{migration-Ccuxti02.d.mts.map → migration-CGyA6YVp.d.mts.map} +1 -1
- package/dist/{migration-65TwrHP0.mjs → migration-DNLfgvkg.mjs} +2 -2
- package/dist/{migration-65TwrHP0.mjs.map → migration-DNLfgvkg.mjs.map} +1 -1
- package/dist/{op-factory-call-B_WuATMN.d.mts → op-factory-call-BsGdsm8Y.d.mts} +57 -8
- package/dist/op-factory-call-BsGdsm8Y.d.mts.map +1 -0
- package/dist/{op-factory-call-Bwp3QS4h-MwflmSX3.mjs → op-factory-call-Cwsf4slr-DRGuq5SV.mjs} +136 -18
- package/dist/op-factory-call-Cwsf4slr-DRGuq5SV.mjs.map +1 -0
- package/dist/{planner-CFIbY54l.d.mts → planner-BOOV5W-E.d.mts} +16 -6
- package/dist/planner-BOOV5W-E.d.mts.map +1 -0
- package/dist/{planner-DcRJaFjk-C9iIWF69.mjs → planner-BWkNzmeL-BolB7hXm.mjs} +144 -16
- package/dist/planner-BWkNzmeL-BolB7hXm.mjs.map +1 -0
- package/dist/planner-produced-sqlite-migration-CBmtR7UQ.d.mts +1 -0
- package/dist/{planner-produced-sqlite-migration-DTTOgkuK-CppVPY1d.mjs → planner-produced-sqlite-migration-Da1JOGGe-Cibm7mK1.mjs} +4 -4
- package/dist/{planner-produced-sqlite-migration-DTTOgkuK-CppVPY1d.mjs.map → planner-produced-sqlite-migration-Da1JOGGe-Cibm7mK1.mjs.map} +1 -1
- package/dist/{planner-produced-sqlite-migration-DXcx0sOR-CcMQKE7n.d.mts → planner-produced-sqlite-migration-aUyGmguF-BORtY3yL.d.mts} +3 -3
- package/dist/planner-produced-sqlite-migration-aUyGmguF-BORtY3yL.d.mts.map +1 -0
- package/dist/{render-ops-KxAmAz6d-W2xyvA5y.mjs → render-ops-BfFXRHIV-x1i1WAHz.mjs} +16 -9
- package/dist/render-ops-BfFXRHIV-x1i1WAHz.mjs.map +1 -0
- package/dist/{sqlite-contract-view-BYR10usg-BteDAUZr.mjs → sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs} +4 -3
- package/dist/sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs.map +1 -0
- package/dist/{sqlite-migration-DckJS_3w-BIKXWN5h.mjs → sqlite-migration-Bz7SwolX-CHLtwGNa.mjs} +357 -62
- package/dist/sqlite-migration-Bz7SwolX-CHLtwGNa.mjs.map +1 -0
- package/dist/{sqlite-migration-BSUZhMDG-DZU3d7bZ.d.mts → sqlite-migration-Kqf6dAgP-DDc4wuXM.d.mts} +27 -3
- package/dist/sqlite-migration-Kqf6dAgP-DDc4wuXM.d.mts.map +1 -0
- package/dist/target.d.mts +7 -7
- package/dist/target.mjs +12 -12
- package/dist/target__contract-free.mjs +2 -2
- package/dist/target__control.mjs +2 -2
- package/dist/target__migration.d.mts +2 -2
- package/dist/target__migration.mjs +2 -2
- package/dist/target__op-factory-call.d.mts +2 -2
- package/dist/target__op-factory-call.mjs +2 -2
- package/dist/target__planner-produced-sqlite-migration.d.mts +2 -2
- package/dist/target__planner-produced-sqlite-migration.mjs +1 -1
- package/dist/target__planner.d.mts +1 -1
- package/dist/target__planner.mjs +1 -1
- package/dist/target__render-ops.mjs +1 -1
- package/dist/target__runtime.mjs +1 -1
- package/dist/target__runtime.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/adapter-Cy1Xx1rP-CJcOoS_O.mjs.map +0 -1
- package/dist/control-CtIPKwqL.mjs.map +0 -1
- package/dist/ddl-CXduXyOT-nlDP6DGx.mjs.map +0 -1
- package/dist/op-factory-call-B_WuATMN.d.mts.map +0 -1
- package/dist/op-factory-call-Bwp3QS4h-MwflmSX3.mjs.map +0 -1
- package/dist/planner-CFIbY54l.d.mts.map +0 -1
- package/dist/planner-DcRJaFjk-C9iIWF69.mjs.map +0 -1
- package/dist/planner-produced-sqlite-migration-DXcx0sOR-CcMQKE7n.d.mts.map +0 -1
- package/dist/planner-produced-sqlite-migration-sYbbeyyS.d.mts +0 -1
- package/dist/render-ops-KxAmAz6d-W2xyvA5y.mjs.map +0 -1
- package/dist/sqlite-contract-view-BYR10usg-BteDAUZr.mjs.map +0 -1
- package/dist/sqlite-migration-BSUZhMDG-DZU3d7bZ.d.mts.map +0 -1
- package/dist/sqlite-migration-DckJS_3w-BIKXWN5h.mjs.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { n as sqliteError } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
|
|
2
|
+
import { g as isSqliteOpFactoryCall } from "./op-factory-call-Cwsf4slr-DRGuq5SV.mjs";
|
|
2
3
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
4
|
import { isThenable } from "@prisma/orm-framework/utils/promise";
|
|
4
|
-
//#region ../../../3-targets/3-targets/sqlite/dist/render-ops-
|
|
5
|
+
//#region ../../../3-targets/3-targets/sqlite/dist/render-ops-BfFXRHIV.mjs
|
|
5
6
|
function assertSqliteOp(op, callFactoryName) {
|
|
6
7
|
const targetId = blindCast(op).target?.id;
|
|
7
8
|
if (targetId !== "sqlite") throw sqliteError("MIGRATION.TARGET_MISMATCH", `renderOps: expected sqlite op but got target.id="${String(targetId)}" for op.id="${op.id}" (factoryName="${callFactoryName}"). An OpFactoryCall produced an op for a different target on the sqlite planner path; check the call's target binding.`, { meta: {
|
|
@@ -10,18 +11,24 @@ function assertSqliteOp(op, callFactoryName) {
|
|
|
10
11
|
factoryName: callFactoryName
|
|
11
12
|
} });
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
assertSqliteOp(op, c.factoryName);
|
|
14
|
+
function checkedOp(opOrPromise, callFactoryName) {
|
|
15
|
+
if (isThenable(opOrPromise)) {
|
|
16
|
+
const checked = opOrPromise.then((op) => {
|
|
17
|
+
assertSqliteOp(op, callFactoryName);
|
|
18
18
|
return op;
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
return
|
|
20
|
+
checked.catch(() => void 0);
|
|
21
|
+
return checked;
|
|
22
|
+
}
|
|
23
|
+
assertSqliteOp(opOrPromise, callFactoryName);
|
|
24
|
+
return opOrPromise;
|
|
25
|
+
}
|
|
26
|
+
function renderOps(calls, lowerer) {
|
|
27
|
+
return calls.flatMap((c) => {
|
|
28
|
+
return (isSqliteOpFactoryCall(c) ? c.toOps(lowerer) : [blindCast(c).toOp(lowerer)]).map((opOrPromise) => checkedOp(opOrPromise, c.factoryName));
|
|
22
29
|
});
|
|
23
30
|
}
|
|
24
31
|
//#endregion
|
|
25
32
|
export { renderOps as t };
|
|
26
33
|
|
|
27
|
-
//# sourceMappingURL=render-ops-
|
|
34
|
+
//# sourceMappingURL=render-ops-BfFXRHIV-x1i1WAHz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-ops-BfFXRHIV-x1i1WAHz.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/render-ops-BfFXRHIV.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { p as isSqliteOpFactoryCall } from \"./op-factory-call-Cwsf4slr.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { isThenable } from \"@internal/utils/promise\";\n//#region src/core/migrations/render-ops.ts\nfunction assertSqliteOp(op, callFactoryName) {\n\tconst targetId = blindCast(op).target?.id;\n\tif (targetId !== \"sqlite\") throw sqliteError(\"MIGRATION.TARGET_MISMATCH\", `renderOps: expected sqlite op but got target.id=\"${String(targetId)}\" for op.id=\"${op.id}\" (factoryName=\"${callFactoryName}\"). An OpFactoryCall produced an op for a different target on the sqlite planner path; check the call's target binding.`, { meta: {\n\t\topId: op.id,\n\t\ttargetId: String(targetId),\n\t\tfactoryName: callFactoryName\n\t} });\n}\nfunction checkedOp(opOrPromise, callFactoryName) {\n\tif (isThenable(opOrPromise)) {\n\t\tconst checked = opOrPromise.then((op) => {\n\t\t\tassertSqliteOp(op, callFactoryName);\n\t\t\treturn op;\n\t\t});\n\t\tchecked.catch(() => void 0);\n\t\treturn checked;\n\t}\n\tassertSqliteOp(opOrPromise, callFactoryName);\n\treturn opOrPromise;\n}\nfunction renderOps(calls, lowerer) {\n\treturn calls.flatMap((c) => {\n\t\treturn (isSqliteOpFactoryCall(c) ? c.toOps(lowerer) : [blindCast(c).toOp(lowerer)]).map((opOrPromise) => checkedOp(opOrPromise, c.factoryName));\n\t});\n}\n//#endregion\nexport { renderOps as t };\n\n//# sourceMappingURL=render-ops-BfFXRHIV.mjs.map"],"mappings":";;;;;AAKA,SAAS,eAAe,IAAI,iBAAiB;CAC5C,MAAM,WAAW,UAAU,EAAE,CAAC,CAAC,QAAQ;CACvC,IAAI,aAAa,UAAU,MAAM,YAAY,6BAA6B,oDAAoD,OAAO,QAAQ,EAAE,eAAe,GAAG,GAAG,kBAAkB,gBAAgB,0HAA0H,EAAE,MAAM;EACvU,MAAM,GAAG;EACT,UAAU,OAAO,QAAQ;EACzB,aAAa;CACd,EAAE,CAAC;AACJ;AACA,SAAS,UAAU,aAAa,iBAAiB;CAChD,IAAI,WAAW,WAAW,GAAG;EAC5B,MAAM,UAAU,YAAY,MAAM,OAAO;GACxC,eAAe,IAAI,eAAe;GAClC,OAAO;EACR,CAAC;EACD,QAAQ,YAAY,KAAK,CAAC;EAC1B,OAAO;CACR;CACA,eAAe,aAAa,eAAe;CAC3C,OAAO;AACR;AACA,SAAS,UAAU,OAAO,SAAS;CAClC,OAAO,MAAM,SAAS,MAAM;EAC3B,QAAQ,sBAAsB,CAAC,IAAI,EAAE,MAAM,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,EAAA,CAAG,KAAK,gBAAgB,UAAU,aAAa,EAAE,WAAW,CAAC;CAC/I,CAAC;AACF"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { n as sqliteError } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
|
|
2
|
+
import { n as quoteIdentifier } from "./sql-utils-C2O4zVkP-Dz3Hb85I.mjs";
|
|
2
3
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
3
4
|
import { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma/orm-framework/components/ir";
|
|
4
5
|
import { SqlNamespaceBase } from "@prisma/orm-family-sql/contract/types";
|
|
5
6
|
import { buildSqlSingleNamespaceView } from "@prisma/orm-family-sql/contract/contract-view";
|
|
6
7
|
import { SqlContractSerializerBase } from "@prisma/orm-family-sql/family/ir";
|
|
7
8
|
import { tableEntityKind } from "@prisma/orm-family-sql/contract/entity-kinds";
|
|
8
|
-
//#region ../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-
|
|
9
|
+
//#region ../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-BrXalcTm.mjs
|
|
9
10
|
const SQLITE_NAMESPACE_KIND = "sqlite-namespace";
|
|
10
11
|
/**
|
|
11
12
|
* SQLite namespace concretion carrying table metadata under
|
|
@@ -35,7 +36,7 @@ var SqliteDatabase = class extends SqlNamespaceBase {
|
|
|
35
36
|
return "";
|
|
36
37
|
}
|
|
37
38
|
qualifyTable(tableName) {
|
|
38
|
-
return
|
|
39
|
+
return quoteIdentifier(tableName);
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
/**
|
|
@@ -148,4 +149,4 @@ const SqliteContractView = {
|
|
|
148
149
|
//#endregion
|
|
149
150
|
export { sqliteCreateNamespace as i, SqliteContractView as n, SqliteUnboundDatabase as r, SqliteContractSerializer as t };
|
|
150
151
|
|
|
151
|
-
//# sourceMappingURL=sqlite-contract-view-
|
|
152
|
+
//# sourceMappingURL=sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs","names":[],"sources":["../../../../3-targets/3-targets/sqlite/dist/sqlite-contract-view-BrXalcTm.mjs"],"sourcesContent":["import { n as sqliteError } from \"./errors-DnR-sMHS.mjs\";\nimport { n as quoteIdentifier } from \"./sql-utils-C2O4zVkP.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\nimport { SqlNamespaceBase } from \"@internal/sql-contract/types\";\nimport { UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from \"@internal/framework-components/ir\";\nimport { buildSqlSingleNamespaceView } from \"@internal/sql-contract/contract-view\";\nimport { SqlContractSerializerBase } from \"@internal/family-sql/ir\";\nimport { tableEntityKind } from \"@internal/sql-contract/entity-kinds\";\n//#region src/core/sqlite-unbound-database.ts\nconst SQLITE_NAMESPACE_KIND = \"sqlite-namespace\";\n/**\n* SQLite namespace concretion carrying table metadata under\n* `entries.table` and unqualified `qualifyTable()` emission for runtime\n* SQL rendering.\n*/\nvar SqliteDatabase = class extends SqlNamespaceBase {\n\tid;\n\tentries;\n\tconstructor(input) {\n\t\tsuper();\n\t\tthis.id = input.id;\n\t\tconst dispatched = hydrateNamespaceEntities(input.entries, /* @__PURE__ */ new Map([[\"table\", tableEntityKind]]), \"carry\");\n\t\tthis.entries = Object.freeze(blindCast(dispatched));\n\t\tObject.defineProperty(this, \"kind\", {\n\t\t\tvalue: SQLITE_NAMESPACE_KIND,\n\t\t\twritable: false,\n\t\t\tenumerable: false,\n\t\t\tconfigurable: true\n\t\t});\n\t\tfreezeNode(this);\n\t}\n\tget table() {\n\t\treturn this.entries.table ?? Object.freeze({});\n\t}\n\tqualifier() {\n\t\treturn \"\";\n\t}\n\tqualifyTable(tableName) {\n\t\treturn quoteIdentifier(tableName);\n\t}\n};\n/**\n* SQLite target `Namespace` concretion. SQLite has no schema or\n* database-namespacing concept at the SQL level — there is exactly one\n* effective namespace per connection, so the target ships a single\n* singleton bound to the framework's `UNBOUND_NAMESPACE_ID` slot.\n*\n* Qualifier emission elides the prefix entirely: rendered DDL and\n* queries look unqualified (`CREATE TABLE \"users\" (...)`), matching\n* SQLite's native dialect. Call sites stay polymorphic — they ask the\n* namespace for its qualifier and consume the empty/unqualified result\n* the same way Postgres consumes a `\"schema\"` prefix.\n*\n* The SQLite PSL interpreter rejects every explicit `namespace { … }`\n* block with a diagnostic naming SQLite; only the implicit\n* `__unspecified__` AST bucket reaches the SQLite interpreter, which\n* lowers it to this singleton.\n*/\nvar SqliteUnboundDatabase = class SqliteUnboundDatabase extends SqliteDatabase {\n\tstatic instance = new SqliteUnboundDatabase();\n\tconstructor() {\n\t\tsuper({\n\t\t\tid: UNBOUND_NAMESPACE_ID,\n\t\t\tentries: { table: {} }\n\t\t});\n\t}\n};\n/**\n* The SQLite target's rejection of expression and partial indexes: the\n* family-shared authoring surfaces parse `expression:`/`where:` for every\n* SQL target, but SQLite neither renders nor introspects them (project\n* non-goal) — a contract carrying one must fail loudly at lowering instead\n* of silently producing an unverifiable index. Target-owned so no family\n* code branches on the target.\n*/\nfunction rejectSqlBodyIndexes(input) {\n\tconst tables = input.entries[\"table\"];\n\tif (tables === void 0) return;\n\tfor (const [tableName, table] of Object.entries(tables)) {\n\t\tconst indexes = blindCast(table).indexes;\n\t\tfor (const index of indexes ?? []) if (index.expression !== void 0 || index.where !== void 0) throw sqliteError(\"CONTRACT.ARGUMENT_INVALID\", `SQLite does not support expression or partial indexes: index \"${index.name ?? \"<unnamed>\"}\" on table \"${tableName}\" declares ${index.expression !== void 0 ? \"an expression\" : \"a where predicate\"}. Use a fields-only index, or author this index against a Postgres target.`);\n\t}\n}\nfunction buildSqliteNamespace(input) {\n\trejectSqlBodyIndexes(input);\n\tif (input.id !== UNBOUND_NAMESPACE_ID) throw sqliteError(\"CONTRACT.NAMESPACE_INVALID\", `buildSqliteNamespace: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${input.id}\").`, { meta: { received: input.id } });\n\tconst tableKind = input.entries[\"table\"];\n\tconst tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;\n\tconst hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== \"table\");\n\tif (tableCount === 0 && !hasUnknownKinds) return SqliteUnboundDatabase.instance;\n\treturn new SqliteDatabase({\n\t\tid: input.id,\n\t\tentries: input.entries\n\t});\n}\n/**\n* Target-supplied `Namespace` factory the SQLite target plumbs through\n* `defineContract({ createNamespace })`. SQLite has only one\n* effective namespace slot — the framework `UNBOUND_NAMESPACE_ID`\n* sentinel — so the factory always returns the singleton or a fresh\n* `SqliteDatabase` for the unbound slot with tables. The SQL family's\n* defensive validation in `defineContract` already rejects\n* user-declared SQLite namespaces, so this throw is a structural\n* safety net rather than a user-facing surface.\n*/\nfunction sqliteCreateNamespace(input) {\n\treturn buildSqliteNamespace(input);\n}\n//#endregion\n//#region src/core/sqlite-contract-serializer.ts\n/**\n* SQLite target `ContractSerializer` concretion. Mirrors the Postgres\n* shape: inherits the full SQL-family deserialization pipeline and\n* materialises namespace entries as SQLite database concretions that\n* expose `qualifyTable()` for runtime SQL rendering.\n*/\nvar SqliteContractSerializer = class extends SqlContractSerializerBase {\n\tconstructor() {\n\t\tsuper(/* @__PURE__ */ new Map());\n\t}\n\thydrateSqlNamespaceEntry(nsId, raw) {\n\t\treturn buildSqliteNamespace(blindCast(super.hydrateSqlNamespaceEntry(nsId, raw)));\n\t}\n\tserializeContract(contract) {\n\t\tconst { storage, ...rest } = contract;\n\t\tconst namespacesJson = {};\n\t\tfor (const [nsId, ns] of Object.entries(storage.namespaces)) namespacesJson[nsId] = {\n\t\t\tid: ns.id,\n\t\t\tentries: this.serializeNamespaceEntries(ns.entries)\n\t\t};\n\t\treturn blindCast({\n\t\t\t...rest,\n\t\t\tstorage: {\n\t\t\t\tstorageHash: String(storage.storageHash),\n\t\t\t\tnamespaces: namespacesJson,\n\t\t\t\t...storage.types !== void 0 ? { types: this.serializeJsonObject(storage.types) } : {}\n\t\t\t}\n\t\t});\n\t}\n};\n//#endregion\n//#region src/core/sqlite-contract-view.ts\nconst SqliteContractView = {\n\t/** Wrap an already-deserialized SQLite contract in a view. */\n\tfrom(contract) {\n\t\treturn buildSqlSingleNamespaceView(contract);\n\t},\n\t/** Deserialize a SQLite contract JSON envelope and wrap it in a view. */\n\tfromJson(json) {\n\t\treturn buildSqlSingleNamespaceView(new SqliteContractSerializer().deserializeContract(json));\n\t}\n};\n//#endregion\nexport { sqliteCreateNamespace as i, SqliteContractSerializer as n, SqliteUnboundDatabase as r, SqliteContractView as t };\n\n//# sourceMappingURL=sqlite-contract-view-BrXalcTm.mjs.map"],"mappings":"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"}
|
package/dist/{sqlite-migration-DckJS_3w-BIKXWN5h.mjs → sqlite-migration-Bz7SwolX-CHLtwGNa.mjs}
RENAMED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { n as sqliteError, t as errorSqliteMigrationStackMissing } from "./errors-DnR-sMHS-KkMLIP2U.mjs";
|
|
2
2
|
import { n as SQLITE_NOW_EXPRESSION } from "./datetime-text-Bniwehv--Ddt3VS4z.mjs";
|
|
3
3
|
import { n as sqliteResolveDefault } from "./default-normalizer-Ch3VFnEH-C-h1XtlJ.mjs";
|
|
4
|
-
import { _ as
|
|
4
|
+
import { _ as renameTableSteps, a as DropColumnCall, b as sqliteIdentifiersCollide, d as RenameTableCall, f as buildColumnTypeSql, h as indexReplacementCalls, i as DataTransformCall, l as RecreateTableCall, m as buildRecreateSummary, n as CreateIndexCall, o as DropIndexCall, p as buildRecreatePostchecks, r as CreateTableCall, s as DropTableCall, t as AddColumnCall, u as RenameColumnCall, v as renderDefaultLiteral, y as sqliteDefaultToDdlColumnDefault } from "./op-factory-call-Cwsf4slr-DRGuq5SV.mjs";
|
|
5
5
|
import { t as CONTROL_TABLE_NAMES } from "./control-tables-D_o8dKRB-BXi43noL.mjs";
|
|
6
|
-
import { n as SqliteContractView } from "./sqlite-contract-view-
|
|
6
|
+
import { n as SqliteContractView } from "./sqlite-contract-view-BrXalcTm-DYDH4LQC.mjs";
|
|
7
7
|
import { DdlColumn, ForeignKeyConstraint, PrimaryKeyConstraint, UniqueConstraint } from "@prisma/orm-family-sql/relational-core/ast";
|
|
8
8
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
9
9
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
10
10
|
import { diffSchemas, issueOutcome, orderIssuesByDependencies } from "@prisma/orm-framework/components/control";
|
|
11
|
-
import { entityAt } from "@prisma/orm-framework/components/ir";
|
|
12
|
-
import { RelationalSchemaNodeKind, SqlIndexIR, SqlSchemaIR, contractDefaultRefusal, relationalNodeGranularity } from "@prisma/orm-family-sql/schema-ir/types";
|
|
11
|
+
import { UNBOUND_NAMESPACE_ID, entityAt } from "@prisma/orm-framework/components/ir";
|
|
12
|
+
import { PrimaryKey, RelationalSchemaNodeKind, SqlCheckConstraintIR, SqlColumnIR, SqlForeignKeyIR, SqlIndexIR, SqlSchemaIR, SqlTableIR, SqlUniqueIR, contractDefaultRefusal, relationalNodeGranularity } from "@prisma/orm-family-sql/schema-ir/types";
|
|
13
13
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
14
|
-
import {
|
|
14
|
+
import { contractToSchemaIR, resolveColumnRenameAgainst, resolveTableRenameAgainst, sqlTypeLookupsOf, unmatchedColumnRename, unmatchedTableRename } from "@prisma/orm-family-sql/family/control";
|
|
15
15
|
import { verifySqlSchemaByDiff } from "@prisma/orm-family-sql/family/diff";
|
|
16
|
-
import { parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
17
16
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
17
|
+
import { namingOf, namingOfLiveName, parseWireName } from "@prisma/orm-family-sql/schema-ir/naming";
|
|
18
|
+
import { isArrayEqual } from "@prisma/orm-framework/utils/array-equal";
|
|
18
19
|
import { Migration } from "@prisma/orm-family-sql/family/migration";
|
|
19
20
|
import { MigrationContractViews } from "@prisma/orm-toolchain/migration-tools/migration";
|
|
20
|
-
//#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-
|
|
21
|
+
//#region ../../../3-targets/3-targets/sqlite/dist/sqlite-migration-Bz7SwolX.mjs
|
|
21
22
|
/** Renders a column default for the SQLite dialect. */
|
|
22
23
|
function sqliteRenderDefault(def, column) {
|
|
23
24
|
if (def.kind === "function") {
|
|
@@ -107,13 +108,17 @@ function diffSqliteSchema(input) {
|
|
|
107
108
|
function buildSqlitePlanDiff(input) {
|
|
108
109
|
const types = sqlTypeLookupsOf(input.frameworkComponents);
|
|
109
110
|
const expected = sqliteContractToSchema(input.contract, types);
|
|
110
|
-
const actual =
|
|
111
|
+
const actual = sqliteActualSchema(input.actualSchema);
|
|
111
112
|
return {
|
|
112
113
|
expected,
|
|
113
114
|
actual,
|
|
114
115
|
issues: diffSchemas(expected, actual)
|
|
115
116
|
};
|
|
116
117
|
}
|
|
118
|
+
/** The schema a plan starts from as a `SqlSchemaIR`, its table and column names taken from their keys. */
|
|
119
|
+
function sqliteActualSchema(actualSchema) {
|
|
120
|
+
return new SqlSchemaIR(withRecordKeyNames(actualSchema));
|
|
121
|
+
}
|
|
117
122
|
/**
|
|
118
123
|
* Every schema-tree builder in this codebase derives a table's / column's
|
|
119
124
|
* `name` from the record key it's stored under (`contractToSchemaIR`,
|
|
@@ -270,33 +275,33 @@ function tableConstraintsFromNode(table, hasInlinePk) {
|
|
|
270
275
|
* all (table/column not-found-or-not-expected, and index issues — those are
|
|
271
276
|
* standalone ops, never folded into a recreate).
|
|
272
277
|
*
|
|
273
|
-
* Column drift is a single `not-equal` issue
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* is destructive when tightening (NOT NULL required) and widening when
|
|
278
|
-
* relaxing.
|
|
278
|
+
* Column drift is a single `not-equal` issue (type and nullability compared
|
|
279
|
+
* together by `SqlColumnIR.isEqualTo`): a type change is destructive, because
|
|
280
|
+
* the copy can change values; a nullability change alone is widening, because
|
|
281
|
+
* a tightening copy fails on a NULL rather than losing it.
|
|
279
282
|
*/
|
|
283
|
+
/** The column of a column issue, which `classifyNodeIssue` classes destructive only for a type change. */
|
|
284
|
+
function columnNameOf(issue) {
|
|
285
|
+
return blindCast(issue.expected).name;
|
|
286
|
+
}
|
|
280
287
|
function classifyNodeIssue(issue) {
|
|
281
288
|
const node = issue.expected ?? issue.actual;
|
|
282
289
|
if (node === void 0) return null;
|
|
283
290
|
switch (blindCast(node).nodeKind) {
|
|
284
|
-
case RelationalSchemaNodeKind.column:
|
|
291
|
+
case RelationalSchemaNodeKind.column:
|
|
285
292
|
if (issueOutcome(issue) !== "not-equal") return null;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return expected.nullable ? "widening" : "destructive";
|
|
289
|
-
}
|
|
290
|
-
case RelationalSchemaNodeKind.columnDefault: return issueOutcome(issue) === "not-expected" ? "destructive" : "widening";
|
|
293
|
+
return columnTypeChanged(blindCast(issue.expected), blindCast(issue.actual)) ? "destructive" : "widening";
|
|
294
|
+
case RelationalSchemaNodeKind.columnDefault:
|
|
291
295
|
case RelationalSchemaNodeKind.primaryKey:
|
|
292
296
|
case RelationalSchemaNodeKind.foreignKey:
|
|
293
|
-
case RelationalSchemaNodeKind.unique: return "
|
|
297
|
+
case RelationalSchemaNodeKind.unique: return "widening";
|
|
294
298
|
default: return null;
|
|
295
299
|
}
|
|
296
300
|
}
|
|
297
301
|
/**
|
|
298
302
|
* Groups recreate-eligible issues by table, decides per-table operation class
|
|
299
|
-
* (destructive wins over widening
|
|
303
|
+
* (destructive wins over widening, and a recreate that leaves a live column
|
|
304
|
+
* out of the new table loses its values, so it is destructive), and emits one `RecreateTableCall` per
|
|
300
305
|
* table. Returns unchanged-or-smaller issue list — issues the strategy
|
|
301
306
|
* consumed are removed so `mapNodeIssueToCall` doesn't double-handle them.
|
|
302
307
|
*
|
|
@@ -313,14 +318,17 @@ const recreateTableStrategy = (issues, ctx) => {
|
|
|
313
318
|
if (!cls) continue;
|
|
314
319
|
const tableName = issue.path[1];
|
|
315
320
|
if (tableName === void 0) continue;
|
|
316
|
-
const entry = byTable.get(tableName)
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
const entry = byTable.get(tableName) ?? {
|
|
322
|
+
issues: [],
|
|
323
|
+
hasDestructive: false,
|
|
324
|
+
lossyColumns: []
|
|
325
|
+
};
|
|
326
|
+
entry.issues.push(issue);
|
|
327
|
+
if (cls === "destructive") {
|
|
328
|
+
entry.hasDestructive = true;
|
|
329
|
+
entry.lossyColumns.push(columnNameOf(issue));
|
|
330
|
+
}
|
|
331
|
+
byTable.set(tableName, entry);
|
|
324
332
|
consumed.add(issue);
|
|
325
333
|
}
|
|
326
334
|
if (byTable.size === 0) return { kind: "no_match" };
|
|
@@ -329,7 +337,8 @@ const recreateTableStrategy = (issues, ctx) => {
|
|
|
329
337
|
const expectedTable = ctx.expected.tables[tableName];
|
|
330
338
|
const actualTable = ctx.actual.tables[tableName];
|
|
331
339
|
if (!expectedTable || !actualTable) continue;
|
|
332
|
-
const
|
|
340
|
+
const leavesColumnsOut = Object.keys(actualTable.columns).some((column) => !Object.hasOwn(expectedTable.columns, column));
|
|
341
|
+
const operationClass = entry.hasDestructive || leavesColumnsOut ? "destructive" : "widening";
|
|
333
342
|
const tableSpec = tableSpecFromNode(expectedTable, ctx.types);
|
|
334
343
|
const indexes = expectedTable.indexes.map((idx) => ({
|
|
335
344
|
name: idx.name,
|
|
@@ -343,7 +352,7 @@ const recreateTableStrategy = (issues, ctx) => {
|
|
|
343
352
|
summary: buildRecreateSummary(tableName, entry.issues),
|
|
344
353
|
postchecks: buildRecreatePostchecks(tableName, entry.issues, tableSpec),
|
|
345
354
|
operationClass
|
|
346
|
-
}));
|
|
355
|
+
}, entry.lossyColumns));
|
|
347
356
|
}
|
|
348
357
|
return {
|
|
349
358
|
kind: "match",
|
|
@@ -366,11 +375,10 @@ const recreateTableStrategy = (issues, ctx) => {
|
|
|
366
375
|
* recipe slot in strategy order (backfill first, recreate second), which
|
|
367
376
|
* matches the required execution order.
|
|
368
377
|
*
|
|
369
|
-
* Mirrors Postgres's `nullableTighteningCallStrategy
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* behavior where a tightening blows up at runtime if NULLs are present.
|
|
378
|
+
* Mirrors Postgres's `nullableTighteningCallStrategy`. When `'data'` is not
|
|
379
|
+
* in the policy (the default `db update` / `db init` path), the strategy
|
|
380
|
+
* short-circuits and the recreate alone runs, failing at runtime if NULLs
|
|
381
|
+
* are present.
|
|
374
382
|
*/
|
|
375
383
|
const nullabilityTighteningBackfillStrategy = (issues, ctx) => {
|
|
376
384
|
if (!ctx.policy.allowedOperationClasses.includes("data")) return { kind: "no_match" };
|
|
@@ -690,6 +698,13 @@ function renamedTableIndex(renamedTables) {
|
|
|
690
698
|
};
|
|
691
699
|
}
|
|
692
700
|
/**
|
|
701
|
+
* An index on the renamed column whose wire name derives from the column name: after the rename
|
|
702
|
+
* the old and the new index cover the same columns on the same table and differ in name.
|
|
703
|
+
*/
|
|
704
|
+
function renamedColumnIndex(table, column) {
|
|
705
|
+
return (old, replacement) => old.tableName === table && replacement.tableName === table && old.index.name !== replacement.index.name && old.index.expression === void 0 && old.index.where === void 0 && (old.index.columns ?? []).includes(column) && old.index.unique === replacement.index.unique && isArrayEqual(old.index.columns ?? [], replacement.index.columns ?? []);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
693
708
|
* An index on the same table whose new name SQLite takes for the old one, as after a table renamed by hand. Its content is not compared: the old index must be dropped before the new one can be created whatever either defines, and the new one is created from its own definition.
|
|
694
709
|
*/
|
|
695
710
|
const indexNameCaseChange = (old, replacement) => old.tableName === replacement.tableName && old.index.name !== replacement.index.name && sqliteIdentifiersCollide(old.index.name, replacement.index.name);
|
|
@@ -707,29 +722,251 @@ function pairIndexReplacements(issues, matches) {
|
|
|
707
722
|
replacement
|
|
708
723
|
}];
|
|
709
724
|
});
|
|
725
|
+
const replacements = pairs.map(({ old, replacement }) => ({
|
|
726
|
+
drop: new DropIndexCall(old.tableName, old.index.name),
|
|
727
|
+
create: new CreateIndexCall(replacement.tableName, replacement.index.name, replacement.index.columns ?? [])
|
|
728
|
+
}));
|
|
710
729
|
return {
|
|
711
|
-
|
|
730
|
+
replacements,
|
|
731
|
+
calls: indexReplacementCalls(replacements),
|
|
712
732
|
consumed: new Set(pairs.flatMap(({ old, replacement }) => [old.issue, replacement.issue]))
|
|
713
733
|
};
|
|
714
734
|
}
|
|
715
735
|
/**
|
|
716
|
-
* The
|
|
736
|
+
* The tables of a SQLite schema. SQLite has one namespace, so the namespace id is ignored, and it
|
|
737
|
+
* compares table and column names without regard to the case of ASCII letters.
|
|
738
|
+
*/
|
|
739
|
+
function sqliteSchemaTables(schema) {
|
|
740
|
+
const hasTable = (_namespaceId, table) => Object.hasOwn(schema.tables, table);
|
|
741
|
+
return {
|
|
742
|
+
hasTable,
|
|
743
|
+
hasColumn: (_namespaceId, table, column) => Object.hasOwn(schema.tables[table]?.columns ?? {}, column),
|
|
744
|
+
tablesNamed: (_namespaceId, table) => Object.keys(schema.tables).filter((existing) => sqliteIdentifiersCollide(existing, table)),
|
|
745
|
+
columnsNamed: (_namespaceId, table, column) => Object.keys(schema.tables[table]?.columns ?? {}).filter((existing) => sqliteIdentifiersCollide(existing, column)),
|
|
746
|
+
namespacesWithTable: (table) => hasTable(UNBOUND_NAMESPACE_ID, table) ? [UNBOUND_NAMESPACE_ID] : []
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function rewriteRefs(refs, rewrite) {
|
|
750
|
+
return refs?.map(rewrite);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Rewrites the step of `kind` and `id` in a ref that runs through the given table, and the table
|
|
754
|
+
* step itself when `kind` is the table kind.
|
|
717
755
|
*/
|
|
718
|
-
function
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
756
|
+
function stepRewrite(tableName, kind, fromId, toId) {
|
|
757
|
+
return (ref) => {
|
|
758
|
+
const tableStep = ref[1];
|
|
759
|
+
if (tableStep?.nodeKind !== RelationalSchemaNodeKind.table || tableStep.id !== tableName) return ref;
|
|
760
|
+
return ref.map((step, index) => index >= 1 && step.nodeKind === kind && step.id === fromId ? {
|
|
761
|
+
nodeKind: kind,
|
|
762
|
+
id: toId
|
|
763
|
+
} : step);
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function withColumnName(column, name) {
|
|
767
|
+
return new SqlColumnIR({
|
|
768
|
+
name,
|
|
769
|
+
nativeType: column.nativeType,
|
|
770
|
+
nullable: column.nullable,
|
|
771
|
+
...ifDefined("default", column.default),
|
|
772
|
+
...ifDefined("annotations", column.annotations),
|
|
773
|
+
...ifDefined("many", column.many),
|
|
774
|
+
...ifDefined("resolvedNativeType", column.resolvedNativeType),
|
|
775
|
+
...ifDefined("resolvedDefault", column.resolvedDefault),
|
|
776
|
+
...ifDefined("authoredDefault", column.authoredDefault),
|
|
777
|
+
...ifDefined("codecRef", column.codecRef),
|
|
778
|
+
...ifDefined("codecBaseNativeType", column.codecBaseNativeType),
|
|
779
|
+
...ifDefined("dataType", column.dataType),
|
|
780
|
+
...ifDefined("toCanonicalForm", column.toCanonicalForm)
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* An index whose definition carries SQL text, an expression or a predicate, keeps its columns as
|
|
785
|
+
* they are: a column named inside the text cannot be renamed here, so the diff plans the index.
|
|
786
|
+
*/
|
|
787
|
+
function withIndex(index, name, rewrite, columnName) {
|
|
788
|
+
const columnsFollow = index.expression === void 0 && index.where === void 0;
|
|
789
|
+
const base = {
|
|
790
|
+
naming: name === index.name ? namingOf(index.name, index.prefix) : namingOfLiveName(name),
|
|
791
|
+
where: index.where,
|
|
792
|
+
unique: index.unique,
|
|
793
|
+
partial: index.partial,
|
|
794
|
+
type: index.type,
|
|
795
|
+
options: index.options,
|
|
796
|
+
annotations: index.annotations,
|
|
797
|
+
dependsOn: rewriteRefs(index.dependsOn, rewrite)
|
|
798
|
+
};
|
|
799
|
+
return new SqlIndexIR(index.expression !== void 0 ? {
|
|
800
|
+
...base,
|
|
801
|
+
expression: index.expression
|
|
802
|
+
} : {
|
|
803
|
+
...base,
|
|
804
|
+
columns: (index.columns ?? []).map(columnsFollow ? columnName : (c) => c)
|
|
724
805
|
});
|
|
725
|
-
|
|
726
|
-
|
|
806
|
+
}
|
|
807
|
+
function rebuildTable(table, edit, rewrite) {
|
|
808
|
+
const { primaryKey } = table;
|
|
809
|
+
const { columnName } = edit;
|
|
810
|
+
return new SqlTableIR({
|
|
811
|
+
name: edit.name,
|
|
812
|
+
columns: Object.fromEntries(Object.values(table.columns).map((column) => {
|
|
813
|
+
const name = columnName(column.name);
|
|
814
|
+
return [name, name === column.name ? column : withColumnName(column, name)];
|
|
815
|
+
})),
|
|
816
|
+
...ifDefined("primaryKey", primaryKey === void 0 ? void 0 : new PrimaryKey({
|
|
817
|
+
columns: primaryKey.columns.map(columnName),
|
|
818
|
+
...ifDefined("name", primaryKey.name),
|
|
819
|
+
...ifDefined("dependsOn", rewriteRefs(primaryKey.dependsOn, rewrite))
|
|
820
|
+
})),
|
|
821
|
+
uniques: table.uniques.map((unique) => new SqlUniqueIR({
|
|
822
|
+
columns: unique.columns.map(columnName),
|
|
823
|
+
...ifDefined("name", unique.name),
|
|
824
|
+
...ifDefined("annotations", unique.annotations),
|
|
825
|
+
...ifDefined("dependsOn", rewriteRefs(unique.dependsOn, rewrite))
|
|
826
|
+
})),
|
|
827
|
+
foreignKeys: table.foreignKeys.map((fk) => new SqlForeignKeyIR({
|
|
828
|
+
columns: fk.columns.map(columnName),
|
|
829
|
+
referencedTable: edit.referencedTable(fk),
|
|
830
|
+
referencedColumns: edit.referencedColumns(fk),
|
|
831
|
+
...ifDefined("referencedSchema", fk.referencedSchema),
|
|
832
|
+
...ifDefined("name", fk.name),
|
|
833
|
+
...ifDefined("onDelete", fk.onDelete),
|
|
834
|
+
...ifDefined("onUpdate", fk.onUpdate),
|
|
835
|
+
...ifDefined("annotations", fk.annotations),
|
|
836
|
+
...ifDefined("resolvedReferencedNamespace", fk.resolvedReferencedNamespace),
|
|
837
|
+
...ifDefined("dependsOn", rewriteRefs(fk.dependsOn, rewrite))
|
|
838
|
+
})),
|
|
839
|
+
indexes: table.indexes.map((index) => withIndex(index, edit.indexName(index), rewrite, columnName)),
|
|
840
|
+
...ifDefined("checks", table.checks?.map((check) => new SqlCheckConstraintIR({
|
|
841
|
+
naming: namingOf(check.name, check.prefix),
|
|
842
|
+
expression: check.expression,
|
|
843
|
+
dependsOn: rewriteRefs(check.dependsOn, rewrite)
|
|
844
|
+
}))),
|
|
845
|
+
...ifDefined("annotations", table.annotations)
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
/** Rebuilds every table: `editFor` returns the edit for a table, or `undefined` to keep it. */
|
|
849
|
+
function mapTables(schema, rewrite, editFor) {
|
|
850
|
+
return new SqlSchemaIR({
|
|
851
|
+
tables: Object.fromEntries(Object.values(schema.tables).map((table) => {
|
|
852
|
+
const rebuilt = rebuildTable(table, {
|
|
853
|
+
name: table.name,
|
|
854
|
+
columnName: (column) => column,
|
|
855
|
+
referencedTable: (fk) => fk.referencedTable,
|
|
856
|
+
referencedColumns: (fk) => fk.referencedColumns,
|
|
857
|
+
indexName: (index) => index.name,
|
|
858
|
+
...editFor(table)
|
|
859
|
+
}, rewrite);
|
|
860
|
+
return [rebuilt.name, rebuilt];
|
|
861
|
+
})),
|
|
862
|
+
...ifDefined("annotations", schema.annotations)
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* The schema with one table under its new name. Foreign keys anywhere that reference the table
|
|
867
|
+
* follow it, and every dependency that names it moves with it. Object names do not change. An
|
|
868
|
+
* unnamed primary key, unique constraint or foreign key stays unnamed: SQLite gives such a
|
|
869
|
+
* constraint no name, so an introspected schema has none either, and the planner never renames
|
|
870
|
+
* one.
|
|
871
|
+
*/
|
|
872
|
+
function renameTableInSqliteSchema(schema, rename) {
|
|
873
|
+
const { from, to } = rename;
|
|
874
|
+
return mapTables(schema, stepRewrite(from, RelationalSchemaNodeKind.table, from, to), (table) => ({
|
|
875
|
+
...table.name === from ? { name: to } : {},
|
|
876
|
+
referencedTable: (fk) => fk.referencedTable === from ? to : fk.referencedTable
|
|
877
|
+
}));
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* The schema with one column under its new name. The table's primary key, unique constraints,
|
|
881
|
+
* foreign keys and plain column indexes name it under the new name, foreign keys anywhere that
|
|
882
|
+
* reference it follow it, and every dependency that names it moves with it. An index with an
|
|
883
|
+
* expression or a predicate keeps its SQL text, and index names do not change, as in SQLite.
|
|
884
|
+
*/
|
|
885
|
+
function renameColumnInSqliteSchema(schema, rename) {
|
|
886
|
+
const { table: tableName, from, to } = rename;
|
|
887
|
+
const rewrite = stepRewrite(tableName, RelationalSchemaNodeKind.column, `column:${from}`, `column:${to}`);
|
|
888
|
+
const renamed = (column) => column === from ? to : column;
|
|
889
|
+
return mapTables(schema, rewrite, (table) => ({
|
|
890
|
+
...table.name === tableName ? { columnName: renamed } : {},
|
|
891
|
+
referencedColumns: (fk) => fk.referencedTable === tableName ? fk.referencedColumns.map(renamed) : fk.referencedColumns
|
|
892
|
+
}));
|
|
893
|
+
}
|
|
894
|
+
function replaceIndex(schema, replacement) {
|
|
895
|
+
const { tableName, indexName: oldIndexName } = replacement.drop;
|
|
896
|
+
const newIndexName = replacement.create.indexName;
|
|
897
|
+
return mapTables(schema, stepRewrite(tableName, RelationalSchemaNodeKind.index, `index:${oldIndexName}`, `index:${newIndexName}`), (table) => table.name === tableName ? { indexName: (index) => index.name === oldIndexName ? newIndexName : index.name } : void 0);
|
|
898
|
+
}
|
|
899
|
+
/** The working schema of a plan or a migration, starting from `initial`. */
|
|
900
|
+
function createWorkingSchema(initial) {
|
|
901
|
+
return new WorkingSchemaImpl(initial);
|
|
902
|
+
}
|
|
903
|
+
var WorkingSchemaImpl = class {
|
|
904
|
+
#current;
|
|
905
|
+
constructor(initial) {
|
|
906
|
+
this.#current = initial;
|
|
907
|
+
}
|
|
908
|
+
get current() {
|
|
909
|
+
return this.#current;
|
|
910
|
+
}
|
|
911
|
+
apply(call) {
|
|
912
|
+
const renamed = call instanceof RenameColumnCall ? renameColumnInSqliteSchema(this.#current, {
|
|
913
|
+
table: call.tableName,
|
|
914
|
+
from: call.oldColumnName,
|
|
915
|
+
to: call.columnName
|
|
916
|
+
}) : renameTableInSqliteSchema(this.#current, {
|
|
917
|
+
from: call.oldTableName,
|
|
918
|
+
to: call.tableName
|
|
919
|
+
});
|
|
920
|
+
this.#current = call.indexReplacements.reduce(replaceIndex, renamed);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
/** The SQL a user runs against the database to rename the table by hand. */
|
|
924
|
+
function renameTableByHandStatements(rename) {
|
|
925
|
+
return renameTableSteps(rename.from, rename.to).map((renameStep) => renameStep.sql);
|
|
926
|
+
}
|
|
927
|
+
/** The `renameTable` call a user writes in `migration.ts` for `rename`; SQLite has no namespaces. */
|
|
928
|
+
function renderRenameTableCall(rename) {
|
|
929
|
+
return new RenameTableCall(rename.from, rename.to, []).renderTypeScript();
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* The call that renames a table, carrying as companions a drop and a create under the new name of
|
|
933
|
+
* each index whose wire name derives from the old table name, since SQLite cannot rename an index.
|
|
934
|
+
* `previous` is the schema with the table under its old name; the renamed copy is diffed against
|
|
935
|
+
* `contract`. SQLite names no primary key, unique constraint or foreign key the contract leaves
|
|
936
|
+
* unnamed, so those need nothing.
|
|
937
|
+
*/
|
|
938
|
+
function sqliteTableRenameCall(input) {
|
|
939
|
+
const { from, to } = input.rename;
|
|
940
|
+
const { issues } = buildSqlitePlanDiff({
|
|
941
|
+
contract: input.contract,
|
|
942
|
+
actualSchema: renameTableInSqliteSchema(input.previous, {
|
|
943
|
+
from,
|
|
944
|
+
to
|
|
945
|
+
}),
|
|
946
|
+
frameworkComponents: input.frameworkComponents
|
|
947
|
+
});
|
|
948
|
+
const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedTableIndex(/* @__PURE__ */ new Set([to])));
|
|
949
|
+
return new RenameTableCall(from, to, replacements);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* The call that renames a column, carrying as companions a drop and a create under the new name of
|
|
953
|
+
* each index on the column whose wire name derives from the column name, since SQLite cannot rename
|
|
954
|
+
* an index and keeps the old name when it renames the column. `previous` is the schema with the
|
|
955
|
+
* column under its old name; the renamed copy is diffed against `contract`.
|
|
956
|
+
*/
|
|
957
|
+
function sqliteColumnRenameCall(input) {
|
|
958
|
+
const { table, from, to } = input.rename;
|
|
727
959
|
const { issues } = buildSqlitePlanDiff({
|
|
728
|
-
contract: input.
|
|
729
|
-
actualSchema:
|
|
960
|
+
contract: input.contract,
|
|
961
|
+
actualSchema: renameColumnInSqliteSchema(input.previous, {
|
|
962
|
+
table,
|
|
963
|
+
from,
|
|
964
|
+
to
|
|
965
|
+
}),
|
|
730
966
|
frameworkComponents: input.frameworkComponents
|
|
731
967
|
});
|
|
732
|
-
|
|
968
|
+
const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedColumnIndex(table, to));
|
|
969
|
+
return new RenameColumnCall(table, from, to, replacements);
|
|
733
970
|
}
|
|
734
971
|
/**
|
|
735
972
|
* Target-owned base class for SQLite migrations. Fixes the `SqlMigration`
|
|
@@ -763,6 +1000,8 @@ var SqliteMigration = class extends Migration {
|
|
|
763
1000
|
*/
|
|
764
1001
|
controlAdapter;
|
|
765
1002
|
#endView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
|
|
1003
|
+
/** The rename calls this read of `operations` has made so far, in order. */
|
|
1004
|
+
#renames = [];
|
|
766
1005
|
#startView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
|
|
767
1006
|
constructor(stack) {
|
|
768
1007
|
super(stack);
|
|
@@ -808,20 +1047,76 @@ var SqliteMigration = class extends Migration {
|
|
|
808
1047
|
return new DropTableCall(options.table).toOp(this.controlAdapterFor("dropTable"));
|
|
809
1048
|
}
|
|
810
1049
|
/**
|
|
811
|
-
* Emit the operations that rename a table: the table rename, then a drop and a create under the
|
|
1050
|
+
* Emit the operations that rename a table: the table rename, then a drop and a create under the
|
|
1051
|
+
* new name of each index whose name was derived from the old table name. The old name is resolved
|
|
1052
|
+
* against the schema as this migration's earlier `renameTable` calls leave it, and the new name
|
|
1053
|
+
* against the end contract. Spread the result into `operations`:
|
|
1054
|
+
* `...this.renameTable({ table: 'userProfile', to: 'UserProfile' })`. Throws
|
|
1055
|
+
* `MIGRATION.TABLE_RENAME_UNMATCHED` when the table does not exist at that point of the migration
|
|
1056
|
+
* or the end contract lacks the new name.
|
|
812
1057
|
*/
|
|
813
1058
|
renameTable(options) {
|
|
814
1059
|
const adapter = this.controlAdapterFor("renameTable");
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1060
|
+
const rename = {
|
|
1061
|
+
namespaceId: void 0,
|
|
1062
|
+
from: options.table,
|
|
1063
|
+
to: options.to
|
|
1064
|
+
};
|
|
1065
|
+
const startContract = this.startContract;
|
|
1066
|
+
if (startContract === null) throw unmatchedTableRename(rename, "the migration has no start contract");
|
|
1067
|
+
const current = this.schemaAfterRenames(startContract);
|
|
1068
|
+
const endContract = this.endContract;
|
|
1069
|
+
const resolved = resolveTableRenameAgainst(sqliteSchemaTables(current), endContract, rename);
|
|
1070
|
+
if (!resolved.ok) throw resolved.failure;
|
|
1071
|
+
const call = sqliteTableRenameCall({
|
|
1072
|
+
previous: current,
|
|
1073
|
+
contract: endContract,
|
|
1074
|
+
rename: resolved.value,
|
|
823
1075
|
frameworkComponents: this.frameworkComponents()
|
|
824
|
-
})
|
|
1076
|
+
});
|
|
1077
|
+
this.#renames.push(call);
|
|
1078
|
+
return call.toOps(adapter);
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Emit the operations that rename a column: the column rename, then a drop and a create under
|
|
1082
|
+
* the new name of each index on the column whose name was derived from the old column name. The
|
|
1083
|
+
* column is resolved against the schema as this migration's earlier rename calls leave it, so a
|
|
1084
|
+
* column of a table an earlier `renameTable` renamed is named on the table's new name. Spread the
|
|
1085
|
+
* result into `operations`: `...this.renameColumn({ table: 'User', column: 'name', to:
|
|
1086
|
+
* 'fullName' })`. Throws `MIGRATION.COLUMN_RENAME_UNMATCHED` when the table or column does not
|
|
1087
|
+
* exist at that point of the migration, the table already has the new column, or the end
|
|
1088
|
+
* contract lacks it.
|
|
1089
|
+
*/
|
|
1090
|
+
renameColumn(options) {
|
|
1091
|
+
const adapter = this.controlAdapterFor("renameColumn");
|
|
1092
|
+
const rename = {
|
|
1093
|
+
namespaceId: void 0,
|
|
1094
|
+
table: options.table,
|
|
1095
|
+
from: options.column,
|
|
1096
|
+
to: options.to
|
|
1097
|
+
};
|
|
1098
|
+
const startContract = this.startContract;
|
|
1099
|
+
if (startContract === null) throw unmatchedColumnRename(rename, "the migration has no start contract");
|
|
1100
|
+
const current = this.schemaAfterRenames(startContract);
|
|
1101
|
+
const resolved = resolveColumnRenameAgainst(sqliteSchemaTables(current), this.endContract, rename);
|
|
1102
|
+
if (!resolved.ok) throw resolved.failure;
|
|
1103
|
+
const call = sqliteColumnRenameCall({
|
|
1104
|
+
previous: current,
|
|
1105
|
+
contract: this.endContract,
|
|
1106
|
+
rename: resolved.value,
|
|
1107
|
+
frameworkComponents: this.frameworkComponents()
|
|
1108
|
+
});
|
|
1109
|
+
this.#renames.push(call);
|
|
1110
|
+
return call.toOps(adapter);
|
|
1111
|
+
}
|
|
1112
|
+
/** The start contract's schema with this read's rename calls applied in order. */
|
|
1113
|
+
schemaAfterRenames(startContract) {
|
|
1114
|
+
const working = createWorkingSchema(sqliteContractToSchema(startContract, sqlTypeLookupsOf(this.frameworkComponents())));
|
|
1115
|
+
for (const call of this.#renames) working.apply(call);
|
|
1116
|
+
return working.current;
|
|
1117
|
+
}
|
|
1118
|
+
beginOperationsRead() {
|
|
1119
|
+
this.#renames = [];
|
|
825
1120
|
}
|
|
826
1121
|
addColumn(options) {
|
|
827
1122
|
return new AddColumnCall(options.table, options.column).toOp(this.controlAdapterFor("addColumn"));
|
|
@@ -840,6 +1135,6 @@ var SqliteMigration = class extends Migration {
|
|
|
840
1135
|
}
|
|
841
1136
|
};
|
|
842
1137
|
//#endregion
|
|
843
|
-
export {
|
|
1138
|
+
export { sqliteSchemaTables as _, createWorkingSchema as a, issueNode as c, renameTableByHandStatements as d, renderRenameTableCall as f, sqlitePlannerStrategies as g, sqliteContractToSchema as h, conflictForDisallowedCall as i, pairIndexReplacements as l, sqliteColumnRenameCall as m, buildSqlitePlanDiff as n, diffSqliteSchema as o, sqliteActualSchema as p, coalesceSubtreeIssues as r, indexNameCaseChange as s, SqliteMigration as t, planIssues as u, sqliteTableRenameCall as v, verifySqliteDatabaseSchema as y };
|
|
844
1139
|
|
|
845
|
-
//# sourceMappingURL=sqlite-migration-
|
|
1140
|
+
//# sourceMappingURL=sqlite-migration-Bz7SwolX-CHLtwGNa.mjs.map
|