@prisma/orm-target-sqlite 8.0.0-rc.16-dev.5 → 8.0.0-rc.16-dev.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/{adapter-Cy1Xx1rP-CJcOoS_O.mjs → adapter-Cfp6xn4m-C6mXiIUR.mjs} +8 -11
- package/dist/adapter-Cfp6xn4m-C6mXiIUR.mjs.map +1 -0
- package/dist/adapter.d.mts +2 -2
- package/dist/adapter.mjs +2 -2
- package/dist/adapter__adapter.mjs +1 -1
- package/dist/adapter__codec-types.d.mts +2 -2
- 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/codec-types-6UMpZZ70.d.mts +1 -0
- package/dist/codec-types-FAF08DkX.d.mts +2 -0
- package/dist/{codec-types-0AMy_n05-BJvXpaEh.d.mts → codec-types-nBSWEx87-B8Jiv6Mm.d.mts} +3 -2
- package/dist/codec-types-nBSWEx87-B8Jiv6Mm.d.mts.map +1 -0
- 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-D6F1gWDe.mjs} +6 -5
- package/dist/control-D6F1gWDe.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-DNHWGn35.mjs} +2 -2
- package/dist/{migration-65TwrHP0.mjs.map → migration-DNHWGn35.mjs.map} +1 -1
- package/dist/{op-factory-call-B_WuATMN.d.mts → op-factory-call-B0N6txAF.d.mts} +51 -7
- package/dist/op-factory-call-B0N6txAF.d.mts.map +1 -0
- package/dist/{op-factory-call-Bwp3QS4h-MwflmSX3.mjs → op-factory-call-BrLX8AMg-BSyJWo6f.mjs} +129 -17
- package/dist/op-factory-call-BrLX8AMg-BSyJWo6f.mjs.map +1 -0
- package/dist/{pack-BIZIGw3P.d.mts → pack-D3pJo5Xh.d.mts} +2 -2
- package/dist/{pack-BIZIGw3P.d.mts.map → pack-D3pJo5Xh.d.mts.map} +1 -1
- package/dist/{planner-CFIbY54l.d.mts → planner-B0nz2W_R.d.mts} +14 -6
- package/dist/planner-B0nz2W_R.d.mts.map +1 -0
- package/dist/{planner-DcRJaFjk-C9iIWF69.mjs → planner-CP704vdn-D0Nn5ZH6.mjs} +57 -14
- package/dist/planner-CP704vdn-D0Nn5ZH6.mjs.map +1 -0
- package/dist/{planner-produced-sqlite-migration-DTTOgkuK-CppVPY1d.mjs → planner-produced-sqlite-migration-Bi5jMcKu-dz5lhOAP.mjs} +4 -4
- package/dist/{planner-produced-sqlite-migration-DTTOgkuK-CppVPY1d.mjs.map → planner-produced-sqlite-migration-Bi5jMcKu-dz5lhOAP.mjs.map} +1 -1
- package/dist/planner-produced-sqlite-migration-CBmtR7UQ.d.mts +1 -0
- 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-CUUasMx_-CFXpgruj.mjs} +16 -9
- package/dist/render-ops-CUUasMx_-CFXpgruj.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-Dtcdl9x4-SNwSvz0C.mjs} +327 -35
- package/dist/sqlite-migration-Dtcdl9x4-SNwSvz0C.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 +10 -10
- package/dist/target.mjs +12 -12
- package/dist/target__codec-types.d.mts +2 -2
- 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__pack.d.mts +1 -1
- 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/codec-types-0AMy_n05-BJvXpaEh.d.mts.map +0 -1
- package/dist/codec-types-BV1uyhho.d.mts +0 -1
- package/dist/codec-types-CLFLW8jd.d.mts +0 -2
- 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,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-Dtcdl9x4-SNwSvz0C.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-BrLX8AMg-BSyJWo6f.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-Dtcdl9x4.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`,
|
|
@@ -287,10 +292,10 @@ function classifyNodeIssue(issue) {
|
|
|
287
292
|
if (columnTypeChanged(expected, blindCast(issue.actual))) return "destructive";
|
|
288
293
|
return expected.nullable ? "widening" : "destructive";
|
|
289
294
|
}
|
|
290
|
-
case RelationalSchemaNodeKind.columnDefault:
|
|
295
|
+
case RelationalSchemaNodeKind.columnDefault:
|
|
291
296
|
case RelationalSchemaNodeKind.primaryKey:
|
|
292
297
|
case RelationalSchemaNodeKind.foreignKey:
|
|
293
|
-
case RelationalSchemaNodeKind.unique: return "
|
|
298
|
+
case RelationalSchemaNodeKind.unique: return "widening";
|
|
294
299
|
default: return null;
|
|
295
300
|
}
|
|
296
301
|
}
|
|
@@ -690,6 +695,13 @@ function renamedTableIndex(renamedTables) {
|
|
|
690
695
|
};
|
|
691
696
|
}
|
|
692
697
|
/**
|
|
698
|
+
* An index on the renamed column whose wire name derives from the column name: after the rename
|
|
699
|
+
* the old and the new index cover the same columns on the same table and differ in name.
|
|
700
|
+
*/
|
|
701
|
+
function renamedColumnIndex(table, column) {
|
|
702
|
+
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 ?? []);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
693
705
|
* 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
706
|
*/
|
|
695
707
|
const indexNameCaseChange = (old, replacement) => old.tableName === replacement.tableName && old.index.name !== replacement.index.name && sqliteIdentifiersCollide(old.index.name, replacement.index.name);
|
|
@@ -707,29 +719,251 @@ function pairIndexReplacements(issues, matches) {
|
|
|
707
719
|
replacement
|
|
708
720
|
}];
|
|
709
721
|
});
|
|
722
|
+
const replacements = pairs.map(({ old, replacement }) => ({
|
|
723
|
+
drop: new DropIndexCall(old.tableName, old.index.name),
|
|
724
|
+
create: new CreateIndexCall(replacement.tableName, replacement.index.name, replacement.index.columns ?? [])
|
|
725
|
+
}));
|
|
710
726
|
return {
|
|
711
|
-
|
|
727
|
+
replacements,
|
|
728
|
+
calls: indexReplacementCalls(replacements),
|
|
712
729
|
consumed: new Set(pairs.flatMap(({ old, replacement }) => [old.issue, replacement.issue]))
|
|
713
730
|
};
|
|
714
731
|
}
|
|
715
732
|
/**
|
|
716
|
-
* The
|
|
733
|
+
* The tables of a SQLite schema. SQLite has one namespace, so the namespace id is ignored, and it
|
|
734
|
+
* compares table and column names without regard to the case of ASCII letters.
|
|
735
|
+
*/
|
|
736
|
+
function sqliteSchemaTables(schema) {
|
|
737
|
+
const hasTable = (_namespaceId, table) => Object.hasOwn(schema.tables, table);
|
|
738
|
+
return {
|
|
739
|
+
hasTable,
|
|
740
|
+
hasColumn: (_namespaceId, table, column) => Object.hasOwn(schema.tables[table]?.columns ?? {}, column),
|
|
741
|
+
tablesNamed: (_namespaceId, table) => Object.keys(schema.tables).filter((existing) => sqliteIdentifiersCollide(existing, table)),
|
|
742
|
+
columnsNamed: (_namespaceId, table, column) => Object.keys(schema.tables[table]?.columns ?? {}).filter((existing) => sqliteIdentifiersCollide(existing, column)),
|
|
743
|
+
namespacesWithTable: (table) => hasTable(UNBOUND_NAMESPACE_ID, table) ? [UNBOUND_NAMESPACE_ID] : []
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function rewriteRefs(refs, rewrite) {
|
|
747
|
+
return refs?.map(rewrite);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Rewrites the step of `kind` and `id` in a ref that runs through the given table, and the table
|
|
751
|
+
* step itself when `kind` is the table kind.
|
|
752
|
+
*/
|
|
753
|
+
function stepRewrite(tableName, kind, fromId, toId) {
|
|
754
|
+
return (ref) => {
|
|
755
|
+
const tableStep = ref[1];
|
|
756
|
+
if (tableStep?.nodeKind !== RelationalSchemaNodeKind.table || tableStep.id !== tableName) return ref;
|
|
757
|
+
return ref.map((step, index) => index >= 1 && step.nodeKind === kind && step.id === fromId ? {
|
|
758
|
+
nodeKind: kind,
|
|
759
|
+
id: toId
|
|
760
|
+
} : step);
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
function withColumnName(column, name) {
|
|
764
|
+
return new SqlColumnIR({
|
|
765
|
+
name,
|
|
766
|
+
nativeType: column.nativeType,
|
|
767
|
+
nullable: column.nullable,
|
|
768
|
+
...ifDefined("default", column.default),
|
|
769
|
+
...ifDefined("annotations", column.annotations),
|
|
770
|
+
...ifDefined("many", column.many),
|
|
771
|
+
...ifDefined("resolvedNativeType", column.resolvedNativeType),
|
|
772
|
+
...ifDefined("resolvedDefault", column.resolvedDefault),
|
|
773
|
+
...ifDefined("authoredDefault", column.authoredDefault),
|
|
774
|
+
...ifDefined("codecRef", column.codecRef),
|
|
775
|
+
...ifDefined("codecBaseNativeType", column.codecBaseNativeType),
|
|
776
|
+
...ifDefined("dataType", column.dataType),
|
|
777
|
+
...ifDefined("toCanonicalForm", column.toCanonicalForm)
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* An index whose definition carries SQL text, an expression or a predicate, keeps its columns as
|
|
782
|
+
* they are: a column named inside the text cannot be renamed here, so the diff plans the index.
|
|
717
783
|
*/
|
|
718
|
-
function
|
|
719
|
-
const
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
784
|
+
function withIndex(index, name, rewrite, columnName) {
|
|
785
|
+
const columnsFollow = index.expression === void 0 && index.where === void 0;
|
|
786
|
+
const base = {
|
|
787
|
+
naming: name === index.name ? namingOf(index.name, index.prefix) : namingOfLiveName(name),
|
|
788
|
+
where: index.where,
|
|
789
|
+
unique: index.unique,
|
|
790
|
+
partial: index.partial,
|
|
791
|
+
type: index.type,
|
|
792
|
+
options: index.options,
|
|
793
|
+
annotations: index.annotations,
|
|
794
|
+
dependsOn: rewriteRefs(index.dependsOn, rewrite)
|
|
795
|
+
};
|
|
796
|
+
return new SqlIndexIR(index.expression !== void 0 ? {
|
|
797
|
+
...base,
|
|
798
|
+
expression: index.expression
|
|
799
|
+
} : {
|
|
800
|
+
...base,
|
|
801
|
+
columns: (index.columns ?? []).map(columnsFollow ? columnName : (c) => c)
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
function rebuildTable(table, edit, rewrite) {
|
|
805
|
+
const { primaryKey } = table;
|
|
806
|
+
const { columnName } = edit;
|
|
807
|
+
return new SqlTableIR({
|
|
808
|
+
name: edit.name,
|
|
809
|
+
columns: Object.fromEntries(Object.values(table.columns).map((column) => {
|
|
810
|
+
const name = columnName(column.name);
|
|
811
|
+
return [name, name === column.name ? column : withColumnName(column, name)];
|
|
812
|
+
})),
|
|
813
|
+
...ifDefined("primaryKey", primaryKey === void 0 ? void 0 : new PrimaryKey({
|
|
814
|
+
columns: primaryKey.columns.map(columnName),
|
|
815
|
+
...ifDefined("name", primaryKey.name),
|
|
816
|
+
...ifDefined("dependsOn", rewriteRefs(primaryKey.dependsOn, rewrite))
|
|
817
|
+
})),
|
|
818
|
+
uniques: table.uniques.map((unique) => new SqlUniqueIR({
|
|
819
|
+
columns: unique.columns.map(columnName),
|
|
820
|
+
...ifDefined("name", unique.name),
|
|
821
|
+
...ifDefined("annotations", unique.annotations),
|
|
822
|
+
...ifDefined("dependsOn", rewriteRefs(unique.dependsOn, rewrite))
|
|
823
|
+
})),
|
|
824
|
+
foreignKeys: table.foreignKeys.map((fk) => new SqlForeignKeyIR({
|
|
825
|
+
columns: fk.columns.map(columnName),
|
|
826
|
+
referencedTable: edit.referencedTable(fk),
|
|
827
|
+
referencedColumns: edit.referencedColumns(fk),
|
|
828
|
+
...ifDefined("referencedSchema", fk.referencedSchema),
|
|
829
|
+
...ifDefined("name", fk.name),
|
|
830
|
+
...ifDefined("onDelete", fk.onDelete),
|
|
831
|
+
...ifDefined("onUpdate", fk.onUpdate),
|
|
832
|
+
...ifDefined("annotations", fk.annotations),
|
|
833
|
+
...ifDefined("resolvedReferencedNamespace", fk.resolvedReferencedNamespace),
|
|
834
|
+
...ifDefined("dependsOn", rewriteRefs(fk.dependsOn, rewrite))
|
|
835
|
+
})),
|
|
836
|
+
indexes: table.indexes.map((index) => withIndex(index, edit.indexName(index), rewrite, columnName)),
|
|
837
|
+
...ifDefined("checks", table.checks?.map((check) => new SqlCheckConstraintIR({
|
|
838
|
+
naming: namingOf(check.name, check.prefix),
|
|
839
|
+
expression: check.expression,
|
|
840
|
+
dependsOn: rewriteRefs(check.dependsOn, rewrite)
|
|
841
|
+
}))),
|
|
842
|
+
...ifDefined("annotations", table.annotations)
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
/** Rebuilds every table: `editFor` returns the edit for a table, or `undefined` to keep it. */
|
|
846
|
+
function mapTables(schema, rewrite, editFor) {
|
|
847
|
+
return new SqlSchemaIR({
|
|
848
|
+
tables: Object.fromEntries(Object.values(schema.tables).map((table) => {
|
|
849
|
+
const rebuilt = rebuildTable(table, {
|
|
850
|
+
name: table.name,
|
|
851
|
+
columnName: (column) => column,
|
|
852
|
+
referencedTable: (fk) => fk.referencedTable,
|
|
853
|
+
referencedColumns: (fk) => fk.referencedColumns,
|
|
854
|
+
indexName: (index) => index.name,
|
|
855
|
+
...editFor(table)
|
|
856
|
+
}, rewrite);
|
|
857
|
+
return [rebuilt.name, rebuilt];
|
|
858
|
+
})),
|
|
859
|
+
...ifDefined("annotations", schema.annotations)
|
|
724
860
|
});
|
|
725
|
-
|
|
726
|
-
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* The schema with one table under its new name. Foreign keys anywhere that reference the table
|
|
864
|
+
* follow it, and every dependency that names it moves with it. Object names do not change. An
|
|
865
|
+
* unnamed primary key, unique constraint or foreign key stays unnamed: SQLite gives such a
|
|
866
|
+
* constraint no name, so an introspected schema has none either, and the planner never renames
|
|
867
|
+
* one.
|
|
868
|
+
*/
|
|
869
|
+
function renameTableInSqliteSchema(schema, rename) {
|
|
870
|
+
const { from, to } = rename;
|
|
871
|
+
return mapTables(schema, stepRewrite(from, RelationalSchemaNodeKind.table, from, to), (table) => ({
|
|
872
|
+
...table.name === from ? { name: to } : {},
|
|
873
|
+
referencedTable: (fk) => fk.referencedTable === from ? to : fk.referencedTable
|
|
874
|
+
}));
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* The schema with one column under its new name. The table's primary key, unique constraints,
|
|
878
|
+
* foreign keys and plain column indexes name it under the new name, foreign keys anywhere that
|
|
879
|
+
* reference it follow it, and every dependency that names it moves with it. An index with an
|
|
880
|
+
* expression or a predicate keeps its SQL text, and index names do not change, as in SQLite.
|
|
881
|
+
*/
|
|
882
|
+
function renameColumnInSqliteSchema(schema, rename) {
|
|
883
|
+
const { table: tableName, from, to } = rename;
|
|
884
|
+
const rewrite = stepRewrite(tableName, RelationalSchemaNodeKind.column, `column:${from}`, `column:${to}`);
|
|
885
|
+
const renamed = (column) => column === from ? to : column;
|
|
886
|
+
return mapTables(schema, rewrite, (table) => ({
|
|
887
|
+
...table.name === tableName ? { columnName: renamed } : {},
|
|
888
|
+
referencedColumns: (fk) => fk.referencedTable === tableName ? fk.referencedColumns.map(renamed) : fk.referencedColumns
|
|
889
|
+
}));
|
|
890
|
+
}
|
|
891
|
+
function replaceIndex(schema, replacement) {
|
|
892
|
+
const { tableName, indexName: oldIndexName } = replacement.drop;
|
|
893
|
+
const newIndexName = replacement.create.indexName;
|
|
894
|
+
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);
|
|
895
|
+
}
|
|
896
|
+
/** The working schema of a plan or a migration, starting from `initial`. */
|
|
897
|
+
function createWorkingSchema(initial) {
|
|
898
|
+
return new WorkingSchemaImpl(initial);
|
|
899
|
+
}
|
|
900
|
+
var WorkingSchemaImpl = class {
|
|
901
|
+
#current;
|
|
902
|
+
constructor(initial) {
|
|
903
|
+
this.#current = initial;
|
|
904
|
+
}
|
|
905
|
+
get current() {
|
|
906
|
+
return this.#current;
|
|
907
|
+
}
|
|
908
|
+
apply(call) {
|
|
909
|
+
const renamed = call instanceof RenameColumnCall ? renameColumnInSqliteSchema(this.#current, {
|
|
910
|
+
table: call.tableName,
|
|
911
|
+
from: call.oldColumnName,
|
|
912
|
+
to: call.columnName
|
|
913
|
+
}) : renameTableInSqliteSchema(this.#current, {
|
|
914
|
+
from: call.oldTableName,
|
|
915
|
+
to: call.tableName
|
|
916
|
+
});
|
|
917
|
+
this.#current = call.indexReplacements.reduce(replaceIndex, renamed);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
/** The SQL a user runs against the database to rename the table by hand. */
|
|
921
|
+
function renameTableByHandStatements(rename) {
|
|
922
|
+
return renameTableSteps(rename.from, rename.to).map((renameStep) => renameStep.sql);
|
|
923
|
+
}
|
|
924
|
+
/** The `renameTable` call a user writes in `migration.ts` for `rename`; SQLite has no namespaces. */
|
|
925
|
+
function renderRenameTableCall(rename) {
|
|
926
|
+
return new RenameTableCall(rename.from, rename.to, []).renderTypeScript();
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The call that renames a table, carrying as companions a drop and a create under the new name of
|
|
930
|
+
* each index whose wire name derives from the old table name, since SQLite cannot rename an index.
|
|
931
|
+
* `previous` is the schema with the table under its old name; the renamed copy is diffed against
|
|
932
|
+
* `contract`. SQLite names no primary key, unique constraint or foreign key the contract leaves
|
|
933
|
+
* unnamed, so those need nothing.
|
|
934
|
+
*/
|
|
935
|
+
function sqliteTableRenameCall(input) {
|
|
936
|
+
const { from, to } = input.rename;
|
|
727
937
|
const { issues } = buildSqlitePlanDiff({
|
|
728
|
-
contract: input.
|
|
729
|
-
actualSchema:
|
|
938
|
+
contract: input.contract,
|
|
939
|
+
actualSchema: renameTableInSqliteSchema(input.previous, {
|
|
940
|
+
from,
|
|
941
|
+
to
|
|
942
|
+
}),
|
|
730
943
|
frameworkComponents: input.frameworkComponents
|
|
731
944
|
});
|
|
732
|
-
|
|
945
|
+
const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedTableIndex(/* @__PURE__ */ new Set([to])));
|
|
946
|
+
return new RenameTableCall(from, to, replacements);
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* The call that renames a column, carrying as companions a drop and a create under the new name of
|
|
950
|
+
* each index on the column whose wire name derives from the column name, since SQLite cannot rename
|
|
951
|
+
* an index and keeps the old name when it renames the column. `previous` is the schema with the
|
|
952
|
+
* column under its old name; the renamed copy is diffed against `contract`.
|
|
953
|
+
*/
|
|
954
|
+
function sqliteColumnRenameCall(input) {
|
|
955
|
+
const { table, from, to } = input.rename;
|
|
956
|
+
const { issues } = buildSqlitePlanDiff({
|
|
957
|
+
contract: input.contract,
|
|
958
|
+
actualSchema: renameColumnInSqliteSchema(input.previous, {
|
|
959
|
+
table,
|
|
960
|
+
from,
|
|
961
|
+
to
|
|
962
|
+
}),
|
|
963
|
+
frameworkComponents: input.frameworkComponents
|
|
964
|
+
});
|
|
965
|
+
const { replacements } = pairIndexReplacements(coalesceSubtreeIssues(issues), renamedColumnIndex(table, to));
|
|
966
|
+
return new RenameColumnCall(table, from, to, replacements);
|
|
733
967
|
}
|
|
734
968
|
/**
|
|
735
969
|
* Target-owned base class for SQLite migrations. Fixes the `SqlMigration`
|
|
@@ -763,6 +997,8 @@ var SqliteMigration = class extends Migration {
|
|
|
763
997
|
*/
|
|
764
998
|
controlAdapter;
|
|
765
999
|
#endView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
|
|
1000
|
+
/** The rename calls this read of `operations` has made so far, in order. */
|
|
1001
|
+
#renames = [];
|
|
766
1002
|
#startView = new MigrationContractViews(this, "SqliteMigration", (json) => SqliteContractView.fromJson(json));
|
|
767
1003
|
constructor(stack) {
|
|
768
1004
|
super(stack);
|
|
@@ -808,20 +1044,76 @@ var SqliteMigration = class extends Migration {
|
|
|
808
1044
|
return new DropTableCall(options.table).toOp(this.controlAdapterFor("dropTable"));
|
|
809
1045
|
}
|
|
810
1046
|
/**
|
|
811
|
-
* Emit the operations that rename a table: the table rename, then a drop and a create under the
|
|
1047
|
+
* Emit the operations that rename a table: the table rename, then a drop and a create under the
|
|
1048
|
+
* new name of each index whose name was derived from the old table name. The old name is resolved
|
|
1049
|
+
* against the schema as this migration's earlier `renameTable` calls leave it, and the new name
|
|
1050
|
+
* against the end contract. Spread the result into `operations`:
|
|
1051
|
+
* `...this.renameTable({ table: 'userProfile', to: 'UserProfile' })`. Throws
|
|
1052
|
+
* `MIGRATION.TABLE_RENAME_UNMATCHED` when the table does not exist at that point of the migration
|
|
1053
|
+
* or the end contract lacks the new name.
|
|
812
1054
|
*/
|
|
813
1055
|
renameTable(options) {
|
|
814
1056
|
const adapter = this.controlAdapterFor("renameTable");
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1057
|
+
const rename = {
|
|
1058
|
+
namespaceId: void 0,
|
|
1059
|
+
from: options.table,
|
|
1060
|
+
to: options.to
|
|
1061
|
+
};
|
|
1062
|
+
const startContract = this.startContract;
|
|
1063
|
+
if (startContract === null) throw unmatchedTableRename(rename, "the migration has no start contract");
|
|
1064
|
+
const current = this.schemaAfterRenames(startContract);
|
|
1065
|
+
const endContract = this.endContract;
|
|
1066
|
+
const resolved = resolveTableRenameAgainst(sqliteSchemaTables(current), endContract, rename);
|
|
1067
|
+
if (!resolved.ok) throw resolved.failure;
|
|
1068
|
+
const call = sqliteTableRenameCall({
|
|
1069
|
+
previous: current,
|
|
1070
|
+
contract: endContract,
|
|
1071
|
+
rename: resolved.value,
|
|
823
1072
|
frameworkComponents: this.frameworkComponents()
|
|
824
|
-
})
|
|
1073
|
+
});
|
|
1074
|
+
this.#renames.push(call);
|
|
1075
|
+
return call.toOps(adapter);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Emit the operations that rename a column: the column rename, then a drop and a create under
|
|
1079
|
+
* the new name of each index on the column whose name was derived from the old column name. The
|
|
1080
|
+
* column is resolved against the schema as this migration's earlier rename calls leave it, so a
|
|
1081
|
+
* column of a table an earlier `renameTable` renamed is named on the table's new name. Spread the
|
|
1082
|
+
* result into `operations`: `...this.renameColumn({ table: 'User', column: 'name', to:
|
|
1083
|
+
* 'fullName' })`. Throws `MIGRATION.COLUMN_RENAME_UNMATCHED` when the table or column does not
|
|
1084
|
+
* exist at that point of the migration, the table already has the new column, or the end
|
|
1085
|
+
* contract lacks it.
|
|
1086
|
+
*/
|
|
1087
|
+
renameColumn(options) {
|
|
1088
|
+
const adapter = this.controlAdapterFor("renameColumn");
|
|
1089
|
+
const rename = {
|
|
1090
|
+
namespaceId: void 0,
|
|
1091
|
+
table: options.table,
|
|
1092
|
+
from: options.column,
|
|
1093
|
+
to: options.to
|
|
1094
|
+
};
|
|
1095
|
+
const startContract = this.startContract;
|
|
1096
|
+
if (startContract === null) throw unmatchedColumnRename(rename, "the migration has no start contract");
|
|
1097
|
+
const current = this.schemaAfterRenames(startContract);
|
|
1098
|
+
const resolved = resolveColumnRenameAgainst(sqliteSchemaTables(current), this.endContract, rename);
|
|
1099
|
+
if (!resolved.ok) throw resolved.failure;
|
|
1100
|
+
const call = sqliteColumnRenameCall({
|
|
1101
|
+
previous: current,
|
|
1102
|
+
contract: this.endContract,
|
|
1103
|
+
rename: resolved.value,
|
|
1104
|
+
frameworkComponents: this.frameworkComponents()
|
|
1105
|
+
});
|
|
1106
|
+
this.#renames.push(call);
|
|
1107
|
+
return call.toOps(adapter);
|
|
1108
|
+
}
|
|
1109
|
+
/** The start contract's schema with this read's rename calls applied in order. */
|
|
1110
|
+
schemaAfterRenames(startContract) {
|
|
1111
|
+
const working = createWorkingSchema(sqliteContractToSchema(startContract, sqlTypeLookupsOf(this.frameworkComponents())));
|
|
1112
|
+
for (const call of this.#renames) working.apply(call);
|
|
1113
|
+
return working.current;
|
|
1114
|
+
}
|
|
1115
|
+
beginOperationsRead() {
|
|
1116
|
+
this.#renames = [];
|
|
825
1117
|
}
|
|
826
1118
|
addColumn(options) {
|
|
827
1119
|
return new AddColumnCall(options.table, options.column).toOp(this.controlAdapterFor("addColumn"));
|
|
@@ -840,6 +1132,6 @@ var SqliteMigration = class extends Migration {
|
|
|
840
1132
|
}
|
|
841
1133
|
};
|
|
842
1134
|
//#endregion
|
|
843
|
-
export {
|
|
1135
|
+
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
1136
|
|
|
845
|
-
//# sourceMappingURL=sqlite-migration-
|
|
1137
|
+
//# sourceMappingURL=sqlite-migration-Dtcdl9x4-SNwSvz0C.mjs.map
|