@prisma-next/target-sqlite 0.13.0-dev.4 → 0.13.0-dev.40
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/contract-free.d.mts +35 -2
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +3 -22
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control.d.mts +5 -8
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +18 -20
- package/dist/control.mjs.map +1 -1
- package/dist/ddl-DrtjQMFK.mjs +68 -0
- package/dist/ddl-DrtjQMFK.mjs.map +1 -0
- package/dist/{descriptor-meta-Dxx2A6PT.mjs → descriptor-meta-DxmEeTJ-.mjs} +10 -3
- package/dist/descriptor-meta-DxmEeTJ-.mjs.map +1 -0
- package/dist/migration.d.mts +4 -46
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -3
- package/dist/migration.mjs.map +1 -1
- package/dist/op-factory-call-DmdfD1yd.mjs +794 -0
- package/dist/op-factory-call-DmdfD1yd.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +22 -12
- package/dist/op-factory-call.d.mts.map +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-DSNDwQy9.mjs → planner-Ciq8p_dL.mjs} +80 -12
- package/dist/planner-Ciq8p_dL.mjs.map +1 -0
- package/dist/{planner-produced-sqlite-migration-DowV_vHw.mjs → planner-produced-sqlite-migration-0xPEm3R1.mjs} +9 -5
- package/dist/planner-produced-sqlite-migration-0xPEm3R1.mjs.map +1 -0
- package/dist/{planner-produced-sqlite-migration-C1yqJAiM.d.mts → planner-produced-sqlite-migration-CpgsY-M9.d.mts} +5 -4
- package/dist/planner-produced-sqlite-migration-CpgsY-M9.d.mts.map +1 -0
- package/dist/planner-produced-sqlite-migration.d.mts +1 -1
- package/dist/planner-produced-sqlite-migration.mjs +1 -1
- package/dist/planner.d.mts +5 -2
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +1 -1
- package/dist/render-ops-BDW2tUeR.mjs +22 -0
- package/dist/render-ops-BDW2tUeR.mjs.map +1 -0
- package/dist/render-ops.d.mts +2 -1
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/runtime.d.mts +1 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -2
- package/dist/shared-Dhc8mLK1.d.mts.map +1 -1
- package/dist/{sqlite-contract-serializer-jcRu8aHh.mjs → sqlite-contract-serializer--iaDgC8e.mjs} +17 -6
- package/dist/sqlite-contract-serializer--iaDgC8e.mjs.map +1 -0
- package/dist/sqlite-migration-A0rwqPOG.mjs +92 -0
- package/dist/sqlite-migration-A0rwqPOG.mjs.map +1 -0
- package/dist/sqlite-migration-DVfhQwN_.d.mts +75 -0
- package/dist/sqlite-migration-DVfhQwN_.d.mts.map +1 -0
- package/package.json +18 -18
- package/src/contract-free/checks.ts +75 -0
- package/src/core/control-target.ts +4 -4
- package/src/core/errors.ts +28 -0
- package/src/core/migrations/issue-planner.ts +151 -8
- package/src/core/migrations/op-factory-call.ts +332 -45
- package/src/core/migrations/operations/columns.ts +32 -26
- package/src/core/migrations/operations/indexes.ts +31 -27
- package/src/core/migrations/operations/shared.ts +11 -3
- package/src/core/migrations/operations/tables.ts +39 -37
- package/src/core/migrations/planner-ddl-builders.ts +7 -16
- package/src/core/migrations/planner-produced-sqlite-migration.ts +8 -2
- package/src/core/migrations/planner-strategies.ts +3 -3
- package/src/core/migrations/planner.ts +14 -2
- package/src/core/migrations/render-ops.ts +37 -9
- package/src/core/migrations/runner.ts +16 -12
- package/src/core/migrations/sqlite-migration.ts +119 -1
- package/src/core/sqlite-contract-serializer.ts +5 -0
- package/src/core/sqlite-unbound-database.ts +30 -54
- package/src/exports/contract-free.ts +8 -0
- package/src/exports/migration.ts +8 -3
- package/dist/descriptor-meta-Dxx2A6PT.mjs.map +0 -1
- package/dist/descriptor-meta-runtime-BkXK3OjD.mjs +0 -12
- package/dist/descriptor-meta-runtime-BkXK3OjD.mjs.map +0 -1
- package/dist/op-factory-call-DymqdXQW.mjs +0 -279
- package/dist/op-factory-call-DymqdXQW.mjs.map +0 -1
- package/dist/planner-DSNDwQy9.mjs.map +0 -1
- package/dist/planner-produced-sqlite-migration-C1yqJAiM.d.mts.map +0 -1
- package/dist/planner-produced-sqlite-migration-DowV_vHw.mjs.map +0 -1
- package/dist/render-ops-CFRbJ3Yb.mjs +0 -8
- package/dist/render-ops-CFRbJ3Yb.mjs.map +0 -1
- package/dist/sqlite-contract-serializer-jcRu8aHh.mjs.map +0 -1
- package/dist/sqlite-migration-CUqgmzQH.mjs +0 -16
- package/dist/sqlite-migration-CUqgmzQH.mjs.map +0 -1
- package/dist/sqlite-migration-D4XGYzgQ.d.mts +0 -17
- package/dist/sqlite-migration-D4XGYzgQ.d.mts.map +0 -1
- package/dist/tables-CjB7vXCr.mjs +0 -412
- package/dist/tables-CjB7vXCr.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"planner-produced-sqlite-migration-DowV_vHw.mjs","names":["#calls","#meta","#destination","#spaceId"],"sources":["../src/core/migrations/render-typescript.ts","../src/core/migrations/planner-produced-sqlite-migration.ts"],"sourcesContent":["/**\n * Polymorphic TypeScript emitter for the SQLite migration IR. Mirrors the\n * Postgres `render-typescript.ts` — different base-class + factory module\n * specifier, same overall shape.\n */\n\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport { detectScaffoldRuntime, shebangLineFor } from '@prisma-next/migration-tools/migration-ts';\nimport { type ImportRequirement, renderImports } from '@prisma-next/ts-render';\n\nexport interface RenderMigrationMeta {\n readonly from: string | null;\n readonly to: string;\n}\n\n/**\n * Always-present base imports for the rendered scaffold. Both come from\n * `@prisma-next/sqlite/migration` so an authored SQLite\n * `migration.ts` only needs a single dependency for its base class and\n * its CLI entrypoint. Mirrors Postgres's `BASE_IMPORTS`.\n *\n * - `Migration` — the facade re-export fixes the `SqlMigration`\n * generic to `SqlitePlanTargetDetails` and the abstract `targetId` to\n * `'sqlite'`.\n * - `MigrationCLI` — the migration-file CLI entrypoint, re-exported from\n * `@prisma-next/cli/migration-cli`. Loads `prisma-next.config.ts`,\n * assembles a `ControlStack`, and instantiates the migration class.\n */\nconst BASE_IMPORTS: readonly ImportRequirement[] = [\n { moduleSpecifier: '@prisma-next/sqlite/migration', symbol: 'Migration' },\n { moduleSpecifier: '@prisma-next/sqlite/migration', symbol: 'MigrationCLI' },\n];\n\nexport function renderCallsToTypeScript(\n calls: ReadonlyArray<OpFactoryCall>,\n meta: RenderMigrationMeta,\n): string {\n const imports = buildImports(calls);\n const operationsBody = calls.map((c) => c.renderTypeScript()).join(',\\n');\n\n return [\n shebangLineFor(detectScaffoldRuntime()),\n imports,\n '',\n 'export default class M extends Migration {',\n buildDescribeMethod(meta),\n ' override get operations() {',\n ' return [',\n indent(operationsBody, 6),\n ' ];',\n ' }',\n '}',\n '',\n 'MigrationCLI.run(import.meta.url, M);',\n '',\n ].join('\\n');\n}\n\nfunction buildImports(calls: ReadonlyArray<OpFactoryCall>): string {\n const requirements: ImportRequirement[] = [...BASE_IMPORTS];\n for (const call of calls) {\n for (const req of call.importRequirements()) {\n requirements.push(req);\n }\n }\n return renderImports(requirements);\n}\n\nfunction buildDescribeMethod(meta: RenderMigrationMeta): string {\n const lines: string[] = [];\n lines.push(' override describe() {');\n lines.push(' return {');\n lines.push(` from: ${JSON.stringify(meta.from)},`);\n lines.push(` to: ${JSON.stringify(meta.to)},`);\n lines.push(' };');\n lines.push(' }');\n lines.push('');\n return lines.join('\\n');\n}\n\nfunction indent(text: string, spaces: number): string {\n const pad = ' '.repeat(spaces);\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${pad}${line}` : line))\n .join('\\n');\n}\n","import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type {\n MigrationPlanWithAuthoringSurface,\n OpFactoryCall,\n} from '@prisma-next/framework-components/control';\nimport type { MigrationMeta } from '@prisma-next/migration-tools/migration';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\nimport { renderOps } from './render-ops';\nimport { renderCallsToTypeScript } from './render-typescript';\nimport { SqliteMigration } from './sqlite-migration';\n\ntype Op = SqlMigrationPlanOperation<SqlitePlanTargetDetails>;\n\nexport interface SqliteMigrationDestinationInfo {\n readonly storageHash: string;\n readonly profileHash?: string;\n}\n\nexport class TypeScriptRenderableSqliteMigration\n extends SqliteMigration\n implements MigrationPlanWithAuthoringSurface\n{\n readonly #calls: readonly OpFactoryCall[];\n readonly #meta: MigrationMeta;\n readonly #destination: SqliteMigrationDestinationInfo;\n readonly #spaceId: string;\n\n constructor(\n calls: readonly OpFactoryCall[],\n meta: MigrationMeta,\n spaceId: string,\n destination?: SqliteMigrationDestinationInfo,\n ) {\n super();\n this.#calls = calls;\n this.#meta = meta;\n this.#spaceId = spaceId;\n this.#destination = destination ?? { storageHash: meta.to };\n }\n\n override get operations(): readonly Op[] {\n return renderOps(this.#calls);\n }\n\n override describe(): MigrationMeta {\n return this.#meta;\n }\n\n override get destination(): SqliteMigrationDestinationInfo {\n return this.#destination;\n }\n\n /**\n * Contract space this planner-produced plan applies to. Threaded\n * from {@link SqlMigrationPlannerPlanOptions.spaceId} so the runner\n * keys the marker row by the right space when executing the plan.\n */\n get spaceId(): string {\n return this.#spaceId;\n }\n\n renderTypeScript(): string {\n return renderCallsToTypeScript(this.#calls, {\n from: this.#meta.from,\n to: this.#meta.to,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,MAAM,eAA6C,CACjD;CAAE,iBAAiB;CAAiC,QAAQ;AAAY,GACxE;CAAE,iBAAiB;CAAiC,QAAQ;AAAe,CAC7E;AAEA,SAAgB,wBACd,OACA,MACQ;CACR,MAAM,UAAU,aAAa,KAAK;CAClC,MAAM,iBAAiB,MAAM,KAAK,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK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;;;;;;CAOA,IAAI,UAAkB;EACpB,OAAO,KAAKC;CACd;CAEA,mBAA2B;EACzB,OAAO,wBAAwB,KAAKH,QAAQ;GAC1C,MAAM,KAAKC,MAAM;GACjB,IAAI,KAAKA,MAAM;EACjB,CAAC;CACH;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-ops-CFRbJ3Yb.mjs","names":[],"sources":["../src/core/migrations/render-ops.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { OpFactoryCall } from '@prisma-next/framework-components/control';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\ntype Op = SqlMigrationPlanOperation<SqlitePlanTargetDetails>;\n\nexport function renderOps(calls: readonly OpFactoryCall[]): Op[] {\n // Each call's `toOp()` is typed as the framework `MigrationPlanOperation`;\n // every concrete Call class on the sqlite planner path produces an op\n // whose `target.details` is `SqlitePlanTargetDetails`-shaped (or whose\n // `target.details` is absent, which is structurally compatible). The\n // narrowing cast happens at this single integration boundary instead of\n // poisoning every caller's type.\n return calls.map((c) => c.toOp() as Op);\n}\n"],"mappings":";AAMA,SAAgB,UAAU,OAAuC;CAO/D,OAAO,MAAM,KAAK,MAAM,EAAE,KAAK,CAAO;AACxC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-contract-serializer-jcRu8aHh.mjs","names":[],"sources":["../src/core/sqlite-unbound-database.ts","../src/core/sqlite-contract-serializer.ts"],"sourcesContent":["import {\n freezeNode,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport {\n type SqlNamespaceTablesInput,\n StorageTable,\n type StorageTableInput,\n} from '@prisma-next/sql-contract/types';\nimport { blindCast, castAs } from '@prisma-next/utils/casts';\n\nexport type SqliteDatabaseInput = {\n readonly id: string;\n readonly entries: {\n readonly table: Readonly<Record<string, StorageTable | StorageTableInput>>;\n };\n};\n\nconst SQLITE_NAMESPACE_KIND = 'sqlite-namespace' as const;\n\nfunction isMaterializedSqliteNamespace(\n ns: Namespace | SqlNamespaceTablesInput,\n): ns is SqliteDatabase | SqliteUnboundDatabase {\n if (typeof ns !== 'object' || ns === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(ns);\n if (proto === Object.prototype || proto === null) {\n return false;\n }\n return (ns as { kind?: unknown }).kind === SQLITE_NAMESPACE_KIND;\n}\n\n/**\n * SQLite namespace concretion carrying table metadata under\n * `entries.table` and unqualified `qualifyTable()` emission for runtime\n * SQL rendering.\n */\nexport class SqliteDatabase extends NamespaceBase {\n declare readonly kind: string;\n\n readonly id: string;\n readonly entries: Readonly<{\n readonly table: Readonly<Record<string, StorageTable>>;\n }>;\n\n constructor(input: SqliteDatabaseInput) {\n super();\n this.id = input.id;\n this.entries = Object.freeze({\n table: Object.freeze(\n Object.fromEntries(\n Object.entries(input.entries.table).map(([k, v]) => [\n k,\n v instanceof StorageTable ? v : new StorageTable(v as StorageTableInput),\n ]),\n ),\n ),\n });\n Object.defineProperty(this, 'kind', {\n value: SQLITE_NAMESPACE_KIND,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n qualifier(): string {\n return '';\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\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 */\nexport class SqliteUnboundDatabase extends SqliteDatabase {\n static readonly instance: SqliteUnboundDatabase = new SqliteUnboundDatabase();\n\n private constructor() {\n super({ id: UNBOUND_NAMESPACE_ID, entries: { table: {} } });\n }\n}\n\nexport function buildSqliteNamespace(\n input: SqlNamespaceTablesInput,\n): SqliteDatabase | SqliteUnboundDatabase {\n if (input.id !== UNBOUND_NAMESPACE_ID) {\n throw new Error(\n `buildSqliteNamespace: SQLite has no schema concept; the only valid namespace id is \"${UNBOUND_NAMESPACE_ID}\" (received \"${input.id}\").`,\n );\n }\n if (Object.keys(input.entries.table).length === 0) {\n return castAs<SqliteUnboundDatabase>(SqliteUnboundDatabase.instance);\n }\n return new SqliteDatabase({ id: input.id, entries: input.entries });\n}\n\nexport function buildSqliteNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>,\n): Readonly<Record<string, SqliteDatabase | SqliteUnboundDatabase>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsKey, ns]) => [\n nsKey,\n isMaterializedSqliteNamespace(ns)\n ? ns\n : buildSqliteNamespace(\n blindCast<\n SqlNamespaceTablesInput,\n 'non-materialized SQLite namespace map entry is a SqlNamespaceTablesInput'\n >(ns),\n ),\n ]),\n );\n}\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 */\nexport function sqliteCreateNamespace(\n input: SqlNamespaceTablesInput,\n): SqliteDatabase | SqliteUnboundDatabase {\n return buildSqliteNamespace(input);\n}\n","import type { Contract } from '@prisma-next/contract/types';\nimport { SqlContractSerializerBase } from '@prisma-next/family-sql/ir';\nimport { type Namespace, NamespaceBase } from '@prisma-next/framework-components/ir';\nimport type { SqlNamespaceTablesInput, SqlStorage } from '@prisma-next/sql-contract/types';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { buildSqliteNamespace } from './sqlite-unbound-database';\n\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 */\nexport class SqliteContractSerializer extends SqlContractSerializerBase<Contract<SqlStorage>> {\n constructor() {\n super(new Map());\n }\n\n protected override hydrateSqlNamespaceEntry(\n nsId: string,\n raw: Namespace | Record<string, unknown>,\n ): Namespace | SqlNamespaceTablesInput {\n if (raw instanceof NamespaceBase) {\n return raw;\n }\n const hydrated = blindCast<\n SqlNamespaceTablesInput,\n 'super.hydrateSqlNamespaceEntry returns the tables form when raw is not a NamespaceBase'\n >(super.hydrateSqlNamespaceEntry(nsId, raw));\n return buildSqliteNamespace(hydrated);\n }\n}\n"],"mappings":";;;;;AAoBA,MAAM,wBAAwB;;;;;;AAoB9B,IAAa,iBAAb,cAAoC,cAAc;CAGhD;CACA;CAIA,YAAY,OAA4B;EACtC,MAAM;EACN,KAAK,KAAK,MAAM;EAChB,KAAK,UAAU,OAAO,OAAO,EAC3B,OAAO,OAAO,OACZ,OAAO,YACL,OAAO,QAAQ,MAAM,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAClD,GACA,aAAa,eAAe,IAAI,IAAI,aAAa,CAAsB,CACzE,CAAC,CACH,CACF,EACF,CAAC;EACD,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GACZ,cAAc;EAChB,CAAC;EACD,WAAW,IAAI;CACjB;CAEA,YAAoB;EAClB,OAAO;CACT;CAEA,aAAa,WAA2B;EACtC,OAAO,IAAI,UAAU;CACvB;AACF;;;;;;;;;;;;;;;;;;AAmBA,IAAa,wBAAb,MAAa,8BAA8B,eAAe;CACxD,OAAgB,WAAkC,IAAI,sBAAsB;CAE5E,cAAsB;EACpB,MAAM;GAAE,IAAI;GAAsB,SAAS,EAAE,OAAO,CAAC,EAAE;EAAE,CAAC;CAC5D;AACF;AAEA,SAAgB,qBACd,OACwC;CACxC,IAAI,MAAM,OAAO,sBACf,MAAM,IAAI,MACR,uFAAuF,qBAAqB,eAAe,MAAM,GAAG,IACtI;CAEF,IAAI,OAAO,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,WAAW,GAC9C,OAAO,OAA8B,sBAAsB,QAAQ;CAErE,OAAO,IAAI,eAAe;EAAE,IAAI,MAAM;EAAI,SAAS,MAAM;CAAQ,CAAC;AACpE;;;;;;;;;;;AA8BA,SAAgB,sBACd,OACwC;CACxC,OAAO,qBAAqB,KAAK;AACnC;;;;;;;;;ACzIA,IAAa,2BAAb,cAA8C,0BAAgD;CAC5F,cAAc;EACZ,sBAAM,IAAI,IAAI,CAAC;CACjB;CAEA,yBACE,MACA,KACqC;EACrC,IAAI,eAAe,eACjB,OAAO;EAMT,OAAO,qBAJU,UAGf,MAAM,yBAAyB,MAAM,GAAG,CACP,CAAC;CACtC;AACF"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Migration } from "@prisma-next/family-sql/migration";
|
|
2
|
-
//#region src/core/migrations/sqlite-migration.ts
|
|
3
|
-
/**
|
|
4
|
-
* Target-owned base class for SQLite migrations. Fixes the `SqlMigration`
|
|
5
|
-
* generic to `SqlitePlanTargetDetails` and the abstract `targetId` to the
|
|
6
|
-
* SQLite literal, so both user-authored migrations and renderer-generated
|
|
7
|
-
* scaffolds can extend `SqliteMigration` directly without redeclaring
|
|
8
|
-
* target-local identity.
|
|
9
|
-
*/
|
|
10
|
-
var SqliteMigration = class extends Migration {
|
|
11
|
-
targetId = "sqlite";
|
|
12
|
-
};
|
|
13
|
-
//#endregion
|
|
14
|
-
export { SqliteMigration as t };
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=sqlite-migration-CUqgmzQH.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-migration-CUqgmzQH.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/sqlite-migration.ts"],"sourcesContent":["import { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { SqlitePlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for SQLite migrations. Fixes the `SqlMigration`\n * generic to `SqlitePlanTargetDetails` and the abstract `targetId` to the\n * SQLite literal, so both user-authored migrations and renderer-generated\n * scaffolds can extend `SqliteMigration` directly without redeclaring\n * target-local identity.\n */\nexport abstract class SqliteMigration extends SqlMigration<SqlitePlanTargetDetails> {\n readonly targetId = 'sqlite' as const;\n}\n"],"mappings":";;;;;;;;;AAUA,IAAsB,kBAAtB,cAA8CA,UAAsC;CAClF,WAAoB;AACtB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { t as SqlitePlanTargetDetails } from "./planner-target-details-xR6UfIcz.mjs";
|
|
2
|
-
import { Migration } from "@prisma-next/family-sql/migration";
|
|
3
|
-
|
|
4
|
-
//#region src/core/migrations/sqlite-migration.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Target-owned base class for SQLite migrations. Fixes the `SqlMigration`
|
|
7
|
-
* generic to `SqlitePlanTargetDetails` and the abstract `targetId` to the
|
|
8
|
-
* SQLite literal, so both user-authored migrations and renderer-generated
|
|
9
|
-
* scaffolds can extend `SqliteMigration` directly without redeclaring
|
|
10
|
-
* target-local identity.
|
|
11
|
-
*/
|
|
12
|
-
declare abstract class SqliteMigration extends Migration<SqlitePlanTargetDetails> {
|
|
13
|
-
readonly targetId: "sqlite";
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { SqliteMigration as t };
|
|
17
|
-
//# sourceMappingURL=sqlite-migration-D4XGYzgQ.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-migration-D4XGYzgQ.d.mts","names":[],"sources":["../src/core/migrations/sqlite-migration.ts"],"mappings":";;;;;;AAUA;;;;;uBAAsB,eAAA,SAAwB,SAAY,CAAC,uBAAA;EAAA,SAChD,QAAA;AAAA"}
|
package/dist/tables-CjB7vXCr.mjs
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { n as stripOuterParens } from "./default-normalizer-DuoHj9-O.mjs";
|
|
2
|
-
import { n as escapeLiteral, r as quoteIdentifier } from "./sql-utils-CV8Bdgtc.mjs";
|
|
3
|
-
import { t as buildTargetDetails } from "./planner-target-details-H8z9TFDg.mjs";
|
|
4
|
-
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
5
|
-
import { REFERENTIAL_ACTION_SQL } from "@prisma-next/sql-contract/referential-action-sql";
|
|
6
|
-
//#region src/core/migrations/operations/shared.ts
|
|
7
|
-
function step(description, sql) {
|
|
8
|
-
return {
|
|
9
|
-
description,
|
|
10
|
-
sql
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Renders a single column's inline DDL fragment within a `CREATE TABLE`
|
|
15
|
-
* statement. Honours the `inlineAutoincrementPrimaryKey` flag — SQLite
|
|
16
|
-
* treats `INTEGER PRIMARY KEY AUTOINCREMENT` as a special form that aliases
|
|
17
|
-
* `rowid`, and the column must not carry a `DEFAULT` or repeat `NOT NULL`.
|
|
18
|
-
*/
|
|
19
|
-
function renderColumnDefinition(column) {
|
|
20
|
-
const parts = [quoteIdentifier(column.name), column.typeSql];
|
|
21
|
-
if (column.inlineAutoincrementPrimaryKey) parts.push("PRIMARY KEY AUTOINCREMENT");
|
|
22
|
-
else {
|
|
23
|
-
if (column.defaultSql) parts.push(column.defaultSql);
|
|
24
|
-
if (!column.nullable) parts.push("NOT NULL");
|
|
25
|
-
}
|
|
26
|
-
return parts.join(" ");
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Renders an inline FOREIGN KEY constraint clause for a `CREATE TABLE`
|
|
30
|
-
* body. Returns the empty string when `constraint` is false (the FK is
|
|
31
|
-
* tracked at the contract level for index-creation purposes only and must
|
|
32
|
-
* not produce DDL).
|
|
33
|
-
*/
|
|
34
|
-
function renderForeignKeyClause(fk) {
|
|
35
|
-
if (!fk.constraint) return "";
|
|
36
|
-
let sql = `${fk.name ? `CONSTRAINT ${quoteIdentifier(fk.name)} ` : ""}FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(", ")}) REFERENCES ${quoteIdentifier(fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(", ")})`;
|
|
37
|
-
if (fk.onDelete !== void 0) sql += ` ON DELETE ${REFERENTIAL_ACTION_SQL[fk.onDelete]}`;
|
|
38
|
-
if (fk.onUpdate !== void 0) sql += ` ON UPDATE ${REFERENTIAL_ACTION_SQL[fk.onUpdate]}`;
|
|
39
|
-
return sql;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/core/migrations/operations/columns.ts
|
|
43
|
-
function addColumn(tableName, column) {
|
|
44
|
-
const addSql = [
|
|
45
|
-
`ALTER TABLE ${quoteIdentifier(tableName)}`,
|
|
46
|
-
`ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,
|
|
47
|
-
column.defaultSql,
|
|
48
|
-
column.nullable ? "" : "NOT NULL"
|
|
49
|
-
].filter(Boolean).join(" ");
|
|
50
|
-
return {
|
|
51
|
-
id: `column.${tableName}.${column.name}`,
|
|
52
|
-
label: `Add column ${column.name} on ${tableName}`,
|
|
53
|
-
summary: `Adds column ${column.name} on ${tableName}`,
|
|
54
|
-
operationClass: "additive",
|
|
55
|
-
target: {
|
|
56
|
-
id: "sqlite",
|
|
57
|
-
details: buildTargetDetails("column", column.name, tableName)
|
|
58
|
-
},
|
|
59
|
-
precheck: [step(`ensure column "${column.name}" is missing`, `SELECT COUNT(*) = 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(column.name)}'`)],
|
|
60
|
-
execute: [step(`add column "${column.name}"`, addSql)],
|
|
61
|
-
postcheck: [step(`verify column "${column.name}" exists`, `SELECT COUNT(*) > 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(column.name)}'`)]
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function dropColumn(tableName, columnName) {
|
|
65
|
-
return {
|
|
66
|
-
id: `dropColumn.${tableName}.${columnName}`,
|
|
67
|
-
label: `Drop column ${columnName} on ${tableName}`,
|
|
68
|
-
summary: `Drops column ${columnName} on ${tableName} which is not in the contract`,
|
|
69
|
-
operationClass: "destructive",
|
|
70
|
-
target: {
|
|
71
|
-
id: "sqlite",
|
|
72
|
-
details: buildTargetDetails("column", columnName, tableName)
|
|
73
|
-
},
|
|
74
|
-
precheck: [step(`ensure column "${columnName}" exists on "${tableName}"`, `SELECT COUNT(*) > 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(columnName)}'`)],
|
|
75
|
-
execute: [step(`drop column "${columnName}" from "${tableName}"`, `ALTER TABLE ${quoteIdentifier(tableName)} DROP COLUMN ${quoteIdentifier(columnName)}`)],
|
|
76
|
-
postcheck: [step(`verify column "${columnName}" is gone from "${tableName}"`, `SELECT COUNT(*) = 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(columnName)}'`)]
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/core/migrations/planner-ddl-builders.ts
|
|
81
|
-
/**
|
|
82
|
-
* Low-level DDL fragment builders for SQLite migrations.
|
|
83
|
-
*
|
|
84
|
-
* These helpers consume `StorageColumn` (the contract shape, possibly with
|
|
85
|
-
* `typeRef`) and produce string fragments. They are called once per column
|
|
86
|
-
* at the call-construction boundary in `issue-planner.ts` / strategies to
|
|
87
|
-
* build flat `SqliteColumnSpec`s; the operation factories themselves never
|
|
88
|
-
* see `StorageColumn` or `storageTypes`.
|
|
89
|
-
*/
|
|
90
|
-
const SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*$/;
|
|
91
|
-
function assertSafeNativeType(nativeType) {
|
|
92
|
-
if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) throw new Error(`Unsafe native type name in contract: "${nativeType}". Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*\$/`);
|
|
93
|
-
}
|
|
94
|
-
function assertSafeDefaultExpression(expression) {
|
|
95
|
-
if (expression.includes(";") || /--|\/\*|\bSELECT\b/i.test(expression)) throw new Error(`Unsafe default expression in contract: "${expression}". Default expressions must not contain semicolons, SQL comment tokens, or subqueries.`);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Renders the column's DDL type token (e.g. `"INTEGER"`, `"TEXT"`).
|
|
99
|
-
* Resolves `typeRef` against `storageTypes` and validates the resulting
|
|
100
|
-
* native type against a safe-identifier pattern.
|
|
101
|
-
*/
|
|
102
|
-
function buildColumnTypeSql(column, storageTypes = {}) {
|
|
103
|
-
const resolved = resolveColumnTypeMetadata(column, storageTypes);
|
|
104
|
-
assertSafeNativeType(resolved.nativeType);
|
|
105
|
-
return resolved.nativeType.toUpperCase();
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Renders the column's `DEFAULT …` clause. Returns the empty string when
|
|
109
|
-
* there is no default, and also when the default is `autoincrement()` —
|
|
110
|
-
* SQLite encodes that as `INTEGER PRIMARY KEY AUTOINCREMENT` inline on the
|
|
111
|
-
* column definition, not as a separate DEFAULT.
|
|
112
|
-
*/
|
|
113
|
-
function buildColumnDefaultSql(columnDefault) {
|
|
114
|
-
if (!columnDefault) return "";
|
|
115
|
-
switch (columnDefault.kind) {
|
|
116
|
-
case "literal": return `DEFAULT ${renderDefaultLiteral(columnDefault.value)}`;
|
|
117
|
-
case "function":
|
|
118
|
-
if (columnDefault.expression === "autoincrement()") return "";
|
|
119
|
-
if (columnDefault.expression === "now()") return "DEFAULT (datetime('now'))";
|
|
120
|
-
assertSafeDefaultExpression(columnDefault.expression);
|
|
121
|
-
return `DEFAULT (${columnDefault.expression})`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function renderDefaultLiteral(value) {
|
|
125
|
-
if (value instanceof Date) return `'${escapeLiteral(value.toISOString())}'`;
|
|
126
|
-
if (typeof value === "string") return `'${escapeLiteral(value)}'`;
|
|
127
|
-
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
128
|
-
if (typeof value === "boolean") return value ? "1" : "0";
|
|
129
|
-
if (value === null) return "NULL";
|
|
130
|
-
return `'${escapeLiteral(JSON.stringify(value))}'`;
|
|
131
|
-
}
|
|
132
|
-
function buildCreateIndexSql(tableName, indexName, columns, unique = false) {
|
|
133
|
-
return `CREATE ${unique ? "UNIQUE " : ""}INDEX ${quoteIdentifier(indexName)} ON ${quoteIdentifier(tableName)} (${columns.map(quoteIdentifier).join(", ")})`;
|
|
134
|
-
}
|
|
135
|
-
function buildDropIndexSql(indexName) {
|
|
136
|
-
return `DROP INDEX IF EXISTS ${quoteIdentifier(indexName)}`;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* True when the column is rendered inline as `INTEGER PRIMARY KEY
|
|
140
|
-
* AUTOINCREMENT`. Requires the column's default to be `autoincrement()` and
|
|
141
|
-
* the column to be the sole member of the table's primary key — anything
|
|
142
|
-
* else falls back to a separate PRIMARY KEY constraint with a default
|
|
143
|
-
* AUTOINCREMENT semantics expressed elsewhere.
|
|
144
|
-
*/
|
|
145
|
-
function isInlineAutoincrementPrimaryKey(table, columnName) {
|
|
146
|
-
if (table.primaryKey?.columns.length !== 1) return false;
|
|
147
|
-
if (table.primaryKey.columns[0] !== columnName) return false;
|
|
148
|
-
const column = table.columns[columnName];
|
|
149
|
-
return column?.default?.kind === "function" && column.default.expression === "autoincrement()";
|
|
150
|
-
}
|
|
151
|
-
function resolveColumnTypeMetadata(column, storageTypes) {
|
|
152
|
-
if (!column.typeRef) return column;
|
|
153
|
-
const referencedType = storageTypes[column.typeRef];
|
|
154
|
-
if (!referencedType) throw new Error(`Storage type "${column.typeRef}" referenced by column is not defined in storage.types.`);
|
|
155
|
-
if (isPostgresEnumStorageEntry(referencedType)) return {
|
|
156
|
-
codecId: referencedType.codecId,
|
|
157
|
-
nativeType: referencedType.nativeType,
|
|
158
|
-
typeParams: { values: referencedType.values }
|
|
159
|
-
};
|
|
160
|
-
return {
|
|
161
|
-
codecId: referencedType.codecId,
|
|
162
|
-
nativeType: referencedType.nativeType,
|
|
163
|
-
typeParams: referencedType.typeParams
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/core/migrations/operations/indexes.ts
|
|
168
|
-
function createIndex(tableName, indexName, columns) {
|
|
169
|
-
return {
|
|
170
|
-
id: `index.${tableName}.${indexName}`,
|
|
171
|
-
label: `Create index ${indexName} on ${tableName}`,
|
|
172
|
-
summary: `Creates index ${indexName} on ${tableName}`,
|
|
173
|
-
operationClass: "additive",
|
|
174
|
-
target: {
|
|
175
|
-
id: "sqlite",
|
|
176
|
-
details: buildTargetDetails("index", indexName, tableName)
|
|
177
|
-
},
|
|
178
|
-
precheck: [step(`ensure index "${indexName}" is missing`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`)],
|
|
179
|
-
execute: [step(`create index "${indexName}"`, buildCreateIndexSql(tableName, indexName, columns))],
|
|
180
|
-
postcheck: [step(`verify index "${indexName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`)]
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function dropIndex(tableName, indexName) {
|
|
184
|
-
return {
|
|
185
|
-
id: `dropIndex.${tableName}.${indexName}`,
|
|
186
|
-
label: `Drop index ${indexName} on ${tableName}`,
|
|
187
|
-
summary: `Drops index ${indexName} on ${tableName} which is not in the contract`,
|
|
188
|
-
operationClass: "destructive",
|
|
189
|
-
target: {
|
|
190
|
-
id: "sqlite",
|
|
191
|
-
details: buildTargetDetails("index", indexName, tableName)
|
|
192
|
-
},
|
|
193
|
-
precheck: [step(`ensure index "${indexName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`)],
|
|
194
|
-
execute: [step(`drop index "${indexName}"`, buildDropIndexSql(indexName))],
|
|
195
|
-
postcheck: [step(`verify index "${indexName}" is gone`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`)]
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region src/core/migrations/operations/tables.ts
|
|
200
|
-
/**
|
|
201
|
-
* Renders the body of a `CREATE TABLE <name> ( … )` statement from a flat
|
|
202
|
-
* `SqliteTableSpec`. SQLite's `INTEGER PRIMARY KEY AUTOINCREMENT` form is
|
|
203
|
-
* inline on the column; the table-level PRIMARY KEY clause is emitted only
|
|
204
|
-
* when no column carries `inlineAutoincrementPrimaryKey`.
|
|
205
|
-
*/
|
|
206
|
-
function renderCreateTableSql(tableName, spec) {
|
|
207
|
-
const columnDefs = spec.columns.map(renderColumnDefinition);
|
|
208
|
-
const constraintDefs = [];
|
|
209
|
-
const hasInlinePk = spec.columns.some((c) => c.inlineAutoincrementPrimaryKey);
|
|
210
|
-
if (spec.primaryKey && !hasInlinePk) constraintDefs.push(`PRIMARY KEY (${spec.primaryKey.columns.map(quoteIdentifier).join(", ")})`);
|
|
211
|
-
for (const u of spec.uniques ?? []) {
|
|
212
|
-
const name = u.name ? `CONSTRAINT ${quoteIdentifier(u.name)} ` : "";
|
|
213
|
-
constraintDefs.push(`${name}UNIQUE (${u.columns.map(quoteIdentifier).join(", ")})`);
|
|
214
|
-
}
|
|
215
|
-
for (const fk of spec.foreignKeys ?? []) {
|
|
216
|
-
const clause = renderForeignKeyClause(fk);
|
|
217
|
-
if (clause) constraintDefs.push(clause);
|
|
218
|
-
}
|
|
219
|
-
const allDefs = [...columnDefs, ...constraintDefs];
|
|
220
|
-
return `CREATE TABLE ${quoteIdentifier(tableName)} (\n ${allDefs.join(",\n ")}\n)`;
|
|
221
|
-
}
|
|
222
|
-
function createTable(tableName, spec) {
|
|
223
|
-
return {
|
|
224
|
-
id: `table.${tableName}`,
|
|
225
|
-
label: `Create table ${tableName}`,
|
|
226
|
-
summary: `Creates table ${tableName} with required columns`,
|
|
227
|
-
operationClass: "additive",
|
|
228
|
-
target: {
|
|
229
|
-
id: "sqlite",
|
|
230
|
-
details: buildTargetDetails("table", tableName)
|
|
231
|
-
},
|
|
232
|
-
precheck: [step(`ensure table "${tableName}" does not exist`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`)],
|
|
233
|
-
execute: [step(`create table "${tableName}"`, renderCreateTableSql(tableName, spec))],
|
|
234
|
-
postcheck: [step(`verify table "${tableName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`)]
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function dropTable(tableName) {
|
|
238
|
-
return {
|
|
239
|
-
id: `dropTable.${tableName}`,
|
|
240
|
-
label: `Drop table ${tableName}`,
|
|
241
|
-
summary: `Drops table ${tableName} which is not in the contract`,
|
|
242
|
-
operationClass: "destructive",
|
|
243
|
-
target: {
|
|
244
|
-
id: "sqlite",
|
|
245
|
-
details: buildTargetDetails("table", tableName)
|
|
246
|
-
},
|
|
247
|
-
precheck: [step(`ensure table "${tableName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`)],
|
|
248
|
-
execute: [step(`drop table "${tableName}"`, `DROP TABLE ${quoteIdentifier(tableName)}`)],
|
|
249
|
-
postcheck: [step(`verify table "${tableName}" is gone`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`)]
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function recreateTable(args) {
|
|
253
|
-
const { tableName, contractTable, schemaColumnNames, indexes, summary, postchecks, operationClass } = args;
|
|
254
|
-
const tempName = `_prisma_new_${tableName}`;
|
|
255
|
-
const liveSet = new Set(schemaColumnNames);
|
|
256
|
-
const sharedColumns = contractTable.columns.filter((c) => liveSet.has(c.name)).map((c) => c.name);
|
|
257
|
-
const columnList = sharedColumns.map(quoteIdentifier).join(", ");
|
|
258
|
-
const indexStatements = indexes.map((idx) => ({
|
|
259
|
-
description: `recreate index "${idx.name}" on "${tableName}"`,
|
|
260
|
-
sql: buildCreateIndexSql(tableName, idx.name, idx.columns)
|
|
261
|
-
}));
|
|
262
|
-
const copyStep = sharedColumns.length > 0 ? [step(`copy data from "${tableName}" to "${tempName}"`, `INSERT INTO ${quoteIdentifier(tempName)} (${columnList}) SELECT ${columnList} FROM ${quoteIdentifier(tableName)}`)] : [];
|
|
263
|
-
return {
|
|
264
|
-
id: `recreateTable.${tableName}`,
|
|
265
|
-
label: `Recreate table ${tableName}`,
|
|
266
|
-
summary,
|
|
267
|
-
operationClass,
|
|
268
|
-
target: {
|
|
269
|
-
id: "sqlite",
|
|
270
|
-
details: buildTargetDetails("table", tableName)
|
|
271
|
-
},
|
|
272
|
-
precheck: [step(`ensure table "${tableName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`), step(`ensure temp table "${tempName}" does not exist`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tempName)}'`)],
|
|
273
|
-
execute: [
|
|
274
|
-
step(`create new table "${tempName}" with desired schema`, renderCreateTableSql(tempName, contractTable)),
|
|
275
|
-
...copyStep,
|
|
276
|
-
step(`drop old table "${tableName}"`, `DROP TABLE ${quoteIdentifier(tableName)}`),
|
|
277
|
-
step(`rename "${tempName}" to "${tableName}"`, `ALTER TABLE ${quoteIdentifier(tempName)} RENAME TO ${quoteIdentifier(tableName)}`),
|
|
278
|
-
...indexStatements
|
|
279
|
-
],
|
|
280
|
-
postcheck: [
|
|
281
|
-
step(`verify table "${tableName}" exists`, `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`),
|
|
282
|
-
step(`verify temp table "${tempName}" is gone`, `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tempName)}'`),
|
|
283
|
-
...postchecks
|
|
284
|
-
]
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Build a one-line summary of a recreate-table operation from the schema
|
|
289
|
-
* issues that triggered it. Lives next to `recreateTable` so the planner
|
|
290
|
-
* (which has the issues) can produce the same description the factory
|
|
291
|
-
* used to build inline. Keeping the formatting target-side keeps
|
|
292
|
-
* `RecreateTableCall` issue-free at the IR layer.
|
|
293
|
-
*/
|
|
294
|
-
function buildRecreateSummary(tableName, issues) {
|
|
295
|
-
return `Recreates table ${tableName} to apply schema changes: ${issues.map((i) => i.message).join("; ")}`;
|
|
296
|
-
}
|
|
297
|
-
const COLUMN_LEVEL_ISSUE_KINDS = new Set([
|
|
298
|
-
"nullability_mismatch",
|
|
299
|
-
"default_mismatch",
|
|
300
|
-
"default_missing",
|
|
301
|
-
"extra_default",
|
|
302
|
-
"type_mismatch"
|
|
303
|
-
]);
|
|
304
|
-
const PK_ISSUE_KINDS = new Set(["primary_key_mismatch", "extra_primary_key"]);
|
|
305
|
-
const UNIQUE_ISSUE_KINDS = new Set(["unique_constraint_mismatch", "extra_unique_constraint"]);
|
|
306
|
-
const FK_ISSUE_KINDS = new Set(["foreign_key_mismatch", "extra_foreign_key"]);
|
|
307
|
-
/**
|
|
308
|
-
* Returns the columns the contract expects as the table's primary key. Picks
|
|
309
|
-
* up SQLite's inline `INTEGER PRIMARY KEY AUTOINCREMENT` form when no
|
|
310
|
-
* explicit `primaryKey` clause is set on the spec.
|
|
311
|
-
*/
|
|
312
|
-
function expectedPrimaryKeyColumns(spec) {
|
|
313
|
-
if (spec.primaryKey) return spec.primaryKey.columns;
|
|
314
|
-
const inlinePk = spec.columns.find((c) => c.inlineAutoincrementPrimaryKey);
|
|
315
|
-
return inlinePk ? [inlinePk.name] : [];
|
|
316
|
-
}
|
|
317
|
-
function quoteSqlList(values) {
|
|
318
|
-
return values.map((v) => `'${escapeLiteral(v)}'`).join(", ");
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Per-issue postchecks verifying the recreated table's shape against the
|
|
322
|
-
* contract spec. Column-level issues (`nullability_mismatch`,
|
|
323
|
-
* `default_mismatch`, …) emit one targeted check each; constraint-level
|
|
324
|
-
* issues (`primary_key_mismatch`, `unique_constraint_mismatch`,
|
|
325
|
-
* `foreign_key_mismatch`, plus their `extra_*` siblings) emit one
|
|
326
|
-
* `pragma_*`-driven check per declared constraint in the contract spec, so
|
|
327
|
-
* a recreated table with the right columns but the wrong PK / unique / FK
|
|
328
|
-
* shape fails the postcheck instead of passing silently. Exported so the
|
|
329
|
-
* planner can pre-build the list at construction time and
|
|
330
|
-
* `RecreateTableCall` doesn't have to carry `SchemaIssue` objects through
|
|
331
|
-
* to render time.
|
|
332
|
-
*/
|
|
333
|
-
function buildRecreatePostchecks(tableName, issues, spec) {
|
|
334
|
-
const checks = [];
|
|
335
|
-
const t = escapeLiteral(tableName);
|
|
336
|
-
const byName = new Map(spec.columns.map((c) => [c.name, c]));
|
|
337
|
-
for (const issue of issues) {
|
|
338
|
-
if (issue.kind === "enum_values_changed") continue;
|
|
339
|
-
if (!COLUMN_LEVEL_ISSUE_KINDS.has(issue.kind)) continue;
|
|
340
|
-
if (!issue.column) continue;
|
|
341
|
-
const c = escapeLiteral(issue.column);
|
|
342
|
-
if (issue.kind === "nullability_mismatch") {
|
|
343
|
-
let wantNotNull;
|
|
344
|
-
if (issue.expected === "false") wantNotNull = true;
|
|
345
|
-
else if (issue.expected === "true") wantNotNull = false;
|
|
346
|
-
if (wantNotNull !== void 0) checks.push({
|
|
347
|
-
description: `verify "${issue.column}" nullability on "${tableName}"`,
|
|
348
|
-
sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND "notnull" = ${wantNotNull ? 1 : 0}`
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
if (issue.kind === "default_mismatch" || issue.kind === "default_missing") {
|
|
352
|
-
const colSpec = byName.get(issue.column);
|
|
353
|
-
const expectedRaw = colSpec?.defaultSql.startsWith("DEFAULT ") ? stripOuterParens(colSpec.defaultSql.slice(8)) : null;
|
|
354
|
-
if (expectedRaw) checks.push({
|
|
355
|
-
description: `verify "${issue.column}" default on "${tableName}"`,
|
|
356
|
-
sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value = '${escapeLiteral(expectedRaw)}'`
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
if (issue.kind === "type_mismatch") {
|
|
360
|
-
const colSpec = byName.get(issue.column);
|
|
361
|
-
if (colSpec) checks.push({
|
|
362
|
-
description: `verify "${issue.column}" type on "${tableName}"`,
|
|
363
|
-
sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND LOWER(type) = '${escapeLiteral(colSpec.typeSql.toLowerCase())}'`
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
if (issue.kind === "extra_default") checks.push({
|
|
367
|
-
description: `verify "${issue.column}" has no default on "${tableName}"`,
|
|
368
|
-
sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value IS NULL`
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
const hasPkIssue = issues.some((i) => PK_ISSUE_KINDS.has(i.kind));
|
|
372
|
-
const hasUniqueIssue = issues.some((i) => UNIQUE_ISSUE_KINDS.has(i.kind));
|
|
373
|
-
const hasFkIssue = issues.some((i) => FK_ISSUE_KINDS.has(i.kind));
|
|
374
|
-
if (hasPkIssue) {
|
|
375
|
-
const pkColumns = expectedPrimaryKeyColumns(spec);
|
|
376
|
-
const colCount = pkColumns.length;
|
|
377
|
-
if (colCount === 0) checks.push({
|
|
378
|
-
description: `verify "${tableName}" has no primary key`,
|
|
379
|
-
sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = 0`
|
|
380
|
-
});
|
|
381
|
-
else checks.push({
|
|
382
|
-
description: `verify primary key on "${tableName}"`,
|
|
383
|
-
sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = ${colCount} AND (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0 AND name IN (${quoteSqlList(pkColumns)})) = ${colCount}`
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
if (hasUniqueIssue) for (const u of spec.uniques ?? []) {
|
|
387
|
-
const colCount = u.columns.length;
|
|
388
|
-
const description = u.name ? `verify unique constraint "${u.name}" on "${tableName}"` : `verify unique constraint (${u.columns.join(", ")}) on "${tableName}"`;
|
|
389
|
-
checks.push({
|
|
390
|
-
description,
|
|
391
|
-
sql: `SELECT EXISTS (SELECT 1 FROM pragma_index_list('${t}') l WHERE l."unique" = 1 AND (SELECT COUNT(*) FROM pragma_index_info(l.name)) = ${colCount} AND (SELECT COUNT(*) FROM pragma_index_info(l.name) WHERE name IN (${quoteSqlList(u.columns)})) = ${colCount})`
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
if (hasFkIssue) for (const fk of spec.foreignKeys ?? []) {
|
|
395
|
-
const refTable = escapeLiteral(fk.references.table);
|
|
396
|
-
const colCount = fk.columns.length;
|
|
397
|
-
const tuples = fk.columns.map((from, i) => {
|
|
398
|
-
const to = fk.references.columns[i] ?? from;
|
|
399
|
-
return `('${escapeLiteral(from)}', '${escapeLiteral(to)}')`;
|
|
400
|
-
}).join(", ");
|
|
401
|
-
const description = `verify foreign key (${fk.columns.join(", ")}) → ${fk.references.table}(${fk.references.columns.join(", ")}) on "${tableName}"`;
|
|
402
|
-
checks.push({
|
|
403
|
-
description,
|
|
404
|
-
sql: `SELECT EXISTS (SELECT 1 FROM pragma_foreign_key_list('${t}') f WHERE f."table" = '${refTable}' GROUP BY f.id HAVING COUNT(*) = ${colCount} AND SUM(CASE WHEN (f."from", f."to") IN (${tuples}) THEN 1 ELSE 0 END) = ${colCount})`
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
return checks;
|
|
408
|
-
}
|
|
409
|
-
//#endregion
|
|
410
|
-
export { recreateTable as a, buildColumnDefaultSql as c, renderDefaultLiteral as d, addColumn as f, dropTable as i, buildColumnTypeSql as l, step as m, buildRecreateSummary as n, createIndex as o, dropColumn as p, createTable as r, dropIndex as s, buildRecreatePostchecks as t, isInlineAutoincrementPrimaryKey as u };
|
|
411
|
-
|
|
412
|
-
//# sourceMappingURL=tables-CjB7vXCr.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tables-CjB7vXCr.mjs","names":[],"sources":["../src/core/migrations/operations/shared.ts","../src/core/migrations/operations/columns.ts","../src/core/migrations/planner-ddl-builders.ts","../src/core/migrations/operations/indexes.ts","../src/core/migrations/operations/tables.ts"],"sourcesContent":["import type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport { REFERENTIAL_ACTION_SQL } from '@prisma-next/sql-contract/referential-action-sql';\nimport type { ReferentialAction } from '@prisma-next/sql-contract/types';\nimport { quoteIdentifier } from '../../sql-utils';\nimport type { SqlitePlanTargetDetails } from '../planner-target-details';\n\nexport type Op = SqlMigrationPlanOperation<SqlitePlanTargetDetails>;\n\nexport function step(description: string, sql: string): { description: string; sql: string } {\n return { description, sql };\n}\n\n/**\n * Flat, fully-resolved column shape consumed by `createTable`, `addColumn`,\n * and `recreateTable`. Codec / `typeRef` / default expansion happens at the\n * call-construction site (in the issue-planner / strategies) so the\n * operation factories deal only in pre-rendered SQL fragments — mirrors the\n * Postgres `ColumnSpec` pattern.\n *\n * - `typeSql` is the column's DDL type token (e.g. `\"INTEGER\"`, `\"TEXT\"`).\n * - `defaultSql` is the full `DEFAULT …` clause (or empty when there is no\n * default and when the column is rendered as `INTEGER PRIMARY KEY\n * AUTOINCREMENT`, since SQLite forbids a default on an autoincrement PK).\n * - `inlineAutoincrementPrimaryKey` directs the renderer to emit\n * `INTEGER PRIMARY KEY AUTOINCREMENT` inline and to skip the table-level\n * primary-key constraint for this column. SQLite-specific: the column\n * becomes an alias for `rowid` only when this exact form is used.\n */\nexport interface SqliteColumnSpec {\n readonly name: string;\n readonly typeSql: string;\n readonly defaultSql: string;\n readonly nullable: boolean;\n readonly inlineAutoincrementPrimaryKey?: boolean;\n}\n\nexport interface SqlitePrimaryKeySpec {\n readonly columns: readonly string[];\n}\n\nexport interface SqliteUniqueSpec {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\nexport interface SqliteForeignKeySpec {\n readonly columns: readonly string[];\n readonly references: {\n readonly table: string;\n readonly columns: readonly string[];\n };\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly constraint: boolean;\n}\n\n/**\n * Flat shape of a contract table for DDL emission. Used by both\n * `createTable` (additive) and `recreateTable` (widening/destructive).\n */\nexport interface SqliteTableSpec {\n readonly columns: readonly SqliteColumnSpec[];\n readonly primaryKey?: SqlitePrimaryKeySpec;\n readonly uniques?: readonly SqliteUniqueSpec[];\n readonly foreignKeys?: readonly SqliteForeignKeySpec[];\n}\n\n/**\n * Index recreation spec for `recreateTable`. Both declared indexes and\n * FK-backing indexes flatten to the same shape; the planner dedupes by\n * column-set before constructing the call.\n */\nexport interface SqliteIndexSpec {\n readonly name: string;\n readonly columns: readonly string[];\n}\n\n/**\n * Renders a single column's inline DDL fragment within a `CREATE TABLE`\n * statement. Honours the `inlineAutoincrementPrimaryKey` flag — SQLite\n * treats `INTEGER PRIMARY KEY AUTOINCREMENT` as a special form that aliases\n * `rowid`, and the column must not carry a `DEFAULT` or repeat `NOT NULL`.\n */\nexport function renderColumnDefinition(column: SqliteColumnSpec): string {\n const parts: string[] = [quoteIdentifier(column.name), column.typeSql];\n if (column.inlineAutoincrementPrimaryKey) {\n parts.push('PRIMARY KEY AUTOINCREMENT');\n } else {\n if (column.defaultSql) parts.push(column.defaultSql);\n if (!column.nullable) parts.push('NOT NULL');\n }\n return parts.join(' ');\n}\n\n/**\n * Renders an inline FOREIGN KEY constraint clause for a `CREATE TABLE`\n * body. Returns the empty string when `constraint` is false (the FK is\n * tracked at the contract level for index-creation purposes only and must\n * not produce DDL).\n */\nexport function renderForeignKeyClause(fk: SqliteForeignKeySpec): string {\n if (!fk.constraint) return '';\n const name = fk.name ? `CONSTRAINT ${quoteIdentifier(fk.name)} ` : '';\n let sql = `${name}FOREIGN KEY (${fk.columns.map(quoteIdentifier).join(', ')}) REFERENCES ${quoteIdentifier(fk.references.table)} (${fk.references.columns.map(quoteIdentifier).join(', ')})`;\n if (fk.onDelete !== undefined) {\n sql += ` ON DELETE ${REFERENTIAL_ACTION_SQL[fk.onDelete]}`;\n }\n if (fk.onUpdate !== undefined) {\n sql += ` ON UPDATE ${REFERENTIAL_ACTION_SQL[fk.onUpdate]}`;\n }\n return sql;\n}\n","import { escapeLiteral, quoteIdentifier } from '../../sql-utils';\nimport { buildTargetDetails } from '../planner-target-details';\nimport { type Op, type SqliteColumnSpec, step } from './shared';\n\nexport function addColumn(tableName: string, column: SqliteColumnSpec): Op {\n const parts = [\n `ALTER TABLE ${quoteIdentifier(tableName)}`,\n `ADD COLUMN ${quoteIdentifier(column.name)} ${column.typeSql}`,\n column.defaultSql,\n column.nullable ? '' : 'NOT NULL',\n ].filter(Boolean);\n const addSql = parts.join(' ');\n\n return {\n id: `column.${tableName}.${column.name}`,\n label: `Add column ${column.name} on ${tableName}`,\n summary: `Adds column ${column.name} on ${tableName}`,\n operationClass: 'additive',\n target: { id: 'sqlite', details: buildTargetDetails('column', column.name, tableName) },\n precheck: [\n step(\n `ensure column \"${column.name}\" is missing`,\n `SELECT COUNT(*) = 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(column.name)}'`,\n ),\n ],\n execute: [step(`add column \"${column.name}\"`, addSql)],\n postcheck: [\n step(\n `verify column \"${column.name}\" exists`,\n `SELECT COUNT(*) > 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(column.name)}'`,\n ),\n ],\n };\n}\n\nexport function dropColumn(tableName: string, columnName: string): Op {\n return {\n id: `dropColumn.${tableName}.${columnName}`,\n label: `Drop column ${columnName} on ${tableName}`,\n summary: `Drops column ${columnName} on ${tableName} which is not in the contract`,\n operationClass: 'destructive',\n target: { id: 'sqlite', details: buildTargetDetails('column', columnName, tableName) },\n precheck: [\n step(\n `ensure column \"${columnName}\" exists on \"${tableName}\"`,\n `SELECT COUNT(*) > 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(columnName)}'`,\n ),\n ],\n execute: [\n step(\n `drop column \"${columnName}\" from \"${tableName}\"`,\n `ALTER TABLE ${quoteIdentifier(tableName)} DROP COLUMN ${quoteIdentifier(columnName)}`,\n ),\n ],\n postcheck: [\n step(\n `verify column \"${columnName}\" is gone from \"${tableName}\"`,\n `SELECT COUNT(*) = 0 FROM pragma_table_info('${escapeLiteral(tableName)}') WHERE name = '${escapeLiteral(columnName)}'`,\n ),\n ],\n };\n}\n","/**\n * Low-level DDL fragment builders for SQLite migrations.\n *\n * These helpers consume `StorageColumn` (the contract shape, possibly with\n * `typeRef`) and produce string fragments. They are called once per column\n * at the call-construction boundary in `issue-planner.ts` / strategies to\n * build flat `SqliteColumnSpec`s; the operation factories themselves never\n * see `StorageColumn` or `storageTypes`.\n */\n\nimport {\n isPostgresEnumStorageEntry,\n type PostgresEnumStorageEntry,\n type StorageColumn,\n type StorageTable,\n type StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { escapeLiteral, quoteIdentifier } from '../sql-utils';\n\ntype SqliteColumnDefault = StorageColumn['default'];\n\nconst SAFE_NATIVE_TYPE_PATTERN = /^[a-zA-Z][a-zA-Z0-9_ ]*$/;\n\nfunction assertSafeNativeType(nativeType: string): void {\n if (!SAFE_NATIVE_TYPE_PATTERN.test(nativeType)) {\n throw new Error(\n `Unsafe native type name in contract: \"${nativeType}\". ` +\n 'Native type names must match /^[a-zA-Z][a-zA-Z0-9_ ]*$/',\n );\n }\n}\n\nfunction assertSafeDefaultExpression(expression: string): void {\n if (expression.includes(';') || /--|\\/\\*|\\bSELECT\\b/i.test(expression)) {\n throw new Error(\n `Unsafe default expression in contract: \"${expression}\". ` +\n 'Default expressions must not contain semicolons, SQL comment tokens, or subqueries.',\n );\n }\n}\n\n/**\n * Renders the column's DDL type token (e.g. `\"INTEGER\"`, `\"TEXT\"`).\n * Resolves `typeRef` against `storageTypes` and validates the resulting\n * native type against a safe-identifier pattern.\n */\nexport function buildColumnTypeSql(\n column: StorageColumn,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry> = {},\n): string {\n const resolved = resolveColumnTypeMetadata(column, storageTypes);\n assertSafeNativeType(resolved.nativeType);\n return resolved.nativeType.toUpperCase();\n}\n\n/**\n * Renders the column's `DEFAULT …` clause. Returns the empty string when\n * there is no default, and also when the default is `autoincrement()` —\n * SQLite encodes that as `INTEGER PRIMARY KEY AUTOINCREMENT` inline on the\n * column definition, not as a separate DEFAULT.\n */\nexport function buildColumnDefaultSql(columnDefault: SqliteColumnDefault | undefined): string {\n if (!columnDefault) return '';\n\n switch (columnDefault.kind) {\n case 'literal':\n return `DEFAULT ${renderDefaultLiteral(columnDefault.value)}`;\n case 'function': {\n if (columnDefault.expression === 'autoincrement()') return '';\n if (columnDefault.expression === 'now()') return \"DEFAULT (datetime('now'))\";\n assertSafeDefaultExpression(columnDefault.expression);\n return `DEFAULT (${columnDefault.expression})`;\n }\n }\n}\n\nexport function renderDefaultLiteral(value: unknown): string {\n if (value instanceof Date) {\n return `'${escapeLiteral(value.toISOString())}'`;\n }\n if (typeof value === 'string') {\n return `'${escapeLiteral(value)}'`;\n }\n if (typeof value === 'number' || typeof value === 'bigint') {\n return String(value);\n }\n if (typeof value === 'boolean') {\n return value ? '1' : '0';\n }\n if (value === null) {\n return 'NULL';\n }\n return `'${escapeLiteral(JSON.stringify(value))}'`;\n}\n\nexport function buildCreateIndexSql(\n tableName: string,\n indexName: string,\n columns: readonly string[],\n unique = false,\n): string {\n const uniqueKeyword = unique ? 'UNIQUE ' : '';\n return `CREATE ${uniqueKeyword}INDEX ${quoteIdentifier(indexName)} ON ${quoteIdentifier(tableName)} (${columns.map(quoteIdentifier).join(', ')})`;\n}\n\nexport function buildDropIndexSql(indexName: string): string {\n return `DROP INDEX IF EXISTS ${quoteIdentifier(indexName)}`;\n}\n\n/**\n * True when the column is rendered inline as `INTEGER PRIMARY KEY\n * AUTOINCREMENT`. Requires the column's default to be `autoincrement()` and\n * the column to be the sole member of the table's primary key — anything\n * else falls back to a separate PRIMARY KEY constraint with a default\n * AUTOINCREMENT semantics expressed elsewhere.\n */\nexport function isInlineAutoincrementPrimaryKey(table: StorageTable, columnName: string): boolean {\n if (table.primaryKey?.columns.length !== 1) return false;\n if (table.primaryKey.columns[0] !== columnName) return false;\n const column = table.columns[columnName];\n return column?.default?.kind === 'function' && column.default.expression === 'autoincrement()';\n}\n\ntype ResolvedColumnTypeMetadata = Pick<StorageColumn, 'nativeType' | 'codecId' | 'typeParams'>;\n\nfunction resolveColumnTypeMetadata(\n column: StorageColumn,\n storageTypes: Record<string, StorageTypeInstance | PostgresEnumStorageEntry>,\n): ResolvedColumnTypeMetadata {\n if (!column.typeRef) {\n return column;\n }\n const referencedType = storageTypes[column.typeRef];\n if (!referencedType) {\n throw new Error(\n `Storage type \"${column.typeRef}\" referenced by column is not defined in storage.types.`,\n );\n }\n if (isPostgresEnumStorageEntry(referencedType)) {\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: { values: referencedType.values } as Record<string, unknown>,\n };\n }\n return {\n codecId: referencedType.codecId,\n nativeType: referencedType.nativeType,\n typeParams: referencedType.typeParams,\n };\n}\n","import { escapeLiteral } from '../../sql-utils';\nimport { buildCreateIndexSql, buildDropIndexSql } from '../planner-ddl-builders';\nimport { buildTargetDetails } from '../planner-target-details';\nimport { type Op, step } from './shared';\n\nexport function createIndex(tableName: string, indexName: string, columns: readonly string[]): Op {\n return {\n id: `index.${tableName}.${indexName}`,\n label: `Create index ${indexName} on ${tableName}`,\n summary: `Creates index ${indexName} on ${tableName}`,\n operationClass: 'additive',\n target: { id: 'sqlite', details: buildTargetDetails('index', indexName, tableName) },\n precheck: [\n step(\n `ensure index \"${indexName}\" is missing`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`,\n ),\n ],\n execute: [\n step(`create index \"${indexName}\"`, buildCreateIndexSql(tableName, indexName, columns)),\n ],\n postcheck: [\n step(\n `verify index \"${indexName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`,\n ),\n ],\n };\n}\n\nexport function dropIndex(tableName: string, indexName: string): Op {\n return {\n id: `dropIndex.${tableName}.${indexName}`,\n label: `Drop index ${indexName} on ${tableName}`,\n summary: `Drops index ${indexName} on ${tableName} which is not in the contract`,\n operationClass: 'destructive',\n target: { id: 'sqlite', details: buildTargetDetails('index', indexName, tableName) },\n precheck: [\n step(\n `ensure index \"${indexName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`,\n ),\n ],\n execute: [step(`drop index \"${indexName}\"`, buildDropIndexSql(indexName))],\n postcheck: [\n step(\n `verify index \"${indexName}\" is gone`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'index' AND name = '${escapeLiteral(indexName)}'`,\n ),\n ],\n };\n}\n","import type { MigrationOperationClass } from '@prisma-next/family-sql/control';\nimport type { SchemaIssue } from '@prisma-next/framework-components/control';\nimport { stripOuterParens } from '../../default-normalizer';\nimport { escapeLiteral, quoteIdentifier } from '../../sql-utils';\nimport { buildCreateIndexSql } from '../planner-ddl-builders';\nimport { buildTargetDetails } from '../planner-target-details';\nimport {\n type Op,\n renderColumnDefinition,\n renderForeignKeyClause,\n type SqliteIndexSpec,\n type SqliteTableSpec,\n step,\n} from './shared';\n\n/**\n * Renders the body of a `CREATE TABLE <name> ( … )` statement from a flat\n * `SqliteTableSpec`. SQLite's `INTEGER PRIMARY KEY AUTOINCREMENT` form is\n * inline on the column; the table-level PRIMARY KEY clause is emitted only\n * when no column carries `inlineAutoincrementPrimaryKey`.\n */\nfunction renderCreateTableSql(tableName: string, spec: SqliteTableSpec): string {\n const columnDefs = spec.columns.map(renderColumnDefinition);\n\n const constraintDefs: string[] = [];\n const hasInlinePk = spec.columns.some((c) => c.inlineAutoincrementPrimaryKey);\n if (spec.primaryKey && !hasInlinePk) {\n constraintDefs.push(`PRIMARY KEY (${spec.primaryKey.columns.map(quoteIdentifier).join(', ')})`);\n }\n\n for (const u of spec.uniques ?? []) {\n const name = u.name ? `CONSTRAINT ${quoteIdentifier(u.name)} ` : '';\n constraintDefs.push(`${name}UNIQUE (${u.columns.map(quoteIdentifier).join(', ')})`);\n }\n\n for (const fk of spec.foreignKeys ?? []) {\n const clause = renderForeignKeyClause(fk);\n if (clause) constraintDefs.push(clause);\n }\n\n const allDefs = [...columnDefs, ...constraintDefs];\n return `CREATE TABLE ${quoteIdentifier(tableName)} (\\n ${allDefs.join(',\\n ')}\\n)`;\n}\n\nexport function createTable(tableName: string, spec: SqliteTableSpec): Op {\n return {\n id: `table.${tableName}`,\n label: `Create table ${tableName}`,\n summary: `Creates table ${tableName} with required columns`,\n operationClass: 'additive',\n target: { id: 'sqlite', details: buildTargetDetails('table', tableName) },\n precheck: [\n step(\n `ensure table \"${tableName}\" does not exist`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n ],\n execute: [step(`create table \"${tableName}\"`, renderCreateTableSql(tableName, spec))],\n postcheck: [\n step(\n `verify table \"${tableName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n ],\n };\n}\n\nexport function dropTable(tableName: string): Op {\n return {\n id: `dropTable.${tableName}`,\n label: `Drop table ${tableName}`,\n summary: `Drops table ${tableName} which is not in the contract`,\n operationClass: 'destructive',\n target: { id: 'sqlite', details: buildTargetDetails('table', tableName) },\n precheck: [\n step(\n `ensure table \"${tableName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n ],\n execute: [step(`drop table \"${tableName}\"`, `DROP TABLE ${quoteIdentifier(tableName)}`)],\n postcheck: [\n step(\n `verify table \"${tableName}\" is gone`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n ],\n };\n}\n\nexport interface RecreateTableArgs {\n readonly tableName: string;\n /** New (post-recreate) shape of the table. Same flat spec as `createTable`. */\n readonly contractTable: SqliteTableSpec;\n /**\n * Names of columns that exist in the live (pre-recreate) schema. Used to\n * compute the `INSERT INTO temp ... SELECT ... FROM old` column list — only\n * shared columns are copied, so dropped columns are left behind and added\n * columns come from defaults.\n */\n readonly schemaColumnNames: readonly string[];\n /**\n * Indexes (declared + FK-backing, deduped by column-set) to recreate after\n * the table has been replaced. The planner pre-merges these.\n */\n readonly indexes: readonly SqliteIndexSpec[];\n /** Human-readable summary of the change, built by the planner from issues. */\n readonly summary: string;\n /**\n * Per-issue postcheck steps appended after the structural postchecks. The\n * planner pre-builds these via `buildRecreatePostchecks` so the call IR\n * carries flat, serializable data only — no `SchemaIssue` references.\n */\n readonly postchecks: readonly { readonly description: string; readonly sql: string }[];\n readonly operationClass: MigrationOperationClass;\n}\n\nexport function recreateTable(args: RecreateTableArgs): Op {\n const {\n tableName,\n contractTable,\n schemaColumnNames,\n indexes,\n summary,\n postchecks,\n operationClass,\n } = args;\n const tempName = `_prisma_new_${tableName}`;\n const liveSet = new Set(schemaColumnNames);\n const sharedColumns = contractTable.columns.filter((c) => liveSet.has(c.name)).map((c) => c.name);\n const columnList = sharedColumns.map(quoteIdentifier).join(', ');\n\n const indexStatements = indexes.map((idx) => ({\n description: `recreate index \"${idx.name}\" on \"${tableName}\"`,\n sql: buildCreateIndexSql(tableName, idx.name, idx.columns),\n }));\n\n // If the contract retains no columns from the live table, an `INSERT INTO\n // tmp () SELECT FROM old` is invalid SQL — and would also be a no-op since\n // there's nothing to copy. Skip the copy step in that case; the new\n // (empty) table replaces the old one directly.\n const copyStep =\n sharedColumns.length > 0\n ? [\n step(\n `copy data from \"${tableName}\" to \"${tempName}\"`,\n `INSERT INTO ${quoteIdentifier(tempName)} (${columnList}) SELECT ${columnList} FROM ${quoteIdentifier(tableName)}`,\n ),\n ]\n : [];\n\n return {\n id: `recreateTable.${tableName}`,\n label: `Recreate table ${tableName}`,\n summary,\n operationClass,\n target: { id: 'sqlite', details: buildTargetDetails('table', tableName) },\n precheck: [\n step(\n `ensure table \"${tableName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n step(\n `ensure temp table \"${tempName}\" does not exist`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tempName)}'`,\n ),\n ],\n execute: [\n step(\n `create new table \"${tempName}\" with desired schema`,\n renderCreateTableSql(tempName, contractTable),\n ),\n ...copyStep,\n step(`drop old table \"${tableName}\"`, `DROP TABLE ${quoteIdentifier(tableName)}`),\n step(\n `rename \"${tempName}\" to \"${tableName}\"`,\n `ALTER TABLE ${quoteIdentifier(tempName)} RENAME TO ${quoteIdentifier(tableName)}`,\n ),\n ...indexStatements,\n ],\n postcheck: [\n step(\n `verify table \"${tableName}\" exists`,\n `SELECT COUNT(*) > 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tableName)}'`,\n ),\n step(\n `verify temp table \"${tempName}\" is gone`,\n `SELECT COUNT(*) = 0 FROM sqlite_master WHERE type = 'table' AND name = '${escapeLiteral(tempName)}'`,\n ),\n ...postchecks,\n ],\n };\n}\n\n/**\n * Build a one-line summary of a recreate-table operation from the schema\n * issues that triggered it. Lives next to `recreateTable` so the planner\n * (which has the issues) can produce the same description the factory\n * used to build inline. Keeping the formatting target-side keeps\n * `RecreateTableCall` issue-free at the IR layer.\n */\nexport function buildRecreateSummary(tableName: string, issues: readonly SchemaIssue[]): string {\n const messages = issues.map((i) => i.message).join('; ');\n return `Recreates table ${tableName} to apply schema changes: ${messages}`;\n}\n\nconst COLUMN_LEVEL_ISSUE_KINDS = new Set<SchemaIssue['kind']>([\n 'nullability_mismatch',\n 'default_mismatch',\n 'default_missing',\n 'extra_default',\n 'type_mismatch',\n]);\n\nconst PK_ISSUE_KINDS = new Set<SchemaIssue['kind']>(['primary_key_mismatch', 'extra_primary_key']);\n\nconst UNIQUE_ISSUE_KINDS = new Set<SchemaIssue['kind']>([\n 'unique_constraint_mismatch',\n 'extra_unique_constraint',\n]);\n\nconst FK_ISSUE_KINDS = new Set<SchemaIssue['kind']>(['foreign_key_mismatch', 'extra_foreign_key']);\n\n/**\n * Returns the columns the contract expects as the table's primary key. Picks\n * up SQLite's inline `INTEGER PRIMARY KEY AUTOINCREMENT` form when no\n * explicit `primaryKey` clause is set on the spec.\n */\nfunction expectedPrimaryKeyColumns(spec: SqliteTableSpec): readonly string[] {\n if (spec.primaryKey) return spec.primaryKey.columns;\n const inlinePk = spec.columns.find((c) => c.inlineAutoincrementPrimaryKey);\n return inlinePk ? [inlinePk.name] : [];\n}\n\nfunction quoteSqlList(values: readonly string[]): string {\n return values.map((v) => `'${escapeLiteral(v)}'`).join(', ');\n}\n\n/**\n * Per-issue postchecks verifying the recreated table's shape against the\n * contract spec. Column-level issues (`nullability_mismatch`,\n * `default_mismatch`, …) emit one targeted check each; constraint-level\n * issues (`primary_key_mismatch`, `unique_constraint_mismatch`,\n * `foreign_key_mismatch`, plus their `extra_*` siblings) emit one\n * `pragma_*`-driven check per declared constraint in the contract spec, so\n * a recreated table with the right columns but the wrong PK / unique / FK\n * shape fails the postcheck instead of passing silently. Exported so the\n * planner can pre-build the list at construction time and\n * `RecreateTableCall` doesn't have to carry `SchemaIssue` objects through\n * to render time.\n */\nexport function buildRecreatePostchecks(\n tableName: string,\n issues: readonly SchemaIssue[],\n spec: SqliteTableSpec,\n): Array<{ description: string; sql: string }> {\n const checks: Array<{ description: string; sql: string }> = [];\n const t = escapeLiteral(tableName);\n const byName = new Map(spec.columns.map((c) => [c.name, c]));\n\n for (const issue of issues) {\n if (issue.kind === 'enum_values_changed') continue;\n if (!COLUMN_LEVEL_ISSUE_KINDS.has(issue.kind)) continue;\n if (!issue.column) continue;\n const c = escapeLiteral(issue.column);\n if (issue.kind === 'nullability_mismatch') {\n // `expected` carries the contract's nullable flag as a string. We only\n // emit a postcheck when the value is recognized — anything else\n // (case-folded, numeric coding, etc.) is left to the structural\n // verifier so a typo here can't silently invert the meaning.\n let wantNotNull: boolean | undefined;\n if (issue.expected === 'false') wantNotNull = true;\n else if (issue.expected === 'true') wantNotNull = false;\n if (wantNotNull !== undefined) {\n checks.push({\n description: `verify \"${issue.column}\" nullability on \"${tableName}\"`,\n sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND \"notnull\" = ${wantNotNull ? 1 : 0}`,\n });\n }\n }\n if (issue.kind === 'default_mismatch' || issue.kind === 'default_missing') {\n const colSpec = byName.get(issue.column);\n const expectedRaw = colSpec?.defaultSql.startsWith('DEFAULT ')\n ? // SQLite's pragma_table_info.dflt_value strips outer parens for\n // expression defaults (per the SQLite docs), so `(datetime('now'))`\n // is stored as `datetime('now')`. Strip them here so the postcheck\n // matches.\n stripOuterParens(colSpec.defaultSql.slice('DEFAULT '.length))\n : null;\n if (expectedRaw) {\n checks.push({\n description: `verify \"${issue.column}\" default on \"${tableName}\"`,\n sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value = '${escapeLiteral(expectedRaw)}'`,\n });\n }\n }\n if (issue.kind === 'type_mismatch') {\n const colSpec = byName.get(issue.column);\n if (colSpec) {\n checks.push({\n description: `verify \"${issue.column}\" type on \"${tableName}\"`,\n sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND LOWER(type) = '${escapeLiteral(colSpec.typeSql.toLowerCase())}'`,\n });\n }\n }\n if (issue.kind === 'extra_default') {\n checks.push({\n description: `verify \"${issue.column}\" has no default on \"${tableName}\"`,\n sql: `SELECT COUNT(*) > 0 FROM pragma_table_info('${t}') WHERE name = '${c}' AND dflt_value IS NULL`,\n });\n }\n }\n\n // Constraint-level issues — emit one postcheck per declared constraint in\n // the contract spec when *any* issue of that kind fires, since recreate\n // rebuilds the entire table at once.\n const hasPkIssue = issues.some((i) => PK_ISSUE_KINDS.has(i.kind));\n const hasUniqueIssue = issues.some((i) => UNIQUE_ISSUE_KINDS.has(i.kind));\n const hasFkIssue = issues.some((i) => FK_ISSUE_KINDS.has(i.kind));\n\n if (hasPkIssue) {\n const pkColumns = expectedPrimaryKeyColumns(spec);\n // Verify pragma_table_info reports exactly these columns as PK members\n // (count + named membership); zero columns expected ⇒ no PK at all.\n const colCount = pkColumns.length;\n if (colCount === 0) {\n checks.push({\n description: `verify \"${tableName}\" has no primary key`,\n sql: `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = 0`,\n });\n } else {\n checks.push({\n description: `verify primary key on \"${tableName}\"`,\n sql:\n `SELECT (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0) = ${colCount}` +\n ` AND (SELECT COUNT(*) FROM pragma_table_info('${t}') WHERE pk > 0 AND name IN (${quoteSqlList(pkColumns)})) = ${colCount}`,\n });\n }\n }\n\n if (hasUniqueIssue) {\n for (const u of spec.uniques ?? []) {\n const colCount = u.columns.length;\n const description = u.name\n ? `verify unique constraint \"${u.name}\" on \"${tableName}\"`\n : `verify unique constraint (${u.columns.join(', ')}) on \"${tableName}\"`;\n // Match any unique index whose covered columns are exactly the expected\n // set. Order is intentionally not checked — SQLite's unique-index\n // identity is column-set, not column-sequence.\n checks.push({\n description,\n sql:\n `SELECT EXISTS (SELECT 1 FROM pragma_index_list('${t}') l` +\n ` WHERE l.\"unique\" = 1` +\n ` AND (SELECT COUNT(*) FROM pragma_index_info(l.name)) = ${colCount}` +\n ` AND (SELECT COUNT(*) FROM pragma_index_info(l.name) WHERE name IN (${quoteSqlList(u.columns)})) = ${colCount})`,\n });\n }\n }\n\n if (hasFkIssue) {\n for (const fk of spec.foreignKeys ?? []) {\n const refTable = escapeLiteral(fk.references.table);\n const colCount = fk.columns.length;\n // Build a `SUM(CASE WHEN (\"from\",\"to\") IN ((…)) …)` so the check works\n // for both single- and multi-column FKs without depending on FK row\n // ordering inside `pragma_foreign_key_list`.\n const tuples = fk.columns\n .map((from, i) => {\n const to = fk.references.columns[i] ?? from;\n return `('${escapeLiteral(from)}', '${escapeLiteral(to)}')`;\n })\n .join(', ');\n const description = `verify foreign key (${fk.columns.join(', ')}) → ${fk.references.table}(${fk.references.columns.join(', ')}) on \"${tableName}\"`;\n checks.push({\n description,\n sql:\n `SELECT EXISTS (SELECT 1 FROM pragma_foreign_key_list('${t}') f` +\n ` WHERE f.\"table\" = '${refTable}'` +\n ' GROUP BY f.id' +\n ` HAVING COUNT(*) = ${colCount}` +\n ` AND SUM(CASE WHEN (f.\"from\", f.\"to\") IN (${tuples}) THEN 1 ELSE 0 END) = ${colCount})`,\n });\n }\n }\n\n return checks;\n}\n"],"mappings":";;;;;;AAQA,SAAgB,KAAK,aAAqB,KAAmD;CAC3F,OAAO;EAAE;EAAa;CAAI;AAC5B;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