@fragno-dev/db 0.1.3 → 0.1.6

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.
Files changed (62) hide show
  1. package/.turbo/turbo-build.log +43 -30
  2. package/CHANGELOG.md +19 -0
  3. package/dist/adapters/adapters.js +1 -0
  4. package/dist/adapters/drizzle/drizzle-adapter.d.ts +1 -1
  5. package/dist/adapters/drizzle/drizzle-adapter.d.ts.map +1 -1
  6. package/dist/adapters/drizzle/drizzle-adapter.js +9 -2
  7. package/dist/adapters/drizzle/drizzle-adapter.js.map +1 -1
  8. package/dist/adapters/drizzle/generate.js +1 -1
  9. package/dist/adapters/drizzle/generate.js.map +1 -1
  10. package/dist/adapters/kysely/kysely-adapter.d.ts +1 -1
  11. package/dist/adapters/kysely/kysely-adapter.d.ts.map +1 -1
  12. package/dist/adapters/kysely/kysely-adapter.js +47 -27
  13. package/dist/adapters/kysely/kysely-adapter.js.map +1 -1
  14. package/dist/adapters/kysely/kysely-query-compiler.js +2 -2
  15. package/dist/adapters/kysely/kysely-query-compiler.js.map +1 -1
  16. package/dist/adapters/kysely/kysely-query.js +2 -1
  17. package/dist/adapters/kysely/kysely-query.js.map +1 -1
  18. package/dist/adapters/kysely/kysely-uow-compiler.js +2 -2
  19. package/dist/adapters/kysely/kysely-uow-compiler.js.map +1 -1
  20. package/dist/adapters/kysely/migration/execute-base.js +128 -0
  21. package/dist/adapters/kysely/migration/execute-base.js.map +1 -0
  22. package/dist/adapters/kysely/migration/execute-factory.js +28 -0
  23. package/dist/adapters/kysely/migration/execute-factory.js.map +1 -0
  24. package/dist/adapters/kysely/migration/execute-mssql.js +112 -0
  25. package/dist/adapters/kysely/migration/execute-mssql.js.map +1 -0
  26. package/dist/adapters/kysely/migration/execute-mysql.js +93 -0
  27. package/dist/adapters/kysely/migration/execute-mysql.js.map +1 -0
  28. package/dist/adapters/kysely/migration/execute-postgres.js +104 -0
  29. package/dist/adapters/kysely/migration/execute-postgres.js.map +1 -0
  30. package/dist/adapters/kysely/migration/execute-sqlite.js +123 -0
  31. package/dist/adapters/kysely/migration/execute-sqlite.js.map +1 -0
  32. package/dist/adapters/kysely/migration/execute.js +23 -168
  33. package/dist/adapters/kysely/migration/execute.js.map +1 -1
  34. package/dist/migration-engine/shared.d.ts +24 -5
  35. package/dist/migration-engine/shared.d.ts.map +1 -1
  36. package/dist/migration-engine/shared.js.map +1 -1
  37. package/dist/query/query.d.ts +4 -4
  38. package/dist/query/query.d.ts.map +1 -1
  39. package/dist/query/unit-of-work.d.ts +22 -22
  40. package/dist/query/unit-of-work.d.ts.map +1 -1
  41. package/dist/schema/create.d.ts +41 -41
  42. package/dist/schema/create.d.ts.map +1 -1
  43. package/package.json +7 -2
  44. package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +1 -1
  45. package/src/adapters/drizzle/drizzle-adapter.ts +13 -3
  46. package/src/adapters/drizzle/generate.test.ts +97 -0
  47. package/src/adapters/drizzle/generate.ts +3 -2
  48. package/src/adapters/kysely/kysely-adapter.ts +64 -35
  49. package/src/adapters/kysely/kysely-query-compiler.ts +3 -1
  50. package/src/adapters/kysely/kysely-query.ts +3 -1
  51. package/src/adapters/kysely/kysely-uow-compiler.ts +4 -2
  52. package/src/adapters/kysely/migration/execute-base.ts +256 -0
  53. package/src/adapters/kysely/migration/execute-factory.ts +32 -0
  54. package/src/adapters/kysely/migration/execute-mssql.ts +250 -0
  55. package/src/adapters/kysely/migration/execute-mysql.ts +211 -0
  56. package/src/adapters/kysely/migration/execute-postgres.ts +234 -0
  57. package/src/adapters/kysely/migration/execute-sqlite.test.ts +1363 -0
  58. package/src/adapters/kysely/migration/execute-sqlite.ts +247 -0
  59. package/src/adapters/kysely/migration/execute.ts +33 -396
  60. package/src/adapters/kysely/migration/kysely-migrator.test.ts +84 -2
  61. package/src/migration-engine/shared.ts +29 -11
  62. package/tsdown.config.ts +1 -0
@@ -0,0 +1,112 @@
1
+ import { isUpdated } from "../../../migration-engine/shared.js";
2
+ import { BaseMigrationExecutor, createUniqueIndex, dropUniqueIndex, getForeignKeyAction, getMssqlDefaultConstraintName, mssqlDropDefaultConstraint } from "./execute-base.js";
3
+ import { sql } from "kysely";
4
+
5
+ //#region src/adapters/kysely/migration/execute-mssql.ts
6
+ const errors = { IdColumnUpdate: "ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds." };
7
+ /**
8
+ * MSSQL-specific migration executor.
9
+ * Handles complex default constraint management and uses sp_rename for table renames.
10
+ */
11
+ var MssqlMigrationExecutor = class extends BaseMigrationExecutor {
12
+ executeOperation(operation, mapper) {
13
+ switch (operation.type) {
14
+ case "create-table": return this.createTable(operation, mapper);
15
+ case "rename-table": return this.renameTable(operation, mapper);
16
+ case "alter-table": return this.alterTable(operation, mapper);
17
+ case "drop-table": return this.dropTable(operation, mapper);
18
+ case "add-foreign-key": return this.addForeignKey(operation, mapper);
19
+ case "drop-foreign-key": return this.dropForeignKey(operation, mapper);
20
+ case "add-index": return this.addIndex(operation, mapper);
21
+ case "drop-index": return this.dropIndex(operation, mapper);
22
+ case "custom": return this.handleCustomOperation(operation);
23
+ }
24
+ }
25
+ createTable(operation, mapper) {
26
+ const tableName = this.getTableName(operation.name, mapper);
27
+ let builder = this.db.schema.createTable(tableName);
28
+ for (const columnInfo of operation.columns) builder = builder.addColumn(columnInfo.name, sql.raw(this.getDBType(columnInfo)), this.getColumnBuilderCallback(columnInfo));
29
+ return builder;
30
+ }
31
+ renameTable(operation, mapper) {
32
+ return this.rawToNode(sql`EXEC sp_rename ${sql.lit(this.getTableName(operation.from, mapper))}, ${sql.lit(this.getTableName(operation.to, mapper))}`);
33
+ }
34
+ alterTable(operation, mapper) {
35
+ const results = [];
36
+ const tableName = this.getTableName(operation.name, mapper);
37
+ for (const columnOp of operation.value) results.push(...this.executeColumnOperation(tableName, columnOp));
38
+ return results;
39
+ }
40
+ executeColumnOperation(tableName, operation) {
41
+ const next = () => this.db.schema.alterTable(tableName);
42
+ const results = [];
43
+ switch (operation.type) {
44
+ case "rename-column":
45
+ results.push(next().renameColumn(operation.from, operation.to));
46
+ return results;
47
+ case "drop-column":
48
+ results.push(next().dropColumn(operation.name));
49
+ return results;
50
+ case "create-column": {
51
+ const col = operation.value;
52
+ results.push(next().addColumn(col.name, sql.raw(this.getDBType(col)), this.getColumnBuilderCallback(col)));
53
+ return results;
54
+ }
55
+ case "update-column": {
56
+ const col = operation.value;
57
+ if (col.role === "external-id" || col.role === "internal-id") throw new Error(errors.IdColumnUpdate);
58
+ if (!isUpdated(operation)) return results;
59
+ const mssqlRecreateDefaultConstraint = operation.updateDataType || operation.updateDefault;
60
+ if (mssqlRecreateDefaultConstraint) results.push(this.rawToNode(mssqlDropDefaultConstraint(tableName, col.name)));
61
+ if (operation.updateDataType) {
62
+ const dbType = sql.raw(this.getDBType(col));
63
+ results.push(next().alterColumn(operation.name, (b) => b.setDataType(dbType)));
64
+ }
65
+ if (operation.updateNullable) results.push(next().alterColumn(operation.name, (build) => col.isNullable ? build.dropNotNull() : build.setNotNull()));
66
+ if (mssqlRecreateDefaultConstraint) {
67
+ const defaultValue = this.defaultValueToDB(col);
68
+ if (defaultValue) {
69
+ const constraintName = getMssqlDefaultConstraintName(tableName, col.name);
70
+ results.push(this.rawToNode(sql`ALTER TABLE ${sql.ref(tableName)} ADD CONSTRAINT ${sql.ref(constraintName)} DEFAULT ${defaultValue} FOR ${sql.ref(col.name)}`));
71
+ }
72
+ } else if (operation.updateDefault) {
73
+ const defaultValue = this.defaultValueToDB(col);
74
+ results.push(next().alterColumn(operation.name, (build) => {
75
+ if (!defaultValue) return build.dropDefault();
76
+ return build.setDefault(defaultValue);
77
+ }));
78
+ }
79
+ return results;
80
+ }
81
+ }
82
+ }
83
+ dropTable(operation, mapper) {
84
+ return this.db.schema.dropTable(this.getTableName(operation.name, mapper));
85
+ }
86
+ addForeignKey(operation, mapper) {
87
+ const { table, value } = operation;
88
+ const action = getForeignKeyAction(this.provider);
89
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).addForeignKeyConstraint(value.name, value.columns, this.getTableName(value.referencedTable, mapper), value.referencedColumns, (b) => b.onUpdate(action).onDelete(action));
90
+ }
91
+ dropForeignKey(operation, mapper) {
92
+ const { table, name } = operation;
93
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).dropConstraint(name).ifExists();
94
+ }
95
+ addIndex(operation, mapper) {
96
+ const tableName = this.getTableName(operation.table, mapper);
97
+ if (operation.unique) return createUniqueIndex(this.db, operation.name, tableName, operation.columns, this.provider);
98
+ return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);
99
+ }
100
+ dropIndex(operation, mapper) {
101
+ const tableName = this.getTableName(operation.table, mapper);
102
+ return dropUniqueIndex(this.db, operation.name, tableName, this.provider);
103
+ }
104
+ handleCustomOperation(operation) {
105
+ const statement = sql.raw(operation["sql"]);
106
+ return this.rawToNode(statement);
107
+ }
108
+ };
109
+
110
+ //#endregion
111
+ export { MssqlMigrationExecutor };
112
+ //# sourceMappingURL=execute-mssql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-mssql.js","names":["results: ExecuteNode[]"],"sources":["../../../../src/adapters/kysely/migration/execute-mssql.ts"],"sourcesContent":["import { sql } from \"kysely\";\nimport {\n type ColumnOperation,\n isUpdated,\n type MigrationOperation,\n} from \"../../../migration-engine/shared\";\nimport type { TableNameMapper } from \"../kysely-shared\";\nimport {\n BaseMigrationExecutor,\n createUniqueIndex,\n dropUniqueIndex,\n type ExecuteNode,\n getForeignKeyAction,\n getMssqlDefaultConstraintName,\n mssqlDropDefaultConstraint,\n} from \"./execute-base\";\n\nconst errors = {\n IdColumnUpdate:\n \"ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds.\",\n} as const;\n\n/**\n * MSSQL-specific migration executor.\n * Handles complex default constraint management and uses sp_rename for table renames.\n */\nexport class MssqlMigrationExecutor extends BaseMigrationExecutor {\n executeOperation(\n operation: MigrationOperation,\n mapper?: TableNameMapper,\n ): ExecuteNode | ExecuteNode[] {\n switch (operation.type) {\n case \"create-table\":\n return this.createTable(operation, mapper);\n case \"rename-table\":\n return this.renameTable(operation, mapper);\n case \"alter-table\":\n return this.alterTable(operation, mapper);\n case \"drop-table\":\n return this.dropTable(operation, mapper);\n case \"add-foreign-key\":\n return this.addForeignKey(operation, mapper);\n case \"drop-foreign-key\":\n return this.dropForeignKey(operation, mapper);\n case \"add-index\":\n return this.addIndex(operation, mapper);\n case \"drop-index\":\n return this.dropIndex(operation, mapper);\n case \"custom\":\n return this.handleCustomOperation(operation);\n }\n }\n\n private createTable(\n operation: Extract<MigrationOperation, { type: \"create-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.name, mapper);\n let builder = this.db.schema.createTable(tableName);\n\n // Add columns\n for (const columnInfo of operation.columns) {\n builder = builder.addColumn(\n columnInfo.name,\n sql.raw(this.getDBType(columnInfo)),\n this.getColumnBuilderCallback(columnInfo),\n );\n }\n\n return builder;\n }\n\n private renameTable(\n operation: Extract<MigrationOperation, { type: \"rename-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n // MSSQL uses sp_rename procedure\n return this.rawToNode(\n sql`EXEC sp_rename ${sql.lit(this.getTableName(operation.from, mapper))}, ${sql.lit(this.getTableName(operation.to, mapper))}`,\n );\n }\n\n private alterTable(\n operation: Extract<MigrationOperation, { type: \"alter-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode[] {\n const results: ExecuteNode[] = [];\n const tableName = this.getTableName(operation.name, mapper);\n\n for (const columnOp of operation.value) {\n results.push(...this.executeColumnOperation(tableName, columnOp));\n }\n\n return results;\n }\n\n private executeColumnOperation(tableName: string, operation: ColumnOperation): ExecuteNode[] {\n const next = () => this.db.schema.alterTable(tableName);\n const results: ExecuteNode[] = [];\n\n switch (operation.type) {\n case \"rename-column\":\n results.push(next().renameColumn(operation.from, operation.to));\n return results;\n\n case \"drop-column\":\n results.push(next().dropColumn(operation.name));\n return results;\n\n case \"create-column\": {\n const col = operation.value;\n results.push(\n next().addColumn(\n col.name,\n sql.raw(this.getDBType(col)),\n this.getColumnBuilderCallback(col),\n ),\n );\n return results;\n }\n\n case \"update-column\": {\n const col = operation.value;\n\n if (col.role === \"external-id\" || col.role === \"internal-id\") {\n throw new Error(errors.IdColumnUpdate);\n }\n\n if (!isUpdated(operation)) {\n return results;\n }\n\n // MSSQL requires dropping and recreating default constraints when changing data type or default value\n const mssqlRecreateDefaultConstraint = operation.updateDataType || operation.updateDefault;\n\n if (mssqlRecreateDefaultConstraint) {\n results.push(this.rawToNode(mssqlDropDefaultConstraint(tableName, col.name)));\n }\n\n if (operation.updateDataType) {\n const dbType = sql.raw(this.getDBType(col));\n results.push(next().alterColumn(operation.name, (b) => b.setDataType(dbType)));\n }\n\n if (operation.updateNullable) {\n results.push(\n next().alterColumn(operation.name, (build) =>\n col.isNullable ? build.dropNotNull() : build.setNotNull(),\n ),\n );\n }\n\n if (mssqlRecreateDefaultConstraint) {\n const defaultValue = this.defaultValueToDB(col);\n\n if (defaultValue) {\n const constraintName = getMssqlDefaultConstraintName(tableName, col.name);\n results.push(\n this.rawToNode(\n sql`ALTER TABLE ${sql.ref(tableName)} ADD CONSTRAINT ${sql.ref(constraintName)} DEFAULT ${defaultValue} FOR ${sql.ref(col.name)}`,\n ),\n );\n }\n } else if (operation.updateDefault) {\n const defaultValue = this.defaultValueToDB(col);\n results.push(\n next().alterColumn(operation.name, (build) => {\n if (!defaultValue) {\n return build.dropDefault();\n }\n return build.setDefault(defaultValue);\n }),\n );\n }\n\n return results;\n }\n }\n }\n\n private dropTable(\n operation: Extract<MigrationOperation, { type: \"drop-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema.dropTable(this.getTableName(operation.name, mapper));\n }\n\n private addForeignKey(\n operation: Extract<MigrationOperation, { type: \"add-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, value } = operation;\n const action = getForeignKeyAction(this.provider);\n\n return this.db.schema\n .alterTable(this.getTableName(table, mapper))\n .addForeignKeyConstraint(\n value.name,\n value.columns,\n this.getTableName(value.referencedTable, mapper),\n value.referencedColumns,\n (b) => b.onUpdate(action).onDelete(action),\n );\n }\n\n private dropForeignKey(\n operation: Extract<MigrationOperation, { type: \"drop-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, name } = operation;\n return this.db.schema\n .alterTable(this.getTableName(table, mapper))\n .dropConstraint(name)\n .ifExists();\n }\n\n private addIndex(\n operation: Extract<MigrationOperation, { type: \"add-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n\n if (operation.unique) {\n return createUniqueIndex(\n this.db,\n operation.name,\n tableName,\n operation.columns,\n this.provider,\n );\n }\n\n return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);\n }\n\n private dropIndex(\n operation: Extract<MigrationOperation, { type: \"drop-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n return dropUniqueIndex(this.db, operation.name, tableName, this.provider);\n }\n\n private handleCustomOperation(\n operation: Extract<MigrationOperation, { type: \"custom\" }>,\n ): ExecuteNode {\n const statement = sql.raw(operation[\"sql\"] as string);\n return this.rawToNode(statement);\n }\n}\n"],"mappings":";;;;;AAiBA,MAAM,SAAS,EACb,gBACE,mHACH;;;;;AAMD,IAAa,yBAAb,cAA4C,sBAAsB;CAChE,iBACE,WACA,QAC6B;AAC7B,UAAQ,UAAU,MAAlB;GACE,KAAK,eACH,QAAO,KAAK,YAAY,WAAW,OAAO;GAC5C,KAAK,eACH,QAAO,KAAK,YAAY,WAAW,OAAO;GAC5C,KAAK,cACH,QAAO,KAAK,WAAW,WAAW,OAAO;GAC3C,KAAK,aACH,QAAO,KAAK,UAAU,WAAW,OAAO;GAC1C,KAAK,kBACH,QAAO,KAAK,cAAc,WAAW,OAAO;GAC9C,KAAK,mBACH,QAAO,KAAK,eA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AAU,MAAM,OAAO,CAAC;;CAG5E,AAAQ,cACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,UAAU;EACzB,MAAM,SAAS,oBAAoB,KAAK,SAAS;AAEjD,SAAO,KAAK,GAAG,OACZ,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAC5C,wBACC,MAAM,MACN,MAAM,SACN,KAAK,aAAa,MAAM,iBAAiB,OAAO,EAChD,MAAM,oBACL,MAAM,EAAE,SAAS,OAAO,CAAC,SAAS,OAAO,CAC3C;;CAGL,AAAQ,eACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,SAAS;AACxB,SAAO,KAAK,GAAG,OACZ,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAC5C,eAAe,KAAK,CACpB,UAAU;;CAGf,AAAQ,SACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAE5D,MAAI,UAAU,OACZ,QAAO,kBACL,KAAK,IACL,UAAU,MACV,WACA,UAAU,SACV,KAAK,SACN;AAGH,SAAO,KAAK,GAAG,OAAO,YAAY,UAAU,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,UAAU,QAAQ;;CAG5F,AAAQ,UACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAC5D,SAAO,gBAAgB,KAAK,IAAI,UAAU,MAAM,WAAW,KAAK,SAAS;;CAG3E,AAAQ,sBACN,WACa;EACb,MAAM,YAAY,IAAI,IAAI,UAAU,OAAiB;AACrD,SAAO,KAAK,UAAU,UAAU"}
@@ -0,0 +1,93 @@
1
+ import { isUpdated } from "../../../migration-engine/shared.js";
2
+ import { BaseMigrationExecutor, createUniqueIndex, dropUniqueIndex, getForeignKeyAction } from "./execute-base.js";
3
+ import { sql } from "kysely";
4
+
5
+ //#region src/adapters/kysely/migration/execute-mysql.ts
6
+ const errors = { IdColumnUpdate: "ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds." };
7
+ /**
8
+ * MySQL-specific migration executor.
9
+ * Uses modifyColumn for updates and "no action" for FK actions (RESTRICT not supported).
10
+ */
11
+ var MysqlMigrationExecutor = class extends BaseMigrationExecutor {
12
+ executeOperation(operation, mapper) {
13
+ switch (operation.type) {
14
+ case "create-table": return this.createTable(operation, mapper);
15
+ case "rename-table": return this.renameTable(operation, mapper);
16
+ case "alter-table": return this.alterTable(operation, mapper);
17
+ case "drop-table": return this.dropTable(operation, mapper);
18
+ case "add-foreign-key": return this.addForeignKey(operation, mapper);
19
+ case "drop-foreign-key": return this.dropForeignKey(operation, mapper);
20
+ case "add-index": return this.addIndex(operation, mapper);
21
+ case "drop-index": return this.dropIndex(operation, mapper);
22
+ case "custom": return this.handleCustomOperation(operation);
23
+ }
24
+ }
25
+ createTable(operation, mapper) {
26
+ const tableName = this.getTableName(operation.name, mapper);
27
+ let builder = this.db.schema.createTable(tableName);
28
+ for (const columnInfo of operation.columns) builder = builder.addColumn(columnInfo.name, sql.raw(this.getDBType(columnInfo)), this.getColumnBuilderCallback(columnInfo));
29
+ return builder;
30
+ }
31
+ renameTable(operation, mapper) {
32
+ return this.db.schema.alterTable(this.getTableName(operation.from, mapper)).renameTo(this.getTableName(operation.to, mapper));
33
+ }
34
+ alterTable(operation, mapper) {
35
+ const results = [];
36
+ const tableName = this.getTableName(operation.name, mapper);
37
+ for (const columnOp of operation.value) results.push(...this.executeColumnOperation(tableName, columnOp));
38
+ return results;
39
+ }
40
+ executeColumnOperation(tableName, operation) {
41
+ const next = () => this.db.schema.alterTable(tableName);
42
+ const results = [];
43
+ switch (operation.type) {
44
+ case "rename-column":
45
+ results.push(next().renameColumn(operation.from, operation.to));
46
+ return results;
47
+ case "drop-column":
48
+ results.push(next().dropColumn(operation.name));
49
+ return results;
50
+ case "create-column": {
51
+ const col = operation.value;
52
+ results.push(next().addColumn(col.name, sql.raw(this.getDBType(col)), this.getColumnBuilderCallback(col)));
53
+ return results;
54
+ }
55
+ case "update-column": {
56
+ const col = operation.value;
57
+ if (col.role === "external-id" || col.role === "internal-id") throw new Error(errors.IdColumnUpdate);
58
+ if (!isUpdated(operation)) return results;
59
+ results.push(next().modifyColumn(operation.name, sql.raw(this.getDBType(col)), this.getColumnBuilderCallback(col)));
60
+ return results;
61
+ }
62
+ }
63
+ }
64
+ dropTable(operation, mapper) {
65
+ return this.db.schema.dropTable(this.getTableName(operation.name, mapper));
66
+ }
67
+ addForeignKey(operation, mapper) {
68
+ const { table, value } = operation;
69
+ const action = getForeignKeyAction(this.provider);
70
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).addForeignKeyConstraint(value.name, value.columns, this.getTableName(value.referencedTable, mapper), value.referencedColumns, (b) => b.onUpdate(action).onDelete(action));
71
+ }
72
+ dropForeignKey(operation, mapper) {
73
+ const { table, name } = operation;
74
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).dropConstraint(name);
75
+ }
76
+ addIndex(operation, mapper) {
77
+ const tableName = this.getTableName(operation.table, mapper);
78
+ if (operation.unique) return createUniqueIndex(this.db, operation.name, tableName, operation.columns, this.provider);
79
+ return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);
80
+ }
81
+ dropIndex(operation, mapper) {
82
+ const tableName = this.getTableName(operation.table, mapper);
83
+ return dropUniqueIndex(this.db, operation.name, tableName, this.provider);
84
+ }
85
+ handleCustomOperation(operation) {
86
+ const statement = sql.raw(operation["sql"]);
87
+ return this.rawToNode(statement);
88
+ }
89
+ };
90
+
91
+ //#endregion
92
+ export { MysqlMigrationExecutor };
93
+ //# sourceMappingURL=execute-mysql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-mysql.js","names":["results: ExecuteNode[]"],"sources":["../../../../src/adapters/kysely/migration/execute-mysql.ts"],"sourcesContent":["import { sql } from \"kysely\";\nimport {\n type ColumnOperation,\n isUpdated,\n type MigrationOperation,\n} from \"../../../migration-engine/shared\";\nimport type { TableNameMapper } from \"../kysely-shared\";\nimport {\n BaseMigrationExecutor,\n createUniqueIndex,\n dropUniqueIndex,\n type ExecuteNode,\n getForeignKeyAction,\n} from \"./execute-base\";\n\nconst errors = {\n IdColumnUpdate:\n \"ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds.\",\n} as const;\n\n/**\n * MySQL-specific migration executor.\n * Uses modifyColumn for updates and \"no action\" for FK actions (RESTRICT not supported).\n */\nexport class MysqlMigrationExecutor extends BaseMigrationExecutor {\n executeOperation(\n operation: MigrationOperation,\n mapper?: TableNameMapper,\n ): ExecuteNode | ExecuteNode[] {\n switch (operation.type) {\n case \"create-table\":\n return this.createTable(operation, mapper);\n case \"rename-table\":\n return this.renameTable(operation, mapper);\n case \"alter-table\":\n return this.alterTable(operation, mapper);\n case \"drop-table\":\n return this.dropTable(operation, mapper);\n case \"add-foreign-key\":\n return this.addForeignKey(operation, mapper);\n case \"drop-foreign-key\":\n return this.dropForeignKey(operation, mapper);\n case \"add-index\":\n return this.addIndex(operation, mapper);\n case \"drop-index\":\n return this.dropIndex(operation, mapper);\n case \"custom\":\n return this.handleCustomOperation(operation);\n }\n }\n\n private createTable(\n operation: Extract<MigrationOperation, { type: \"create-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.name, mapper);\n let builder = this.db.schema.createTable(tableName);\n\n // Add columns\n for (const columnInfo of operation.columns) {\n builder = builder.addColumn(\n columnInfo.name,\n sql.raw(this.getDBType(columnInfo)),\n this.getColumnBuilderCallback(columnInfo),\n );\n }\n\n return builder;\n }\n\n private renameTable(\n operation: Extract<MigrationOperation, { type: \"rename-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema\n .alterTable(this.getTableName(operation.from, mapper))\n .renameTo(this.getTableName(operation.to, mapper));\n }\n\n private alterTable(\n operation: Extract<MigrationOperation, { type: \"alter-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode[] {\n const results: ExecuteNode[] = [];\n const tableName = this.getTableName(operation.name, mapper);\n\n for (const columnOp of operation.value) {\n results.push(...this.executeColumnOperation(tableName, columnOp));\n }\n\n return results;\n }\n\n private executeColumnOperation(tableName: string, operation: ColumnOperation): ExecuteNode[] {\n const next = () => this.db.schema.alterTable(tableName);\n const results: ExecuteNode[] = [];\n\n switch (operation.type) {\n case \"rename-column\":\n results.push(next().renameColumn(operation.from, operation.to));\n return results;\n\n case \"drop-column\":\n results.push(next().dropColumn(operation.name));\n return results;\n\n case \"create-column\": {\n const col = operation.value;\n results.push(\n next().addColumn(\n col.name,\n sql.raw(this.getDBType(col)),\n this.getColumnBuilderCallback(col),\n ),\n );\n return results;\n }\n\n case \"update-column\": {\n const col = operation.value;\n\n if (col.role === \"external-id\" || col.role === \"internal-id\") {\n throw new Error(errors.IdColumnUpdate);\n }\n\n if (!isUpdated(operation)) {\n return results;\n }\n\n // MySQL: Use modifyColumn which requires the full column definition\n results.push(\n next().modifyColumn(\n operation.name,\n sql.raw(this.getDBType(col)),\n this.getColumnBuilderCallback(col),\n ),\n );\n\n return results;\n }\n }\n }\n\n private dropTable(\n operation: Extract<MigrationOperation, { type: \"drop-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema.dropTable(this.getTableName(operation.name, mapper));\n }\n\n private addForeignKey(\n operation: Extract<MigrationOperation, { type: \"add-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, value } = operation;\n const action = getForeignKeyAction(this.provider);\n\n return this.db.schema\n .alterTable(this.getTableName(table, mapper))\n .addForeignKeyConstraint(\n value.name,\n value.columns,\n this.getTableName(value.referencedTable, mapper),\n value.referencedColumns,\n (b) => b.onUpdate(action).onDelete(action),\n );\n }\n\n private dropForeignKey(\n operation: Extract<MigrationOperation, { type: \"drop-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, name } = operation;\n // MySQL doesn't support IF EXISTS for dropping constraints\n return this.db.schema.alterTable(this.getTableName(table, mapper)).dropConstraint(name);\n }\n\n private addIndex(\n operation: Extract<MigrationOperation, { type: \"add-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n\n if (operation.unique) {\n return createUniqueIndex(\n this.db,\n operation.name,\n tableName,\n operation.columns,\n this.provider,\n );\n }\n\n return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);\n }\n\n private dropIndex(\n operation: Extract<MigrationOperation, { type: \"drop-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n return dropUniqueIndex(this.db, operation.name, tableName, this.provider);\n }\n\n private handleCustomOperation(\n operation: Extract<MigrationOperation, { type: \"custom\" }>,\n ): ExecuteNode {\n const statement = sql.raw(operation[\"sql\"] as string);\n return this.rawToNode(statement);\n }\n}\n"],"mappings":";;;;;AAeA,MAAM,SAAS,EACb,gBACE,mHACH;;;;;AAMD,IAAa,yBAAb,cAA4C,sBAAsB;CAChE,iBACE,WACA,QAC6B;AAC7B,UAAQ,UAAU,MAAlB;GACE,KAAK,eACH,QAAO,KAAK,YAAY,WAAW,OAAO;GAC5C,KAAK,eACH,QAAO,KAAK,YAAY,WAAW,OAAO;GAC5C,KAAK,cACH,QAAO,KAAK,WAAW,WAAW,OAAO;GAC3C,KAAK,aACH,QAAO,KAAK,UAAU,WAAW,OAAO;GAC1C,KAAK,kBACH,QAAO,KAAK,cAAc,WAAW,OAAO;GAC9C,KAAK,mBACH,QAAO,KAAK,eAAe,WAAW,OAAO;GAC/C,KAAK,YACH,QAAO,KAAK,SAAS,WAAW,OAAO;GACzC,KAAK,aACH,QAAO,KAAK,UAAU,WAAW,OAAO;GAC1C,KAAK,SACH,QAAO,KAAK,sBAAsB,UAAU;;;CAIlD,AAAQ,YACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,MAAM,OAAO;EAC3D,IAAI,UAAU,KAAK,GAAG,OAAO,YAAY,UAAU;AAGnD,OAAK,MAAM,cAAc,UAAU,QACjC,WAAU,QAAQ,UAChB,WAAW,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;CAKb,AAAQ,UACN,WACA,QACa;AACb,SAAO,KAAK,GAAG,OAAO,UAAU,KAAK,aAAa,UAAU,MAAM,OAAO,CAAC;;CAG5E,AAAQ,cACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,UAAU;EACzB,MAAM,SAAS,oBAAoB,KAAK,SAAS;AAEjD,SAAO,KAAK,GAAG,OACZ,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAC5C,wBACC,MAAM,MACN,MAAM,SACN,KAAK,aAAa,MAAM,iBAAiB,OAAO,EAChD,MAAM,oBACL,MAAM,EAAE,SAAS,OAAO,CAAC,SAAS,OAAO,CAC3C;;CAGL,AAAQ,eACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,SAAS;AAExB,SAAO,KAAK,GAAG,OAAO,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAAC,eAAe,KAAK;;CAGzF,AAAQ,SACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAE5D,MAAI,UAAU,OACZ,QAAO,kBACL,KAAK,IACL,UAAU,MACV,WACA,UAAU,SACV,KAAK,SACN;AAGH,SAAO,KAAK,GAAG,OAAO,YAAY,UAAU,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,UAAU,QAAQ;;CAG5F,AAAQ,UACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAC5D,SAAO,gBAAgB,KAAK,IAAI,UAAU,MAAM,WAAW,KAAK,SAAS;;CAG3E,AAAQ,sBACN,WACa;EACb,MAAM,YAAY,IAAI,IAAI,UAAU,OAAiB;AACrD,SAAO,KAAK,UAAU,UAAU"}
@@ -0,0 +1,104 @@
1
+ import { isUpdated } from "../../../migration-engine/shared.js";
2
+ import { BaseMigrationExecutor, createUniqueIndex, dropUniqueIndex, getForeignKeyAction } from "./execute-base.js";
3
+ import { sql } from "kysely";
4
+
5
+ //#region src/adapters/kysely/migration/execute-postgres.ts
6
+ const errors = { IdColumnUpdate: "ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds." };
7
+ /**
8
+ * PostgreSQL/CockroachDB-specific migration executor.
9
+ * Uses explicit USING clauses for type conversion.
10
+ */
11
+ var PostgresMigrationExecutor = class extends BaseMigrationExecutor {
12
+ executeOperation(operation, mapper) {
13
+ switch (operation.type) {
14
+ case "create-table": return this.createTable(operation, mapper);
15
+ case "rename-table": return this.renameTable(operation, mapper);
16
+ case "alter-table": return this.alterTable(operation, mapper);
17
+ case "drop-table": return this.dropTable(operation, mapper);
18
+ case "add-foreign-key": return this.addForeignKey(operation, mapper);
19
+ case "drop-foreign-key": return this.dropForeignKey(operation, mapper);
20
+ case "add-index": return this.addIndex(operation, mapper);
21
+ case "drop-index": return this.dropIndex(operation, mapper);
22
+ case "custom": return this.handleCustomOperation(operation);
23
+ }
24
+ }
25
+ createTable(operation, mapper) {
26
+ const tableName = this.getTableName(operation.name, mapper);
27
+ let builder = this.db.schema.createTable(tableName);
28
+ for (const columnInfo of operation.columns) builder = builder.addColumn(columnInfo.name, sql.raw(this.getDBType(columnInfo)), this.getColumnBuilderCallback(columnInfo));
29
+ return builder;
30
+ }
31
+ renameTable(operation, mapper) {
32
+ return this.db.schema.alterTable(this.getTableName(operation.from, mapper)).renameTo(this.getTableName(operation.to, mapper));
33
+ }
34
+ alterTable(operation, mapper) {
35
+ const results = [];
36
+ const tableName = this.getTableName(operation.name, mapper);
37
+ for (const columnOp of operation.value) results.push(...this.executeColumnOperation(tableName, columnOp));
38
+ return results;
39
+ }
40
+ executeColumnOperation(tableName, operation) {
41
+ const next = () => this.db.schema.alterTable(tableName);
42
+ const results = [];
43
+ switch (operation.type) {
44
+ case "rename-column":
45
+ results.push(next().renameColumn(operation.from, operation.to));
46
+ return results;
47
+ case "drop-column":
48
+ results.push(next().dropColumn(operation.name));
49
+ return results;
50
+ case "create-column": {
51
+ const col = operation.value;
52
+ results.push(next().addColumn(col.name, sql.raw(this.getDBType(col)), this.getColumnBuilderCallback(col)));
53
+ return results;
54
+ }
55
+ case "update-column": {
56
+ const col = operation.value;
57
+ if (col.role === "external-id" || col.role === "internal-id") throw new Error(errors.IdColumnUpdate);
58
+ if (!isUpdated(operation)) return results;
59
+ if (operation.updateDataType) {
60
+ const dbType = sql.raw(this.getDBType(col));
61
+ results.push(this.rawToNode(sql`ALTER TABLE ${sql.ref(tableName)} ALTER COLUMN ${sql.ref(operation.name)} TYPE ${dbType} USING (${sql.ref(operation.name)}::${dbType})`));
62
+ }
63
+ if (operation.updateNullable) results.push(next().alterColumn(operation.name, (build) => col.isNullable ? build.dropNotNull() : build.setNotNull()));
64
+ if (operation.updateDefault) {
65
+ const defaultValue = this.defaultValueToDB(col);
66
+ results.push(next().alterColumn(operation.name, (build) => {
67
+ if (!defaultValue) return build.dropDefault();
68
+ return build.setDefault(defaultValue);
69
+ }));
70
+ }
71
+ return results;
72
+ }
73
+ }
74
+ }
75
+ dropTable(operation, mapper) {
76
+ return this.db.schema.dropTable(this.getTableName(operation.name, mapper));
77
+ }
78
+ addForeignKey(operation, mapper) {
79
+ const { table, value } = operation;
80
+ const action = getForeignKeyAction(this.provider);
81
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).addForeignKeyConstraint(value.name, value.columns, this.getTableName(value.referencedTable, mapper), value.referencedColumns, (b) => b.onUpdate(action).onDelete(action));
82
+ }
83
+ dropForeignKey(operation, mapper) {
84
+ const { table, name } = operation;
85
+ return this.db.schema.alterTable(this.getTableName(table, mapper)).dropConstraint(name).ifExists();
86
+ }
87
+ addIndex(operation, mapper) {
88
+ const tableName = this.getTableName(operation.table, mapper);
89
+ if (operation.unique) return createUniqueIndex(this.db, operation.name, tableName, operation.columns, this.provider);
90
+ return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);
91
+ }
92
+ dropIndex(operation, mapper) {
93
+ const tableName = this.getTableName(operation.table, mapper);
94
+ return dropUniqueIndex(this.db, operation.name, tableName, this.provider);
95
+ }
96
+ handleCustomOperation(operation) {
97
+ const statement = sql.raw(operation["sql"]);
98
+ return this.rawToNode(statement);
99
+ }
100
+ };
101
+
102
+ //#endregion
103
+ export { PostgresMigrationExecutor };
104
+ //# sourceMappingURL=execute-postgres.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-postgres.js","names":["results: ExecuteNode[]"],"sources":["../../../../src/adapters/kysely/migration/execute-postgres.ts"],"sourcesContent":["import { sql } from \"kysely\";\nimport {\n type ColumnOperation,\n isUpdated,\n type MigrationOperation,\n} from \"../../../migration-engine/shared\";\nimport type { TableNameMapper } from \"../kysely-shared\";\nimport {\n BaseMigrationExecutor,\n createUniqueIndex,\n dropUniqueIndex,\n type ExecuteNode,\n getForeignKeyAction,\n} from \"./execute-base\";\n\nconst errors = {\n IdColumnUpdate:\n \"ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds.\",\n} as const;\n\n/**\n * PostgreSQL/CockroachDB-specific migration executor.\n * Uses explicit USING clauses for type conversion.\n */\nexport class PostgresMigrationExecutor extends BaseMigrationExecutor {\n executeOperation(\n operation: MigrationOperation,\n mapper?: TableNameMapper,\n ): ExecuteNode | ExecuteNode[] {\n switch (operation.type) {\n case \"create-table\":\n return this.createTable(operation, mapper);\n case \"rename-table\":\n return this.renameTable(operation, mapper);\n case \"alter-table\":\n return this.alterTable(operation, mapper);\n case \"drop-table\":\n return this.dropTable(operation, mapper);\n case \"add-foreign-key\":\n return this.addForeignKey(operation, mapper);\n case \"drop-foreign-key\":\n return this.dropForeignKey(operation, mapper);\n case \"add-index\":\n return this.addIndex(operation, mapper);\n case \"drop-index\":\n return this.dropIndex(operation, mapper);\n case \"custom\":\n return this.handleCustomOperation(operation);\n }\n }\n\n private createTable(\n operation: Extract<MigrationOperation, { type: \"create-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.name, mapper);\n let builder = this.db.schema.createTable(tableName);\n\n // Add columns\n for (const columnInfo of operation.columns) {\n builder = builder.addColumn(\n columnInfo.name,\n sql.raw(this.getDBType(columnInfo)),\n this.getColumnBuilderCallback(columnInfo),\n );\n }\n\n return builder;\n }\n\n private renameTable(\n operation: Extract<MigrationOperation, { type: \"rename-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema\n .alterTable(this.getTableName(operation.from, mapper))\n .renameTo(this.getTableName(operation.to, mapper));\n }\n\n private alterTable(\n operation: Extract<MigrationOperation, { type: \"alter-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode[] {\n const results: ExecuteNode[] = [];\n const tableName = this.getTableName(operation.name, mapper);\n\n for (const columnOp of operation.value) {\n results.push(...this.executeColumnOperation(tableName, columnOp));\n }\n\n return results;\n }\n\n private executeColumnOperation(tableName: string, operation: ColumnOperation): ExecuteNode[] {\n const next = () => this.db.schema.alterTable(tableName);\n const results: ExecuteNode[] = [];\n\n switch (operation.type) {\n case \"rename-column\":\n results.push(next().renameColumn(operation.from, operation.to));\n return results;\n\n case \"drop-column\":\n results.push(next().dropColumn(operation.name));\n return results;\n\n case \"create-column\": {\n const col = operation.value;\n results.push(\n next().addColumn(\n col.name,\n sql.raw(this.getDBType(col)),\n this.getColumnBuilderCallback(col),\n ),\n );\n return results;\n }\n\n case \"update-column\": {\n const col = operation.value;\n\n if (col.role === \"external-id\" || col.role === \"internal-id\") {\n throw new Error(errors.IdColumnUpdate);\n }\n\n if (!isUpdated(operation)) {\n return results;\n }\n\n // PostgreSQL/CockroachDB: Use explicit USING clause for type conversion\n if (operation.updateDataType) {\n const dbType = sql.raw(this.getDBType(col));\n results.push(\n this.rawToNode(\n sql`ALTER TABLE ${sql.ref(tableName)} ALTER COLUMN ${sql.ref(operation.name)} TYPE ${dbType} USING (${sql.ref(operation.name)}::${dbType})`,\n ),\n );\n }\n\n if (operation.updateNullable) {\n results.push(\n next().alterColumn(operation.name, (build) =>\n col.isNullable ? build.dropNotNull() : build.setNotNull(),\n ),\n );\n }\n\n if (operation.updateDefault) {\n const defaultValue = this.defaultValueToDB(col);\n results.push(\n next().alterColumn(operation.name, (build) => {\n if (!defaultValue) {\n return build.dropDefault();\n }\n return build.setDefault(defaultValue);\n }),\n );\n }\n\n return results;\n }\n }\n }\n\n private dropTable(\n operation: Extract<MigrationOperation, { type: \"drop-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema.dropTable(this.getTableName(operation.name, mapper));\n }\n\n private addForeignKey(\n operation: Extract<MigrationOperation, { type: \"add-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, value } = operation;\n const action = getForeignKeyAction(this.provider);\n\n return this.db.schema\n .alterTable(this.getTableName(table, mapper))\n .addForeignKeyConstraint(\n value.name,\n value.columns,\n this.getTableName(value.referencedTable, mapper),\n value.referencedColumns,\n (b) => b.onUpdate(action).onDelete(action),\n );\n }\n\n private dropForeignKey(\n operation: Extract<MigrationOperation, { type: \"drop-foreign-key\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const { table, name } = operation;\n return this.db.schema\n .alterTable(this.getTableName(table, mapper))\n .dropConstraint(name)\n .ifExists();\n }\n\n private addIndex(\n operation: Extract<MigrationOperation, { type: \"add-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n\n if (operation.unique) {\n return createUniqueIndex(\n this.db,\n operation.name,\n tableName,\n operation.columns,\n this.provider,\n );\n }\n\n return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);\n }\n\n private dropIndex(\n operation: Extract<MigrationOperation, { type: \"drop-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n return dropUniqueIndex(this.db, operation.name, tableName, this.provider);\n }\n\n private handleCustomOperation(\n operation: Extract<MigrationOperation, { type: \"custom\" }>,\n ): ExecuteNode {\n const statement = sql.raw(operation[\"sql\"] as string);\n return this.rawToNode(statement);\n }\n}\n"],"mappings":";;;;;AAeA,MAAM,SAAS,EACb,gBACE,mHAC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AAG,OAAO,UAAU,KAAK,aAAa,UAAU,MAAM,OAAO,CAAC;;CAG5E,AAAQ,cACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,UAAU;EACzB,MAAM,SAAS,oBAAoB,KAAK,SAAS;AAEjD,SAAO,KAAK,GAAG,OACZ,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAC5C,wBACC,MAAM,MACN,MAAM,SACN,KAAK,aAAa,MAAM,iBAAiB,OAAO,EAChD,MAAM,oBACL,MAAM,EAAE,SAAS,OAAO,CAAC,SAAS,OAAO,CAC3C;;CAGL,AAAQ,eACN,WACA,QACa;EACb,MAAM,EAAE,OAAO,SAAS;AACxB,SAAO,KAAK,GAAG,OACZ,WAAW,KAAK,aAAa,OAAO,OAAO,CAAC,CAC5C,eAAe,KAAK,CACpB,UAAU;;CAGf,AAAQ,SACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAE5D,MAAI,UAAU,OACZ,QAAO,kBACL,KAAK,IACL,UAAU,MACV,WACA,UAAU,SACV,KAAK,SACN;AAGH,SAAO,KAAK,GAAG,OAAO,YAAY,UAAU,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,UAAU,QAAQ;;CAG5F,AAAQ,UACN,WACA,QACa;EACb,MAAM,YAAY,KAAK,aAAa,UAAU,OAAO,OAAO;AAC5D,SAAO,gBAAgB,KAAK,IAAI,UAAU,MAAM,WAAW,KAAK,SAAS;;CAG3E,AAAQ,sBACN,WACa;EACb,MAAM,YAAY,IAAI,IAAI,UAAU,OAAiB;AACrD,SAAO,KAAK,UAAU,UAAU"}
@@ -0,0 +1,123 @@
1
+ import { BaseMigrationExecutor, createUniqueIndex, dropUniqueIndex } from "./execute-base.js";
2
+ import { sql } from "kysely";
3
+
4
+ //#region src/adapters/kysely/migration/execute-sqlite.ts
5
+ const errors = {
6
+ IdColumnUpdate: "ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds.",
7
+ SQLiteUpdateColumn: "SQLite doesn't support updating columns. Recreate the table instead.",
8
+ SQLiteUpdateForeignKeys: "SQLite doesn't support modifying foreign keys directly. Use `recreate-table` instead."
9
+ };
10
+ /**
11
+ * SQLite-specific migration executor.
12
+ * Handles SQLite's limitations around foreign keys and column updates.
13
+ */
14
+ var SqliteMigrationExecutor = class extends BaseMigrationExecutor {
15
+ /**
16
+ * SQLite preprocessing: merge add-foreign-key operations into create-table operations
17
+ * when both exist in the same batch.
18
+ *
19
+ * SQLite requires foreign keys to be defined at table creation time. This preprocessing
20
+ * step identifies create-table + add-foreign-key pairs and merges them.
21
+ */
22
+ preprocessOperations(operations) {
23
+ const result = [];
24
+ const createTableIndices = /* @__PURE__ */ new Map();
25
+ const foreignKeysByTable = /* @__PURE__ */ new Map();
26
+ for (const op of operations) if (op.type === "create-table") {
27
+ createTableIndices.set(op.name, result.length);
28
+ result.push(op);
29
+ } else if (op.type === "add-foreign-key") {
30
+ if (!foreignKeysByTable.has(op.table)) foreignKeysByTable.set(op.table, []);
31
+ foreignKeysByTable.get(op.table).push(op);
32
+ } else result.push(op);
33
+ for (const [tableName, fkOps] of foreignKeysByTable.entries()) {
34
+ const createTableIdx = createTableIndices.get(tableName);
35
+ if (createTableIdx !== void 0) {
36
+ const createOp = result[createTableIdx];
37
+ if (createOp.type === "create-table") result[createTableIdx] = {
38
+ ...createOp,
39
+ metadata: {
40
+ ...createOp.metadata,
41
+ inlineForeignKeys: fkOps.map((fkOp) => {
42
+ if (fkOp.type === "add-foreign-key") return fkOp.value;
43
+ throw new Error("Unexpected operation type");
44
+ })
45
+ }
46
+ };
47
+ } else result.push(...fkOps);
48
+ }
49
+ return result;
50
+ }
51
+ executeOperation(operation, mapper) {
52
+ switch (operation.type) {
53
+ case "create-table": return this.createTable(operation, mapper);
54
+ case "rename-table": return this.renameTable(operation, mapper);
55
+ case "alter-table": return this.alterTable(operation, mapper);
56
+ case "drop-table": return this.dropTable(operation, mapper);
57
+ case "add-foreign-key": throw new Error(errors.SQLiteUpdateForeignKeys);
58
+ case "drop-foreign-key": throw new Error(errors.SQLiteUpdateForeignKeys);
59
+ case "add-index": return this.addIndex(operation, mapper);
60
+ case "drop-index": return this.dropIndex(operation, mapper);
61
+ case "custom": return this.handleCustomOperation(operation);
62
+ }
63
+ }
64
+ createTable(operation, mapper) {
65
+ const tableName = this.getTableName(operation.name, mapper);
66
+ let builder = this.db.schema.createTable(tableName);
67
+ for (const columnInfo of operation.columns) builder = builder.addColumn(columnInfo.name, sql.raw(this.getDBType(columnInfo)), this.getColumnBuilderCallback(columnInfo));
68
+ const inlineForeignKeys = operation.metadata?.inlineForeignKeys;
69
+ if (inlineForeignKeys) for (const fk of inlineForeignKeys) builder = builder.addForeignKeyConstraint(fk.name, fk.columns, this.getTableName(fk.referencedTable, mapper), fk.referencedColumns, (cb) => cb.onUpdate("restrict").onDelete("restrict"));
70
+ return builder;
71
+ }
72
+ renameTable(operation, mapper) {
73
+ return this.db.schema.alterTable(this.getTableName(operation.from, mapper)).renameTo(this.getTableName(operation.to, mapper));
74
+ }
75
+ alterTable(operation, mapper) {
76
+ const results = [];
77
+ const tableName = this.getTableName(operation.name, mapper);
78
+ for (const columnOp of operation.value) results.push(...this.executeColumnOperation(tableName, columnOp));
79
+ return results;
80
+ }
81
+ executeColumnOperation(tableName, operation) {
82
+ const next = () => this.db.schema.alterTable(tableName);
83
+ const results = [];
84
+ switch (operation.type) {
85
+ case "rename-column":
86
+ results.push(next().renameColumn(operation.from, operation.to));
87
+ return results;
88
+ case "drop-column":
89
+ results.push(next().dropColumn(operation.name));
90
+ return results;
91
+ case "create-column": {
92
+ const col = operation.value;
93
+ results.push(next().addColumn(col.name, sql.raw(this.getDBType(col)), this.getColumnBuilderCallback(col)));
94
+ return results;
95
+ }
96
+ case "update-column": {
97
+ const col = operation.value;
98
+ if (col.role === "external-id" || col.role === "internal-id") throw new Error(errors.IdColumnUpdate);
99
+ throw new Error(errors.SQLiteUpdateColumn);
100
+ }
101
+ }
102
+ }
103
+ dropTable(operation, mapper) {
104
+ return this.db.schema.dropTable(this.getTableName(operation.name, mapper));
105
+ }
106
+ addIndex(operation, mapper) {
107
+ const tableName = this.getTableName(operation.table, mapper);
108
+ if (operation.unique) return createUniqueIndex(this.db, operation.name, tableName, operation.columns, this.provider);
109
+ return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);
110
+ }
111
+ dropIndex(operation, mapper) {
112
+ const tableName = this.getTableName(operation.table, mapper);
113
+ return dropUniqueIndex(this.db, operation.name, tableName, this.provider);
114
+ }
115
+ handleCustomOperation(operation) {
116
+ const statement = sql.raw(operation["sql"]);
117
+ return this.rawToNode(statement);
118
+ }
119
+ };
120
+
121
+ //#endregion
122
+ export { SqliteMigrationExecutor };
123
+ //# sourceMappingURL=execute-sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-sqlite.js","names":["result: MigrationOperation<SqliteCreateTableMetadata>[]","builder: any","results: ExecuteNode[]"],"sources":["../../../../src/adapters/kysely/migration/execute-sqlite.ts"],"sourcesContent":["import { sql } from \"kysely\";\nimport type {\n ColumnOperation,\n MigrationOperation,\n SqliteCreateTableMetadata,\n} from \"../../../migration-engine/shared\";\nimport type { TableNameMapper } from \"../kysely-shared\";\nimport {\n BaseMigrationExecutor,\n createUniqueIndex,\n dropUniqueIndex,\n type ExecuteNode,\n} from \"./execute-base\";\n\nconst errors = {\n IdColumnUpdate:\n \"ID columns cannot be updated. Not every database supports updating primary keys and often requires workarounds.\",\n SQLiteUpdateColumn: \"SQLite doesn't support updating columns. Recreate the table instead.\",\n SQLiteUpdateForeignKeys:\n \"SQLite doesn't support modifying foreign keys directly. Use `recreate-table` instead.\",\n} as const;\n\n/**\n * SQLite-specific migration executor.\n * Handles SQLite's limitations around foreign keys and column updates.\n */\nexport class SqliteMigrationExecutor extends BaseMigrationExecutor<SqliteCreateTableMetadata> {\n /**\n * SQLite preprocessing: merge add-foreign-key operations into create-table operations\n * when both exist in the same batch.\n *\n * SQLite requires foreign keys to be defined at table creation time. This preprocessing\n * step identifies create-table + add-foreign-key pairs and merges them.\n */\n preprocessOperations(\n operations: MigrationOperation[],\n ): MigrationOperation<SqliteCreateTableMetadata>[] {\n const result: MigrationOperation<SqliteCreateTableMetadata>[] = [];\n const createTableIndices = new Map<string, number>(); // table name -> index in result\n const foreignKeysByTable = new Map<string, (typeof operations)[number][]>();\n\n // First pass: identify create-table operations and collect foreign keys\n for (const op of operations) {\n if (op.type === \"create-table\") {\n createTableIndices.set(op.name, result.length);\n result.push(op);\n } else if (op.type === \"add-foreign-key\") {\n if (!foreignKeysByTable.has(op.table)) {\n foreignKeysByTable.set(op.table, []);\n }\n foreignKeysByTable.get(op.table)!.push(op);\n } else {\n result.push(op);\n }\n }\n\n // Second pass: attach foreign keys as metadata to create-table ops\n for (const [tableName, fkOps] of foreignKeysByTable.entries()) {\n const createTableIdx = createTableIndices.get(tableName);\n\n if (createTableIdx !== undefined) {\n // Table is being created in this batch - attach FKs as metadata\n const createOp = result[createTableIdx];\n if (createOp.type === \"create-table\") {\n result[createTableIdx] = {\n ...createOp,\n metadata: {\n ...createOp.metadata,\n inlineForeignKeys: fkOps.map((fkOp) => {\n if (fkOp.type === \"add-foreign-key\") {\n return fkOp.value;\n }\n throw new Error(\"Unexpected operation type\");\n }),\n },\n };\n }\n } else {\n // Table already exists - keep add-foreign-key operations (will throw error during execution)\n result.push(...fkOps);\n }\n }\n\n return result;\n }\n\n executeOperation(\n operation: MigrationOperation<SqliteCreateTableMetadata>,\n mapper?: TableNameMapper,\n ): ExecuteNode | ExecuteNode[] {\n switch (operation.type) {\n case \"create-table\":\n return this.createTable(operation, mapper);\n case \"rename-table\":\n return this.renameTable(operation, mapper);\n case \"alter-table\":\n return this.alterTable(operation, mapper);\n case \"drop-table\":\n return this.dropTable(operation, mapper);\n case \"add-foreign-key\":\n throw new Error(errors.SQLiteUpdateForeignKeys);\n case \"drop-foreign-key\":\n throw new Error(errors.SQLiteUpdateForeignKeys);\n case \"add-index\":\n return this.addIndex(operation, mapper);\n case \"drop-index\":\n return this.dropIndex(operation, mapper);\n case \"custom\":\n return this.handleCustomOperation(operation);\n }\n }\n\n private createTable(\n operation: Extract<MigrationOperation<SqliteCreateTableMetadata>, { type: \"create-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.name, mapper);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let builder: any = this.db.schema.createTable(tableName);\n\n // Add columns\n for (const columnInfo of operation.columns) {\n builder = builder.addColumn(\n columnInfo.name,\n sql.raw(this.getDBType(columnInfo)),\n this.getColumnBuilderCallback(columnInfo),\n );\n }\n\n // Add inline foreign keys from metadata (SQLite-specific)\n const inlineForeignKeys = operation.metadata?.inlineForeignKeys;\n if (inlineForeignKeys) {\n for (const fk of inlineForeignKeys) {\n builder = builder.addForeignKeyConstraint(\n fk.name,\n fk.columns,\n this.getTableName(fk.referencedTable, mapper),\n fk.referencedColumns,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (cb: any) => cb.onUpdate(\"restrict\").onDelete(\"restrict\"),\n );\n }\n }\n\n return builder;\n }\n\n private renameTable(\n operation: Extract<MigrationOperation, { type: \"rename-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema\n .alterTable(this.getTableName(operation.from, mapper))\n .renameTo(this.getTableName(operation.to, mapper));\n }\n\n private alterTable(\n operation: Extract<MigrationOperation, { type: \"alter-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode[] {\n const results: ExecuteNode[] = [];\n const tableName = this.getTableName(operation.name, mapper);\n\n for (const columnOp of operation.value) {\n results.push(...this.executeColumnOperation(tableName, columnOp));\n }\n\n return results;\n }\n\n private executeColumnOperation(tableName: string, operation: ColumnOperation): ExecuteNode[] {\n const next = () => this.db.schema.alterTable(tableName);\n const results: ExecuteNode[] = [];\n\n switch (operation.type) {\n case \"rename-column\":\n results.push(next().renameColumn(operation.from, operation.to));\n return results;\n\n case \"drop-column\":\n results.push(next().dropColumn(operation.name));\n return results;\n\n case \"create-column\": {\n const col = operation.value;\n results.push(\n next().addColumn(\n col.name,\n sql.raw(this.getDBType(col)),\n this.getColumnBuilderCallback(col),\n ),\n );\n return results;\n }\n\n case \"update-column\": {\n const col = operation.value;\n // Check for ID columns first to provide a more specific error message\n if (col.role === \"external-id\" || col.role === \"internal-id\") {\n throw new Error(errors.IdColumnUpdate);\n }\n throw new Error(errors.SQLiteUpdateColumn);\n }\n }\n }\n\n private dropTable(\n operation: Extract<MigrationOperation, { type: \"drop-table\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n return this.db.schema.dropTable(this.getTableName(operation.name, mapper));\n }\n\n private addIndex(\n operation: Extract<MigrationOperation, { type: \"add-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n\n if (operation.unique) {\n return createUniqueIndex(\n this.db,\n operation.name,\n tableName,\n operation.columns,\n this.provider,\n );\n }\n\n return this.db.schema.createIndex(operation.name).on(tableName).columns(operation.columns);\n }\n\n private dropIndex(\n operation: Extract<MigrationOperation, { type: \"drop-index\" }>,\n mapper?: TableNameMapper,\n ): ExecuteNode {\n const tableName = this.getTableName(operation.table, mapper);\n return dropUniqueIndex(this.db, operation.name, tableName, this.provider);\n }\n\n private handleCustomOperation(\n operation: Extract<MigrationOperation, { type: \"custom\" }>,\n ): ExecuteNode {\n const statement = sql.raw(operation[\"sql\"] as string);\n return this.rawToNode(statement);\n }\n}\n"],"mappings":";;;;AAcA,MAAM,SAAS;CACb,gBACE;CACF,oBAAoB;CACpB,yBACE;CACH;;;;;AAMD,IAAa,0BAAb,cAA6C,sBAAiD;;;;;;;;CAQ5F,qBACE,YACiD;EACjD,MAAMA,SAA0D,EAAE;EAClE,MAAM,qCAAqB,IAAI,KAAqB;EACpD,MAAM,qCAAqB,IAAI,KAA4C;AAG3E,OAAK,MAAM,MAAM,WACf,KAAI,GAAG,SAAS,gBAAgB;AAC9B,sBAAmB,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