drizzle-kit 0.20.14-a77266f → 0.20.14-c82ab68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. package/bin.cjs +7311 -7010
  2. package/cli/commands/migrate.d.ts +24 -24
  3. package/cli/commands/mysqlIntrospect.d.ts +8 -8
  4. package/cli/commands/mysqlPushUtils.d.ts +2 -2
  5. package/cli/commands/mysqlUp.d.ts +2 -2
  6. package/cli/commands/pgConnect.d.ts +1 -1
  7. package/cli/commands/pgIntrospect.d.ts +12 -9
  8. package/cli/commands/pgPushUtils.d.ts +2 -2
  9. package/cli/commands/pgUp.d.ts +2 -2
  10. package/cli/commands/sqliteIntrospect.d.ts +9 -9
  11. package/cli/commands/sqlitePushUtils.d.ts +3 -3
  12. package/cli/commands/upFolders.d.ts +1 -1
  13. package/cli/commands/utils.d.ts +14 -259
  14. package/cli/validations/cli.d.ts +104 -0
  15. package/cli/validations/common.d.ts +205 -7
  16. package/cli/validations/mysql.d.ts +6 -1
  17. package/cli/validations/pg.d.ts +6 -1
  18. package/cli/validations/sqlite.d.ts +382 -0
  19. package/cli/views.d.ts +1 -1
  20. package/global.d.ts +1 -1
  21. package/index.d.mts +8 -6
  22. package/index.d.ts +8 -6
  23. package/index.js +1 -0
  24. package/introspect-mysql.d.ts +1 -1
  25. package/introspect-pg.d.ts +5 -2
  26. package/introspect-sqlite.d.ts +1 -1
  27. package/jsonStatements.d.ts +1 -1
  28. package/package.json +3 -1
  29. package/payload.js +2574 -1898
  30. package/payload.mjs +2570 -1895
  31. package/schemaValidator.d.ts +40 -40
  32. package/serializer/mysqlSchema.d.ts +1991 -753
  33. package/serializer/mysqlSerializer.d.ts +2 -2
  34. package/serializer/pgSchema.d.ts +1113 -788
  35. package/serializer/sqliteSchema.d.ts +144 -570
  36. package/serializer/sqliteSerializer.d.ts +2 -2
  37. package/snapshotsDiffer.d.ts +24 -20
  38. package/utils-studio.js +390 -15
  39. package/utils-studio.mjs +389 -15
  40. package/utils.d.ts +12 -12
  41. package/utils.js +849 -735
  42. package/utils.mjs +849 -736
  43. package/cli/commands/sqliteUtils.d.ts +0 -162
package/utils.mjs CHANGED
@@ -1080,6 +1080,7 @@ var require_hanji = __commonJS({
1080
1080
  var import_hanji, info;
1081
1081
  var init_views = __esm({
1082
1082
  "src/cli/views.ts"() {
1083
+ "use strict";
1083
1084
  init_source();
1084
1085
  import_hanji = __toESM(require_hanji());
1085
1086
  info = (msg, greyMsg = "") => {
@@ -1088,6 +1089,26 @@ var init_views = __esm({
1088
1089
  }
1089
1090
  });
1090
1091
 
1092
+ // src/global.ts
1093
+ function assertUnreachable(x) {
1094
+ throw new Error("Didn't expect to get here");
1095
+ }
1096
+ var originUUID, snapshotVersion, mapValues;
1097
+ var init_global = __esm({
1098
+ "src/global.ts"() {
1099
+ "use strict";
1100
+ originUUID = "00000000-0000-0000-0000-000000000000";
1101
+ snapshotVersion = "6";
1102
+ mapValues = (obj, map) => {
1103
+ const result = Object.keys(obj).reduce(function(result2, key) {
1104
+ result2[key] = map(obj[key]);
1105
+ return result2;
1106
+ }, {});
1107
+ return result;
1108
+ };
1109
+ }
1110
+ });
1111
+
1091
1112
  // node_modules/.pnpm/zod@3.20.2/node_modules/zod/lib/index.mjs
1092
1113
  function getErrorMap() {
1093
1114
  return overrideErrorMap;
@@ -4227,734 +4248,778 @@ var init_lib = __esm({
4227
4248
  }
4228
4249
  });
4229
4250
 
4230
- // src/serializer/index.ts
4231
- import * as glob from "glob";
4232
- var init_serializer = __esm({
4233
- "src/serializer/index.ts"() {
4234
- init_source();
4235
- init_views();
4236
- }
4237
- });
4238
-
4239
- // src/cli/validations/outputs.ts
4240
- var init_outputs = __esm({
4241
- "src/cli/validations/outputs.ts"() {
4242
- init_source();
4243
- }
4244
- });
4245
-
4246
- // src/utils.ts
4247
- init_views();
4248
- import {
4249
- existsSync,
4250
- mkdirSync,
4251
- readdirSync,
4252
- readFileSync,
4253
- writeFileSync
4254
- } from "fs";
4255
-
4256
- // src/global.ts
4257
- var originUUID = "00000000-0000-0000-0000-000000000000";
4258
- var snapshotVersion = "5";
4259
- var mapValues = (obj, map) => {
4260
- const result = Object.keys(obj).reduce(function(result2, key) {
4261
- result2[key] = map(obj[key]);
4262
- return result2;
4263
- }, {});
4264
- return result;
4265
- };
4266
-
4267
4251
  // src/serializer/mysqlSchema.ts
4268
- init_lib();
4269
- var index = objectType({
4270
- name: stringType(),
4271
- columns: stringType().array(),
4272
- isUnique: booleanType(),
4273
- using: enumType(["btree", "hash"]).optional(),
4274
- algorithm: enumType(["default", "inplace", "copy"]).optional(),
4275
- lock: enumType(["default", "none", "shared", "exclusive"]).optional()
4276
- }).strict();
4277
- var fk = objectType({
4278
- name: stringType(),
4279
- tableFrom: stringType(),
4280
- columnsFrom: stringType().array(),
4281
- tableTo: stringType(),
4282
- columnsTo: stringType().array(),
4283
- onUpdate: stringType().optional(),
4284
- onDelete: stringType().optional()
4285
- }).strict();
4286
- var column = objectType({
4287
- name: stringType(),
4288
- type: stringType(),
4289
- primaryKey: booleanType(),
4290
- notNull: booleanType(),
4291
- autoincrement: booleanType().optional(),
4292
- default: anyType().optional(),
4293
- onUpdate: anyType().optional()
4294
- }).strict();
4295
- var tableV3 = objectType({
4296
- name: stringType(),
4297
- columns: recordType(stringType(), column),
4298
- indexes: recordType(stringType(), index),
4299
- foreignKeys: recordType(stringType(), fk)
4300
- }).strict();
4301
- var compositePK = objectType({
4302
- name: stringType(),
4303
- columns: stringType().array()
4304
- }).strict();
4305
- var uniqueConstraint = objectType({
4306
- name: stringType(),
4307
- columns: stringType().array()
4308
- }).strict();
4309
- var tableV4 = objectType({
4310
- name: stringType(),
4311
- schema: stringType().optional(),
4312
- columns: recordType(stringType(), column),
4313
- indexes: recordType(stringType(), index),
4314
- foreignKeys: recordType(stringType(), fk)
4315
- }).strict();
4316
- var table = objectType({
4317
- name: stringType(),
4318
- schema: stringType().optional(),
4319
- columns: recordType(stringType(), column),
4320
- indexes: recordType(stringType(), index),
4321
- foreignKeys: recordType(stringType(), fk),
4322
- compositePrimaryKeys: recordType(stringType(), compositePK),
4323
- uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
4324
- }).strict();
4325
- var dialect = literalType("mysql");
4326
- var schemaHash = objectType({
4327
- id: stringType(),
4328
- prevId: stringType()
4329
- });
4330
- var schemaInternalV3 = objectType({
4331
- version: literalType("3"),
4332
- dialect,
4333
- tables: recordType(stringType(), tableV3)
4334
- }).strict();
4335
- var schemaInternalV4 = objectType({
4336
- version: literalType("4"),
4337
- dialect,
4338
- tables: recordType(stringType(), tableV4),
4339
- schemas: recordType(stringType(), stringType())
4340
- }).strict();
4341
- var kitInternals = objectType({
4342
- tables: recordType(
4343
- stringType(),
4344
- objectType({
4345
- columns: recordType(
4252
+ var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternalV6, schemaInternal, schemaV3, schemaV4, schemaV5, schema, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, mysqlSchema, mysqlSchemaV5, backwardCompatibleMysqlSchema, dryMySql;
4253
+ var init_mysqlSchema = __esm({
4254
+ "src/serializer/mysqlSchema.ts"() {
4255
+ "use strict";
4256
+ init_global();
4257
+ init_lib();
4258
+ index = objectType({
4259
+ name: stringType(),
4260
+ columns: stringType().array(),
4261
+ isUnique: booleanType(),
4262
+ using: enumType(["btree", "hash"]).optional(),
4263
+ algorithm: enumType(["default", "inplace", "copy"]).optional(),
4264
+ lock: enumType(["default", "none", "shared", "exclusive"]).optional()
4265
+ }).strict();
4266
+ fk = objectType({
4267
+ name: stringType(),
4268
+ tableFrom: stringType(),
4269
+ columnsFrom: stringType().array(),
4270
+ tableTo: stringType(),
4271
+ columnsTo: stringType().array(),
4272
+ onUpdate: stringType().optional(),
4273
+ onDelete: stringType().optional()
4274
+ }).strict();
4275
+ column = objectType({
4276
+ name: stringType(),
4277
+ type: stringType(),
4278
+ primaryKey: booleanType(),
4279
+ notNull: booleanType(),
4280
+ autoincrement: booleanType().optional(),
4281
+ default: anyType().optional(),
4282
+ onUpdate: anyType().optional()
4283
+ }).strict();
4284
+ tableV3 = objectType({
4285
+ name: stringType(),
4286
+ columns: recordType(stringType(), column),
4287
+ indexes: recordType(stringType(), index),
4288
+ foreignKeys: recordType(stringType(), fk)
4289
+ }).strict();
4290
+ compositePK = objectType({
4291
+ name: stringType(),
4292
+ columns: stringType().array()
4293
+ }).strict();
4294
+ uniqueConstraint = objectType({
4295
+ name: stringType(),
4296
+ columns: stringType().array()
4297
+ }).strict();
4298
+ tableV4 = objectType({
4299
+ name: stringType(),
4300
+ schema: stringType().optional(),
4301
+ columns: recordType(stringType(), column),
4302
+ indexes: recordType(stringType(), index),
4303
+ foreignKeys: recordType(stringType(), fk)
4304
+ }).strict();
4305
+ table = objectType({
4306
+ name: stringType(),
4307
+ schema: stringType().optional(),
4308
+ columns: recordType(stringType(), column),
4309
+ indexes: recordType(stringType(), index),
4310
+ foreignKeys: recordType(stringType(), fk),
4311
+ compositePrimaryKeys: recordType(stringType(), compositePK),
4312
+ uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
4313
+ }).strict();
4314
+ kitInternals = objectType({
4315
+ tables: recordType(
4346
4316
  stringType(),
4347
- objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
4317
+ objectType({
4318
+ columns: recordType(
4319
+ stringType(),
4320
+ objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
4321
+ )
4322
+ }).optional()
4348
4323
  )
4349
- }).optional()
4350
- )
4351
- }).optional();
4352
- var schemaInternal = objectType({
4353
- version: literalType("5"),
4354
- dialect,
4355
- tables: recordType(stringType(), table),
4356
- schemas: recordType(stringType(), stringType()),
4357
- _meta: objectType({
4358
- schemas: recordType(stringType(), stringType()),
4359
- tables: recordType(stringType(), stringType()),
4360
- columns: recordType(stringType(), stringType())
4361
- }),
4362
- internal: kitInternals
4363
- }).strict();
4364
- var schemaV3 = schemaInternalV3.merge(schemaHash);
4365
- var schemaV4 = schemaInternalV4.merge(schemaHash);
4366
- var schema = schemaInternal.merge(schemaHash);
4367
- var tableSquashedV4 = objectType({
4368
- name: stringType(),
4369
- schema: stringType().optional(),
4370
- columns: recordType(stringType(), column),
4371
- indexes: recordType(stringType(), stringType()),
4372
- foreignKeys: recordType(stringType(), stringType())
4373
- }).strict();
4374
- var tableSquashed = objectType({
4375
- name: stringType(),
4376
- schema: stringType().optional(),
4377
- columns: recordType(stringType(), column),
4378
- indexes: recordType(stringType(), stringType()),
4379
- foreignKeys: recordType(stringType(), stringType()),
4380
- compositePrimaryKeys: recordType(stringType(), stringType()),
4381
- uniqueConstraints: recordType(stringType(), stringType()).default({})
4382
- }).strict();
4383
- var schemaSquashed = objectType({
4384
- version: literalType("5"),
4385
- dialect,
4386
- tables: recordType(stringType(), tableSquashed),
4387
- schemas: recordType(stringType(), stringType())
4388
- }).strict();
4389
- var schemaSquashedV4 = objectType({
4390
- version: literalType("4"),
4391
- dialect,
4392
- tables: recordType(stringType(), tableSquashedV4),
4393
- schemas: recordType(stringType(), stringType())
4394
- }).strict();
4395
- var MySqlSquasher = {
4396
- squashIdx: (idx) => {
4397
- index.parse(idx);
4398
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.using ?? ""};${idx.algorithm ?? ""};${idx.lock ?? ""}`;
4399
- },
4400
- unsquashIdx: (input) => {
4401
- const [name, columnsString, isUnique, using, algorithm, lock] = input.split(";");
4402
- const destructed = {
4403
- name,
4404
- columns: columnsString.split(","),
4405
- isUnique: isUnique === "true",
4406
- using: using ? using : void 0,
4407
- algorithm: algorithm ? algorithm : void 0,
4408
- lock: lock ? lock : void 0
4409
- };
4410
- return index.parse(destructed);
4411
- },
4412
- squashPK: (pk) => {
4413
- return `${pk.name};${pk.columns.join(",")}`;
4414
- },
4415
- unsquashPK: (pk) => {
4416
- const splitted = pk.split(";");
4417
- return { name: splitted[0], columns: splitted[1].split(",") };
4418
- },
4419
- squashUnique: (unq) => {
4420
- return `${unq.name};${unq.columns.join(",")}`;
4421
- },
4422
- unsquashUnique: (unq) => {
4423
- const [name, columns] = unq.split(";");
4424
- return { name, columns: columns.split(",") };
4425
- },
4426
- squashFK: (fk4) => {
4427
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4428
- },
4429
- unsquashFK: (input) => {
4430
- const [
4431
- name,
4432
- tableFrom,
4433
- columnsFromStr,
4434
- tableTo,
4435
- columnsToStr,
4436
- onUpdate,
4437
- onDelete
4438
- ] = input.split(";");
4439
- const result = fk.parse({
4440
- name,
4441
- tableFrom,
4442
- columnsFrom: columnsFromStr.split(","),
4443
- tableTo,
4444
- columnsTo: columnsToStr.split(","),
4445
- onUpdate,
4446
- onDelete
4324
+ }).optional();
4325
+ dialect = literalType("mysql");
4326
+ schemaHash = objectType({
4327
+ id: stringType(),
4328
+ prevId: stringType()
4329
+ });
4330
+ schemaInternalV3 = objectType({
4331
+ version: literalType("3"),
4332
+ dialect,
4333
+ tables: recordType(stringType(), tableV3)
4334
+ }).strict();
4335
+ schemaInternalV4 = objectType({
4336
+ version: literalType("4"),
4337
+ dialect,
4338
+ tables: recordType(stringType(), tableV4),
4339
+ schemas: recordType(stringType(), stringType())
4340
+ }).strict();
4341
+ schemaInternalV5 = objectType({
4342
+ version: literalType("5"),
4343
+ dialect,
4344
+ tables: recordType(stringType(), table),
4345
+ schemas: recordType(stringType(), stringType()),
4346
+ _meta: objectType({
4347
+ schemas: recordType(stringType(), stringType()),
4348
+ tables: recordType(stringType(), stringType()),
4349
+ columns: recordType(stringType(), stringType())
4350
+ }),
4351
+ internal: kitInternals
4352
+ }).strict();
4353
+ schemaInternalV6 = objectType({
4354
+ version: literalType("6"),
4355
+ dialect,
4356
+ tables: recordType(stringType(), table),
4357
+ schemas: recordType(stringType(), stringType()),
4358
+ _meta: objectType({
4359
+ schemas: recordType(stringType(), stringType()),
4360
+ tables: recordType(stringType(), stringType()),
4361
+ columns: recordType(stringType(), stringType())
4362
+ }),
4363
+ internal: kitInternals
4364
+ }).strict();
4365
+ schemaInternal = objectType({
4366
+ version: literalType("6"),
4367
+ dialect,
4368
+ tables: recordType(stringType(), table),
4369
+ schemas: recordType(stringType(), stringType()),
4370
+ _meta: objectType({
4371
+ schemas: recordType(stringType(), stringType()),
4372
+ tables: recordType(stringType(), stringType()),
4373
+ columns: recordType(stringType(), stringType())
4374
+ }),
4375
+ internal: kitInternals
4376
+ }).strict();
4377
+ schemaV3 = schemaInternalV3.merge(schemaHash);
4378
+ schemaV4 = schemaInternalV4.merge(schemaHash);
4379
+ schemaV5 = schemaInternalV5.merge(schemaHash);
4380
+ schema = schemaInternal.merge(schemaHash);
4381
+ tableSquashedV4 = objectType({
4382
+ name: stringType(),
4383
+ schema: stringType().optional(),
4384
+ columns: recordType(stringType(), column),
4385
+ indexes: recordType(stringType(), stringType()),
4386
+ foreignKeys: recordType(stringType(), stringType())
4387
+ }).strict();
4388
+ tableSquashed = objectType({
4389
+ name: stringType(),
4390
+ schema: stringType().optional(),
4391
+ columns: recordType(stringType(), column),
4392
+ indexes: recordType(stringType(), stringType()),
4393
+ foreignKeys: recordType(stringType(), stringType()),
4394
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4395
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4396
+ }).strict();
4397
+ schemaSquashed = objectType({
4398
+ version: literalType("5"),
4399
+ dialect,
4400
+ tables: recordType(stringType(), tableSquashed),
4401
+ schemas: recordType(stringType(), stringType())
4402
+ }).strict();
4403
+ schemaSquashedV4 = objectType({
4404
+ version: literalType("4"),
4405
+ dialect,
4406
+ tables: recordType(stringType(), tableSquashedV4),
4407
+ schemas: recordType(stringType(), stringType())
4408
+ }).strict();
4409
+ MySqlSquasher = {
4410
+ squashIdx: (idx) => {
4411
+ index.parse(idx);
4412
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.using ?? ""};${idx.algorithm ?? ""};${idx.lock ?? ""}`;
4413
+ },
4414
+ unsquashIdx: (input) => {
4415
+ const [name, columnsString, isUnique, using, algorithm, lock] = input.split(";");
4416
+ const destructed = {
4417
+ name,
4418
+ columns: columnsString.split(","),
4419
+ isUnique: isUnique === "true",
4420
+ using: using ? using : void 0,
4421
+ algorithm: algorithm ? algorithm : void 0,
4422
+ lock: lock ? lock : void 0
4423
+ };
4424
+ return index.parse(destructed);
4425
+ },
4426
+ squashPK: (pk) => {
4427
+ return `${pk.name};${pk.columns.join(",")}`;
4428
+ },
4429
+ unsquashPK: (pk) => {
4430
+ const splitted = pk.split(";");
4431
+ return { name: splitted[0], columns: splitted[1].split(",") };
4432
+ },
4433
+ squashUnique: (unq) => {
4434
+ return `${unq.name};${unq.columns.join(",")}`;
4435
+ },
4436
+ unsquashUnique: (unq) => {
4437
+ const [name, columns] = unq.split(";");
4438
+ return { name, columns: columns.split(",") };
4439
+ },
4440
+ squashFK: (fk4) => {
4441
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4442
+ },
4443
+ unsquashFK: (input) => {
4444
+ const [
4445
+ name,
4446
+ tableFrom,
4447
+ columnsFromStr,
4448
+ tableTo,
4449
+ columnsToStr,
4450
+ onUpdate,
4451
+ onDelete
4452
+ ] = input.split(";");
4453
+ const result = fk.parse({
4454
+ name,
4455
+ tableFrom,
4456
+ columnsFrom: columnsFromStr.split(","),
4457
+ tableTo,
4458
+ columnsTo: columnsToStr.split(","),
4459
+ onUpdate,
4460
+ onDelete
4461
+ });
4462
+ return result;
4463
+ }
4464
+ };
4465
+ mysqlSchema = schema;
4466
+ mysqlSchemaV5 = schemaV5;
4467
+ backwardCompatibleMysqlSchema = unionType([mysqlSchemaV5, schema]);
4468
+ dryMySql = mysqlSchema.parse({
4469
+ version: snapshotVersion,
4470
+ dialect: "mysql",
4471
+ id: originUUID,
4472
+ prevId: "",
4473
+ tables: {},
4474
+ schemas: {},
4475
+ _meta: {
4476
+ schemas: {},
4477
+ tables: {},
4478
+ columns: {}
4479
+ }
4447
4480
  });
4448
- return result;
4449
- }
4450
- };
4451
- var mysqlSchema = schema;
4452
- var backwardCompatibleMysqlSchema = unionType([
4453
- schemaV3,
4454
- schemaV4,
4455
- schema
4456
- ]);
4457
- var dryMySql = mysqlSchema.parse({
4458
- version: snapshotVersion,
4459
- dialect: "mysql",
4460
- id: originUUID,
4461
- prevId: "",
4462
- tables: {},
4463
- schemas: {},
4464
- _meta: {
4465
- schemas: {},
4466
- tables: {},
4467
- columns: {}
4468
4481
  }
4469
4482
  });
4470
4483
 
4471
4484
  // src/serializer/pgSchema.ts
4472
- init_lib();
4473
- var indexV2 = objectType({
4474
- name: stringType(),
4475
- columns: recordType(
4476
- stringType(),
4477
- objectType({
4478
- name: stringType()
4479
- })
4480
- ),
4481
- isUnique: booleanType()
4482
- }).strict();
4483
- var columnV2 = objectType({
4484
- name: stringType(),
4485
- type: stringType(),
4486
- primaryKey: booleanType(),
4487
- notNull: booleanType(),
4488
- default: anyType().optional(),
4489
- references: stringType().optional()
4490
- }).strict();
4491
- var tableV2 = objectType({
4492
- name: stringType(),
4493
- columns: recordType(stringType(), columnV2),
4494
- indexes: recordType(stringType(), indexV2)
4495
- }).strict();
4496
- var enumSchema = objectType({
4497
- name: stringType(),
4498
- values: recordType(stringType(), stringType())
4499
- }).strict();
4500
- var pgSchemaV2 = objectType({
4501
- version: literalType("2"),
4502
- tables: recordType(stringType(), tableV2),
4503
- enums: recordType(stringType(), enumSchema)
4504
- }).strict();
4505
- var references = objectType({
4506
- foreignKeyName: stringType(),
4507
- table: stringType(),
4508
- column: stringType(),
4509
- onDelete: stringType().optional(),
4510
- onUpdate: stringType().optional()
4511
- }).strict();
4512
- var columnV1 = objectType({
4513
- name: stringType(),
4514
- type: stringType(),
4515
- primaryKey: booleanType(),
4516
- notNull: booleanType(),
4517
- default: anyType().optional(),
4518
- references: references.optional()
4519
- }).strict();
4520
- var tableV1 = objectType({
4521
- name: stringType(),
4522
- columns: recordType(stringType(), columnV1),
4523
- indexes: recordType(stringType(), indexV2)
4524
- }).strict();
4525
- var pgSchemaV1 = objectType({
4526
- version: literalType("1"),
4527
- tables: recordType(stringType(), tableV1),
4528
- enums: recordType(stringType(), enumSchema)
4529
- }).strict();
4530
- var index2 = objectType({
4531
- name: stringType(),
4532
- columns: stringType().array(),
4533
- isUnique: booleanType()
4534
- }).strict();
4535
- var fk2 = objectType({
4536
- name: stringType(),
4537
- tableFrom: stringType(),
4538
- columnsFrom: stringType().array(),
4539
- tableTo: stringType(),
4540
- schemaTo: stringType().optional(),
4541
- columnsTo: stringType().array(),
4542
- onUpdate: stringType().optional(),
4543
- onDelete: stringType().optional()
4544
- }).strict();
4545
- var column2 = objectType({
4546
- name: stringType(),
4547
- type: stringType(),
4548
- primaryKey: booleanType(),
4549
- notNull: booleanType(),
4550
- default: anyType().optional(),
4551
- isUnique: anyType().optional(),
4552
- uniqueName: stringType().optional(),
4553
- nullsNotDistinct: booleanType().optional()
4554
- }).strict();
4555
- var tableV32 = objectType({
4556
- name: stringType(),
4557
- columns: recordType(stringType(), column2),
4558
- indexes: recordType(stringType(), index2),
4559
- foreignKeys: recordType(stringType(), fk2)
4560
- }).strict();
4561
- var compositePK2 = objectType({
4562
- name: stringType(),
4563
- columns: stringType().array()
4564
- }).strict();
4565
- var uniqueConstraint2 = objectType({
4566
- name: stringType(),
4567
- columns: stringType().array(),
4568
- nullsNotDistinct: booleanType()
4569
- }).strict();
4570
- var tableV42 = objectType({
4571
- name: stringType(),
4572
- schema: stringType(),
4573
- columns: recordType(stringType(), column2),
4574
- indexes: recordType(stringType(), index2),
4575
- foreignKeys: recordType(stringType(), fk2)
4576
- }).strict();
4577
- var table2 = objectType({
4578
- name: stringType(),
4579
- schema: stringType(),
4580
- columns: recordType(stringType(), column2),
4581
- indexes: recordType(stringType(), index2),
4582
- foreignKeys: recordType(stringType(), fk2),
4583
- compositePrimaryKeys: recordType(stringType(), compositePK2),
4584
- uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
4585
- }).strict();
4586
- var schemaHash2 = objectType({
4587
- id: stringType(),
4588
- prevId: stringType()
4589
- });
4590
- var pgSchemaInternalV3 = objectType({
4591
- version: literalType("3"),
4592
- dialect: literalType("pg"),
4593
- tables: recordType(stringType(), tableV32),
4594
- enums: recordType(stringType(), enumSchema)
4595
- }).strict();
4596
- var pgSchemaInternalV4 = objectType({
4597
- version: literalType("4"),
4598
- dialect: literalType("pg"),
4599
- tables: recordType(stringType(), tableV42),
4600
- enums: recordType(stringType(), enumSchema),
4601
- schemas: recordType(stringType(), stringType())
4602
- }).strict();
4603
- var pgSchemaExternal = objectType({
4604
- version: literalType("5"),
4605
- dialect: literalType("pg"),
4606
- tables: arrayType(table2),
4607
- enums: arrayType(enumSchema),
4608
- schemas: arrayType(objectType({ name: stringType() })),
4609
- _meta: objectType({
4610
- schemas: recordType(stringType(), stringType()),
4611
- tables: recordType(stringType(), stringType()),
4612
- columns: recordType(stringType(), stringType())
4613
- })
4614
- }).strict();
4615
- var kitInternals2 = objectType({
4616
- tables: recordType(
4617
- stringType(),
4618
- objectType({
4485
+ var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaExternal, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
4486
+ var init_pgSchema = __esm({
4487
+ "src/serializer/pgSchema.ts"() {
4488
+ "use strict";
4489
+ init_global();
4490
+ init_lib();
4491
+ indexV2 = objectType({
4492
+ name: stringType(),
4619
4493
  columns: recordType(
4620
4494
  stringType(),
4621
4495
  objectType({
4622
- isArray: booleanType().optional(),
4623
- dimensions: numberType().optional(),
4624
- rawType: stringType().optional()
4496
+ name: stringType()
4497
+ })
4498
+ ),
4499
+ isUnique: booleanType()
4500
+ }).strict();
4501
+ columnV2 = objectType({
4502
+ name: stringType(),
4503
+ type: stringType(),
4504
+ primaryKey: booleanType(),
4505
+ notNull: booleanType(),
4506
+ default: anyType().optional(),
4507
+ references: stringType().optional()
4508
+ }).strict();
4509
+ tableV2 = objectType({
4510
+ name: stringType(),
4511
+ columns: recordType(stringType(), columnV2),
4512
+ indexes: recordType(stringType(), indexV2)
4513
+ }).strict();
4514
+ enumSchema = objectType({
4515
+ name: stringType(),
4516
+ values: recordType(stringType(), stringType())
4517
+ }).strict();
4518
+ pgSchemaV2 = objectType({
4519
+ version: literalType("2"),
4520
+ tables: recordType(stringType(), tableV2),
4521
+ enums: recordType(stringType(), enumSchema)
4522
+ }).strict();
4523
+ references = objectType({
4524
+ foreignKeyName: stringType(),
4525
+ table: stringType(),
4526
+ column: stringType(),
4527
+ onDelete: stringType().optional(),
4528
+ onUpdate: stringType().optional()
4529
+ }).strict();
4530
+ columnV1 = objectType({
4531
+ name: stringType(),
4532
+ type: stringType(),
4533
+ primaryKey: booleanType(),
4534
+ notNull: booleanType(),
4535
+ default: anyType().optional(),
4536
+ references: references.optional()
4537
+ }).strict();
4538
+ tableV1 = objectType({
4539
+ name: stringType(),
4540
+ columns: recordType(stringType(), columnV1),
4541
+ indexes: recordType(stringType(), indexV2)
4542
+ }).strict();
4543
+ pgSchemaV1 = objectType({
4544
+ version: literalType("1"),
4545
+ tables: recordType(stringType(), tableV1),
4546
+ enums: recordType(stringType(), enumSchema)
4547
+ }).strict();
4548
+ index2 = objectType({
4549
+ name: stringType(),
4550
+ columns: stringType().array(),
4551
+ isUnique: booleanType()
4552
+ }).strict();
4553
+ fk2 = objectType({
4554
+ name: stringType(),
4555
+ tableFrom: stringType(),
4556
+ columnsFrom: stringType().array(),
4557
+ tableTo: stringType(),
4558
+ schemaTo: stringType().optional(),
4559
+ columnsTo: stringType().array(),
4560
+ onUpdate: stringType().optional(),
4561
+ onDelete: stringType().optional()
4562
+ }).strict();
4563
+ column2 = objectType({
4564
+ name: stringType(),
4565
+ type: stringType(),
4566
+ primaryKey: booleanType(),
4567
+ notNull: booleanType(),
4568
+ default: anyType().optional(),
4569
+ isUnique: anyType().optional(),
4570
+ uniqueName: stringType().optional(),
4571
+ nullsNotDistinct: booleanType().optional()
4572
+ }).strict();
4573
+ tableV32 = objectType({
4574
+ name: stringType(),
4575
+ columns: recordType(stringType(), column2),
4576
+ indexes: recordType(stringType(), index2),
4577
+ foreignKeys: recordType(stringType(), fk2)
4578
+ }).strict();
4579
+ compositePK2 = objectType({
4580
+ name: stringType(),
4581
+ columns: stringType().array()
4582
+ }).strict();
4583
+ uniqueConstraint2 = objectType({
4584
+ name: stringType(),
4585
+ columns: stringType().array(),
4586
+ nullsNotDistinct: booleanType()
4587
+ }).strict();
4588
+ tableV42 = objectType({
4589
+ name: stringType(),
4590
+ schema: stringType(),
4591
+ columns: recordType(stringType(), column2),
4592
+ indexes: recordType(stringType(), index2),
4593
+ foreignKeys: recordType(stringType(), fk2)
4594
+ }).strict();
4595
+ table2 = objectType({
4596
+ name: stringType(),
4597
+ schema: stringType(),
4598
+ columns: recordType(stringType(), column2),
4599
+ indexes: recordType(stringType(), index2),
4600
+ foreignKeys: recordType(stringType(), fk2),
4601
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
4602
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
4603
+ }).strict();
4604
+ schemaHash2 = objectType({
4605
+ id: stringType(),
4606
+ prevId: stringType()
4607
+ });
4608
+ kitInternals2 = objectType({
4609
+ tables: recordType(
4610
+ stringType(),
4611
+ objectType({
4612
+ columns: recordType(
4613
+ stringType(),
4614
+ objectType({
4615
+ isArray: booleanType().optional(),
4616
+ dimensions: numberType().optional(),
4617
+ rawType: stringType().optional()
4618
+ }).optional()
4619
+ )
4625
4620
  }).optional()
4626
4621
  )
4627
- }).optional()
4628
- )
4629
- }).optional();
4630
- var pgSchemaInternal = objectType({
4631
- version: literalType("5"),
4632
- dialect: literalType("pg"),
4633
- tables: recordType(stringType(), table2),
4634
- enums: recordType(stringType(), enumSchema),
4635
- schemas: recordType(stringType(), stringType()),
4636
- _meta: objectType({
4637
- schemas: recordType(stringType(), stringType()),
4638
- tables: recordType(stringType(), stringType()),
4639
- columns: recordType(stringType(), stringType())
4640
- }),
4641
- internal: kitInternals2
4642
- }).strict();
4643
- var tableSquashed2 = objectType({
4644
- name: stringType(),
4645
- schema: stringType(),
4646
- columns: recordType(stringType(), column2),
4647
- indexes: recordType(stringType(), stringType()),
4648
- foreignKeys: recordType(stringType(), stringType()),
4649
- compositePrimaryKeys: recordType(stringType(), stringType()),
4650
- uniqueConstraints: recordType(stringType(), stringType())
4651
- }).strict();
4652
- var tableSquashedV42 = objectType({
4653
- name: stringType(),
4654
- schema: stringType(),
4655
- columns: recordType(stringType(), column2),
4656
- indexes: recordType(stringType(), stringType()),
4657
- foreignKeys: recordType(stringType(), stringType())
4658
- }).strict();
4659
- var pgSchemaSquashedV4 = objectType({
4660
- version: literalType("4"),
4661
- dialect: enumType(["pg"]),
4662
- tables: recordType(stringType(), tableSquashedV42),
4663
- enums: recordType(stringType(), enumSchema),
4664
- schemas: recordType(stringType(), stringType())
4665
- }).strict();
4666
- var pgSchemaSquashed = objectType({
4667
- version: literalType("5"),
4668
- dialect: enumType(["pg"]),
4669
- tables: recordType(stringType(), tableSquashed2),
4670
- enums: recordType(stringType(), enumSchema),
4671
- schemas: recordType(stringType(), stringType())
4672
- }).strict();
4673
- var pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
4674
- var pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
4675
- var pgSchema = pgSchemaInternal.merge(schemaHash2);
4676
- var backwardCompatiblePgSchema = unionType([
4677
- pgSchemaV1,
4678
- pgSchemaV2,
4679
- pgSchemaV3,
4680
- pgSchemaV4,
4681
- pgSchema
4682
- ]);
4683
- var PgSquasher = {
4684
- squashIdx: (idx) => {
4685
- index2.parse(idx);
4686
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique}`;
4687
- },
4688
- unsquashIdx: (input) => {
4689
- const [name, columnsString, isUnique] = input.split(";");
4690
- const result = index2.parse({
4691
- name,
4692
- columns: columnsString.split(","),
4693
- isUnique: isUnique === "true"
4694
- });
4695
- return result;
4696
- },
4697
- squashFK: (fk4) => {
4698
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo ?? ""}`;
4699
- },
4700
- squashPK: (pk) => {
4701
- return `${pk.columns.join(",")};${pk.name}`;
4702
- },
4703
- unsquashPK: (pk) => {
4704
- const splitted = pk.split(";");
4705
- return { name: splitted[1], columns: splitted[0].split(",") };
4706
- },
4707
- squashUnique: (unq) => {
4708
- return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
4709
- },
4710
- unsquashUnique: (unq) => {
4711
- const [name, columns, nullsNotDistinct] = unq.split(";");
4712
- return {
4713
- name,
4714
- columns: columns.split(","),
4715
- nullsNotDistinct: nullsNotDistinct === "true"
4622
+ }).optional();
4623
+ pgSchemaInternalV3 = objectType({
4624
+ version: literalType("3"),
4625
+ dialect: literalType("pg"),
4626
+ tables: recordType(stringType(), tableV32),
4627
+ enums: recordType(stringType(), enumSchema)
4628
+ }).strict();
4629
+ pgSchemaInternalV4 = objectType({
4630
+ version: literalType("4"),
4631
+ dialect: literalType("pg"),
4632
+ tables: recordType(stringType(), tableV42),
4633
+ enums: recordType(stringType(), enumSchema),
4634
+ schemas: recordType(stringType(), stringType())
4635
+ }).strict();
4636
+ pgSchemaInternalV5 = objectType({
4637
+ version: literalType("5"),
4638
+ dialect: literalType("pg"),
4639
+ tables: recordType(stringType(), table2),
4640
+ enums: recordType(stringType(), enumSchema),
4641
+ schemas: recordType(stringType(), stringType()),
4642
+ _meta: objectType({
4643
+ schemas: recordType(stringType(), stringType()),
4644
+ tables: recordType(stringType(), stringType()),
4645
+ columns: recordType(stringType(), stringType())
4646
+ }),
4647
+ internal: kitInternals2
4648
+ }).strict();
4649
+ pgSchemaExternal = objectType({
4650
+ version: literalType("5"),
4651
+ dialect: literalType("pg"),
4652
+ tables: arrayType(table2),
4653
+ enums: arrayType(enumSchema),
4654
+ schemas: arrayType(objectType({ name: stringType() })),
4655
+ _meta: objectType({
4656
+ schemas: recordType(stringType(), stringType()),
4657
+ tables: recordType(stringType(), stringType()),
4658
+ columns: recordType(stringType(), stringType())
4659
+ })
4660
+ }).strict();
4661
+ pgSchemaInternal = objectType({
4662
+ version: literalType("6"),
4663
+ dialect: literalType("pg"),
4664
+ tables: recordType(stringType(), table2),
4665
+ enums: recordType(stringType(), enumSchema),
4666
+ schemas: recordType(stringType(), stringType()),
4667
+ _meta: objectType({
4668
+ schemas: recordType(stringType(), stringType()),
4669
+ tables: recordType(stringType(), stringType()),
4670
+ columns: recordType(stringType(), stringType())
4671
+ }),
4672
+ internal: kitInternals2
4673
+ }).strict();
4674
+ tableSquashed2 = objectType({
4675
+ name: stringType(),
4676
+ schema: stringType(),
4677
+ columns: recordType(stringType(), column2),
4678
+ indexes: recordType(stringType(), stringType()),
4679
+ foreignKeys: recordType(stringType(), stringType()),
4680
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4681
+ uniqueConstraints: recordType(stringType(), stringType())
4682
+ }).strict();
4683
+ tableSquashedV42 = objectType({
4684
+ name: stringType(),
4685
+ schema: stringType(),
4686
+ columns: recordType(stringType(), column2),
4687
+ indexes: recordType(stringType(), stringType()),
4688
+ foreignKeys: recordType(stringType(), stringType())
4689
+ }).strict();
4690
+ pgSchemaSquashedV4 = objectType({
4691
+ version: literalType("4"),
4692
+ dialect: enumType(["pg"]),
4693
+ tables: recordType(stringType(), tableSquashedV42),
4694
+ enums: recordType(stringType(), enumSchema),
4695
+ schemas: recordType(stringType(), stringType())
4696
+ }).strict();
4697
+ pgSchemaSquashed = objectType({
4698
+ version: literalType("6"),
4699
+ dialect: enumType(["pg"]),
4700
+ tables: recordType(stringType(), tableSquashed2),
4701
+ enums: recordType(stringType(), enumSchema),
4702
+ schemas: recordType(stringType(), stringType())
4703
+ }).strict();
4704
+ pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
4705
+ pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
4706
+ pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
4707
+ pgSchema = pgSchemaInternal.merge(schemaHash2);
4708
+ backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema]);
4709
+ PgSquasher = {
4710
+ squashIdx: (idx) => {
4711
+ index2.parse(idx);
4712
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique}`;
4713
+ },
4714
+ unsquashIdx: (input) => {
4715
+ const [name, columnsString, isUnique] = input.split(";");
4716
+ const result = index2.parse({
4717
+ name,
4718
+ columns: columnsString.split(","),
4719
+ isUnique: isUnique === "true"
4720
+ });
4721
+ return result;
4722
+ },
4723
+ squashFK: (fk4) => {
4724
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
4725
+ },
4726
+ squashPK: (pk) => {
4727
+ return `${pk.columns.join(",")};${pk.name}`;
4728
+ },
4729
+ unsquashPK: (pk) => {
4730
+ const splitted = pk.split(";");
4731
+ return { name: splitted[1], columns: splitted[0].split(",") };
4732
+ },
4733
+ squashUnique: (unq) => {
4734
+ return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
4735
+ },
4736
+ unsquashUnique: (unq) => {
4737
+ const [name, columns, nullsNotDistinct] = unq.split(";");
4738
+ return {
4739
+ name,
4740
+ columns: columns.split(","),
4741
+ nullsNotDistinct: nullsNotDistinct === "true"
4742
+ };
4743
+ },
4744
+ unsquashFK: (input) => {
4745
+ const [
4746
+ name,
4747
+ tableFrom,
4748
+ columnsFromStr,
4749
+ tableTo,
4750
+ columnsToStr,
4751
+ onUpdate,
4752
+ onDelete,
4753
+ schemaTo
4754
+ ] = input.split(";");
4755
+ const result = fk2.parse({
4756
+ name,
4757
+ tableFrom,
4758
+ columnsFrom: columnsFromStr.split(","),
4759
+ schemaTo,
4760
+ tableTo,
4761
+ columnsTo: columnsToStr.split(","),
4762
+ onUpdate,
4763
+ onDelete
4764
+ });
4765
+ return result;
4766
+ }
4716
4767
  };
4717
- },
4718
- unsquashFK: (input) => {
4719
- const [
4720
- name,
4721
- tableFrom,
4722
- columnsFromStr,
4723
- tableTo,
4724
- columnsToStr,
4725
- onUpdate,
4726
- onDelete,
4727
- schemaTo
4728
- ] = input.split(";");
4729
- const result = fk2.parse({
4730
- name,
4731
- tableFrom,
4732
- columnsFrom: columnsFromStr.split(","),
4733
- schemaTo,
4734
- tableTo,
4735
- columnsTo: columnsToStr.split(","),
4736
- onUpdate,
4737
- onDelete
4738
- });
4739
- return result;
4740
- }
4741
- };
4742
- var squashPgScheme = (json) => {
4743
- const mappedTables = Object.fromEntries(
4744
- Object.entries(json.tables).map((it) => {
4745
- const squashedIndexes = mapValues(it[1].indexes, (index4) => {
4746
- return PgSquasher.squashIdx(index4);
4747
- });
4748
- const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
4749
- return PgSquasher.squashFK(fk4);
4750
- });
4751
- const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
4752
- return PgSquasher.squashPK(pk);
4753
- });
4754
- const squashedUniqueConstraints = mapValues(
4755
- it[1].uniqueConstraints,
4756
- (unq) => {
4757
- return PgSquasher.squashUnique(unq);
4758
- }
4768
+ squashPgScheme = (json) => {
4769
+ const mappedTables = Object.fromEntries(
4770
+ Object.entries(json.tables).map((it) => {
4771
+ const squashedIndexes = mapValues(it[1].indexes, (index4) => {
4772
+ return PgSquasher.squashIdx(index4);
4773
+ });
4774
+ const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
4775
+ return PgSquasher.squashFK(fk4);
4776
+ });
4777
+ const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
4778
+ return PgSquasher.squashPK(pk);
4779
+ });
4780
+ const squashedUniqueConstraints = mapValues(
4781
+ it[1].uniqueConstraints,
4782
+ (unq) => {
4783
+ return PgSquasher.squashUnique(unq);
4784
+ }
4785
+ );
4786
+ return [
4787
+ it[0],
4788
+ {
4789
+ name: it[1].name,
4790
+ schema: it[1].schema,
4791
+ columns: it[1].columns,
4792
+ indexes: squashedIndexes,
4793
+ foreignKeys: squashedFKs,
4794
+ compositePrimaryKeys: squashedPKs,
4795
+ uniqueConstraints: squashedUniqueConstraints
4796
+ }
4797
+ ];
4798
+ })
4759
4799
  );
4760
- return [
4761
- it[0],
4762
- {
4763
- name: it[1].name,
4764
- schema: it[1].schema,
4765
- columns: it[1].columns,
4766
- indexes: squashedIndexes,
4767
- foreignKeys: squashedFKs,
4768
- compositePrimaryKeys: squashedPKs,
4769
- uniqueConstraints: squashedUniqueConstraints
4770
- }
4771
- ];
4772
- })
4773
- );
4774
- return {
4775
- version: "5",
4776
- dialect: json.dialect,
4777
- tables: mappedTables,
4778
- enums: json.enums,
4779
- schemas: json.schemas
4780
- };
4781
- };
4782
- var dryPg = pgSchema.parse({
4783
- version: snapshotVersion,
4784
- dialect: "pg",
4785
- id: originUUID,
4786
- prevId: "",
4787
- tables: {},
4788
- enums: {},
4789
- schemas: {},
4790
- _meta: {
4791
- schemas: {},
4792
- tables: {},
4793
- columns: {}
4800
+ return {
4801
+ version: "6",
4802
+ dialect: json.dialect,
4803
+ tables: mappedTables,
4804
+ enums: json.enums,
4805
+ schemas: json.schemas
4806
+ };
4807
+ };
4808
+ dryPg = pgSchema.parse({
4809
+ version: snapshotVersion,
4810
+ dialect: "pg",
4811
+ id: originUUID,
4812
+ prevId: "",
4813
+ tables: {},
4814
+ enums: {},
4815
+ schemas: {},
4816
+ _meta: {
4817
+ schemas: {},
4818
+ tables: {},
4819
+ columns: {}
4820
+ }
4821
+ });
4794
4822
  }
4795
4823
  });
4796
4824
 
4797
4825
  // src/serializer/sqliteSchema.ts
4798
- init_lib();
4799
- var index3 = objectType({
4800
- name: stringType(),
4801
- columns: stringType().array(),
4802
- where: stringType().optional(),
4803
- isUnique: booleanType()
4804
- }).strict();
4805
- var fk3 = objectType({
4806
- name: stringType(),
4807
- tableFrom: stringType(),
4808
- columnsFrom: stringType().array(),
4809
- tableTo: stringType(),
4810
- columnsTo: stringType().array(),
4811
- onUpdate: stringType().optional(),
4812
- onDelete: stringType().optional()
4813
- }).strict();
4814
- var compositePK3 = objectType({
4815
- columns: stringType().array(),
4816
- name: stringType().optional()
4817
- }).strict();
4818
- var column3 = objectType({
4819
- name: stringType(),
4820
- type: stringType(),
4821
- primaryKey: booleanType(),
4822
- notNull: booleanType(),
4823
- autoincrement: booleanType().optional(),
4824
- default: anyType().optional()
4825
- }).strict();
4826
- var tableV33 = objectType({
4827
- name: stringType(),
4828
- columns: recordType(stringType(), column3),
4829
- indexes: recordType(stringType(), index3),
4830
- foreignKeys: recordType(stringType(), fk3)
4831
- }).strict();
4832
- var uniqueConstraint3 = objectType({
4833
- name: stringType(),
4834
- columns: stringType().array()
4835
- }).strict();
4836
- var table3 = objectType({
4837
- name: stringType(),
4838
- columns: recordType(stringType(), column3),
4839
- indexes: recordType(stringType(), index3),
4840
- foreignKeys: recordType(stringType(), fk3),
4841
- compositePrimaryKeys: recordType(stringType(), compositePK3),
4842
- uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
4843
- }).strict();
4844
- var dialect2 = enumType(["sqlite"]);
4845
- var schemaHash3 = objectType({
4846
- id: stringType(),
4847
- prevId: stringType()
4848
- }).strict();
4849
- var schemaInternalV32 = objectType({
4850
- version: literalType("3"),
4851
- dialect: dialect2,
4852
- tables: recordType(stringType(), tableV33),
4853
- enums: objectType({})
4854
- }).strict();
4855
- var schemaInternalV42 = objectType({
4856
- version: literalType("4"),
4857
- dialect: dialect2,
4858
- tables: recordType(stringType(), table3),
4859
- enums: objectType({})
4860
- }).strict();
4861
- var latestVersion = literalType("5");
4862
- var schemaInternal2 = objectType({
4863
- version: latestVersion,
4864
- dialect: dialect2,
4865
- tables: recordType(stringType(), table3),
4866
- enums: objectType({}),
4867
- _meta: objectType({
4868
- tables: recordType(stringType(), stringType()),
4869
- columns: recordType(stringType(), stringType())
4870
- })
4871
- }).strict();
4872
- var schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
4873
- var schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
4874
- var schema2 = schemaInternal2.merge(schemaHash3).strict();
4875
- var tableSquashed3 = objectType({
4876
- name: stringType(),
4877
- columns: recordType(stringType(), column3),
4878
- indexes: recordType(stringType(), stringType()),
4879
- foreignKeys: recordType(stringType(), stringType()),
4880
- compositePrimaryKeys: recordType(stringType(), stringType()),
4881
- uniqueConstraints: recordType(stringType(), stringType()).default({})
4882
- }).strict();
4883
- var schemaSquashed2 = objectType({
4884
- version: latestVersion,
4885
- dialect: dialect2,
4886
- tables: recordType(stringType(), tableSquashed3),
4887
- enums: anyType()
4888
- }).strict();
4889
- var SQLiteSquasher = {
4890
- squashIdx: (idx) => {
4891
- index3.parse(idx);
4892
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.where ?? ""}`;
4893
- },
4894
- unsquashIdx: (input) => {
4895
- const [name, columnsString, isUnique, where] = input.split(";");
4896
- const result = index3.parse({
4897
- name,
4898
- columns: columnsString.split(","),
4899
- isUnique: isUnique === "true",
4900
- where: where ?? void 0
4901
- });
4902
- return result;
4903
- },
4904
- squashUnique: (unq) => {
4905
- return `${unq.name};${unq.columns.join(",")}`;
4906
- },
4907
- unsquashUnique: (unq) => {
4908
- const [name, columns] = unq.split(";");
4909
- return { name, columns: columns.split(",") };
4910
- },
4911
- squashFK: (fk4) => {
4912
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4913
- },
4914
- unsquashFK: (input) => {
4915
- const [
4916
- name,
4917
- tableFrom,
4918
- columnsFromStr,
4919
- tableTo,
4920
- columnsToStr,
4921
- onUpdate,
4922
- onDelete
4923
- ] = input.split(";");
4924
- const result = fk3.parse({
4925
- name,
4926
- tableFrom,
4927
- columnsFrom: columnsFromStr.split(","),
4928
- tableTo,
4929
- columnsTo: columnsToStr.split(","),
4930
- onUpdate,
4931
- onDelete
4826
+ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, drySQLite, backwardCompatibleSqliteSchema;
4827
+ var init_sqliteSchema = __esm({
4828
+ "src/serializer/sqliteSchema.ts"() {
4829
+ "use strict";
4830
+ init_global();
4831
+ init_lib();
4832
+ index3 = objectType({
4833
+ name: stringType(),
4834
+ columns: stringType().array(),
4835
+ where: stringType().optional(),
4836
+ isUnique: booleanType()
4837
+ }).strict();
4838
+ fk3 = objectType({
4839
+ name: stringType(),
4840
+ tableFrom: stringType(),
4841
+ columnsFrom: stringType().array(),
4842
+ tableTo: stringType(),
4843
+ columnsTo: stringType().array(),
4844
+ onUpdate: stringType().optional(),
4845
+ onDelete: stringType().optional()
4846
+ }).strict();
4847
+ compositePK3 = objectType({
4848
+ columns: stringType().array(),
4849
+ name: stringType().optional()
4850
+ }).strict();
4851
+ column3 = objectType({
4852
+ name: stringType(),
4853
+ type: stringType(),
4854
+ primaryKey: booleanType(),
4855
+ notNull: booleanType(),
4856
+ autoincrement: booleanType().optional(),
4857
+ default: anyType().optional()
4858
+ }).strict();
4859
+ tableV33 = objectType({
4860
+ name: stringType(),
4861
+ columns: recordType(stringType(), column3),
4862
+ indexes: recordType(stringType(), index3),
4863
+ foreignKeys: recordType(stringType(), fk3)
4864
+ }).strict();
4865
+ uniqueConstraint3 = objectType({
4866
+ name: stringType(),
4867
+ columns: stringType().array()
4868
+ }).strict();
4869
+ table3 = objectType({
4870
+ name: stringType(),
4871
+ columns: recordType(stringType(), column3),
4872
+ indexes: recordType(stringType(), index3),
4873
+ foreignKeys: recordType(stringType(), fk3),
4874
+ compositePrimaryKeys: recordType(stringType(), compositePK3),
4875
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
4876
+ }).strict();
4877
+ dialect2 = enumType(["sqlite"]);
4878
+ schemaHash3 = objectType({
4879
+ id: stringType(),
4880
+ prevId: stringType()
4881
+ }).strict();
4882
+ schemaInternalV32 = objectType({
4883
+ version: literalType("3"),
4884
+ dialect: dialect2,
4885
+ tables: recordType(stringType(), tableV33),
4886
+ enums: objectType({})
4887
+ }).strict();
4888
+ schemaInternalV42 = objectType({
4889
+ version: literalType("4"),
4890
+ dialect: dialect2,
4891
+ tables: recordType(stringType(), table3),
4892
+ enums: objectType({})
4893
+ }).strict();
4894
+ latestVersion = literalType("5");
4895
+ schemaInternal2 = objectType({
4896
+ version: latestVersion,
4897
+ dialect: dialect2,
4898
+ tables: recordType(stringType(), table3),
4899
+ enums: objectType({}),
4900
+ _meta: objectType({
4901
+ tables: recordType(stringType(), stringType()),
4902
+ columns: recordType(stringType(), stringType())
4903
+ })
4904
+ }).strict();
4905
+ schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
4906
+ schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
4907
+ schema2 = schemaInternal2.merge(schemaHash3).strict();
4908
+ tableSquashed3 = objectType({
4909
+ name: stringType(),
4910
+ columns: recordType(stringType(), column3),
4911
+ indexes: recordType(stringType(), stringType()),
4912
+ foreignKeys: recordType(stringType(), stringType()),
4913
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4914
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4915
+ }).strict();
4916
+ schemaSquashed2 = objectType({
4917
+ version: latestVersion,
4918
+ dialect: dialect2,
4919
+ tables: recordType(stringType(), tableSquashed3),
4920
+ enums: anyType()
4921
+ }).strict();
4922
+ SQLiteSquasher = {
4923
+ squashIdx: (idx) => {
4924
+ index3.parse(idx);
4925
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.where ?? ""}`;
4926
+ },
4927
+ unsquashIdx: (input) => {
4928
+ const [name, columnsString, isUnique, where] = input.split(";");
4929
+ const result = index3.parse({
4930
+ name,
4931
+ columns: columnsString.split(","),
4932
+ isUnique: isUnique === "true",
4933
+ where: where ?? void 0
4934
+ });
4935
+ return result;
4936
+ },
4937
+ squashUnique: (unq) => {
4938
+ return `${unq.name};${unq.columns.join(",")}`;
4939
+ },
4940
+ unsquashUnique: (unq) => {
4941
+ const [name, columns] = unq.split(";");
4942
+ return { name, columns: columns.split(",") };
4943
+ },
4944
+ squashFK: (fk4) => {
4945
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4946
+ },
4947
+ unsquashFK: (input) => {
4948
+ const [
4949
+ name,
4950
+ tableFrom,
4951
+ columnsFromStr,
4952
+ tableTo,
4953
+ columnsToStr,
4954
+ onUpdate,
4955
+ onDelete
4956
+ ] = input.split(";");
4957
+ const result = fk3.parse({
4958
+ name,
4959
+ tableFrom,
4960
+ columnsFrom: columnsFromStr.split(","),
4961
+ tableTo,
4962
+ columnsTo: columnsToStr.split(","),
4963
+ onUpdate,
4964
+ onDelete
4965
+ });
4966
+ return result;
4967
+ },
4968
+ squashPK: (pk) => {
4969
+ return pk.columns.join(",");
4970
+ },
4971
+ unsquashPK: (pk) => {
4972
+ return pk.split(",");
4973
+ }
4974
+ };
4975
+ drySQLite = schema2.parse({
4976
+ version: "5",
4977
+ dialect: "sqlite",
4978
+ id: originUUID,
4979
+ prevId: "",
4980
+ tables: {},
4981
+ enums: {},
4982
+ _meta: {
4983
+ tables: {},
4984
+ columns: {}
4985
+ }
4932
4986
  });
4933
- return result;
4934
- },
4935
- squashPK: (pk) => {
4936
- return pk.columns.join(",");
4937
- },
4938
- unsquashPK: (pk) => {
4939
- return pk.split(",");
4940
- }
4941
- };
4942
- var drySQLite = schema2.parse({
4943
- version: snapshotVersion,
4944
- dialect: "sqlite",
4945
- id: originUUID,
4946
- prevId: "",
4947
- tables: {},
4948
- enums: {},
4949
- _meta: {
4950
- tables: {},
4951
- columns: {}
4987
+ backwardCompatibleSqliteSchema = schema2;
4988
+ }
4989
+ });
4990
+
4991
+ // src/serializer/index.ts
4992
+ import * as glob from "glob";
4993
+ var init_serializer = __esm({
4994
+ "src/serializer/index.ts"() {
4995
+ "use strict";
4996
+ init_source();
4997
+ init_views();
4998
+ }
4999
+ });
5000
+
5001
+ // src/cli/validations/outputs.ts
5002
+ var init_outputs = __esm({
5003
+ "src/cli/validations/outputs.ts"() {
5004
+ "use strict";
5005
+ init_source();
4952
5006
  }
4953
5007
  });
4954
- var backwardCompatibleSqliteSchema = unionType([schemaV32, schemaV42, schema2]);
4955
5008
 
4956
5009
  // src/utils.ts
5010
+ init_views();
5011
+ init_mysqlSchema();
5012
+ init_pgSchema();
5013
+ init_sqliteSchema();
4957
5014
  init_source();
5015
+ init_global();
5016
+ import {
5017
+ existsSync,
5018
+ mkdirSync,
5019
+ readdirSync,
5020
+ readFileSync,
5021
+ writeFileSync
5022
+ } from "fs";
4958
5023
  import { join } from "path";
4959
5024
 
4960
5025
  // src/jsonDiffer.js
@@ -5197,17 +5262,30 @@ var alternationsInColumn = (column4) => {
5197
5262
  return result[0];
5198
5263
  };
5199
5264
 
5265
+ // src/cli/commands/upFolders.ts
5266
+ init_mysqlSchema();
5267
+ init_sqliteSchema();
5268
+
5200
5269
  // src/migrationPreparator.ts
5201
5270
  init_serializer();
5271
+ init_pgSchema();
5272
+ init_sqliteSchema();
5273
+ init_mysqlSchema();
5202
5274
 
5203
5275
  // src/cli/commands/migrate.ts
5204
5276
  var import_hanji2 = __toESM(require_hanji());
5205
5277
  init_views();
5206
5278
  init_source();
5279
+ init_pgSchema();
5280
+ init_sqliteSchema();
5281
+ init_mysqlSchema();
5207
5282
  init_outputs();
5208
5283
  var BREAKPOINT = "--> statement-breakpoint\n";
5209
5284
 
5210
5285
  // src/sqlgenerator.ts
5286
+ init_mysqlSchema();
5287
+ init_pgSchema();
5288
+ init_sqliteSchema();
5211
5289
  var pgNativeTypes = /* @__PURE__ */ new Set([
5212
5290
  "uuid",
5213
5291
  "smallint",
@@ -6519,17 +6597,20 @@ drop type __venum;
6519
6597
  init_lib();
6520
6598
 
6521
6599
  // src/jsonStatements.ts
6600
+ init_mysqlSchema();
6601
+ init_pgSchema();
6602
+ init_sqliteSchema();
6522
6603
  var preparePgCreateTableJson = (table4, json2) => {
6523
6604
  const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
6605
+ const tableKey = `${schema4 || "public"}.${name}`;
6606
+ const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
6524
6607
  return {
6525
6608
  type: "create_table",
6526
6609
  tableName: name,
6527
6610
  schema: schema4,
6528
6611
  columns: Object.values(columns),
6529
6612
  compositePKs: Object.values(compositePrimaryKeys),
6530
- compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${PgSquasher.unsquashPK(
6531
- Object.values(compositePrimaryKeys)[0]
6532
- ).name}`].name : "",
6613
+ compositePkName,
6533
6614
  uniqueConstraints: Object.values(uniqueConstraints)
6534
6615
  };
6535
6616
  };
@@ -6631,7 +6712,8 @@ var prepareRenameColumns = (tableName, schema4, pairs) => {
6631
6712
  var prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, json2, dialect3) => {
6632
6713
  const addColumns = [];
6633
6714
  const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
6634
- const alterColumns = _prepareAlterColumns(tableName, schema4, altered, json2);
6715
+ const tableKey = `${schema4 || "public"}.${tableName}`;
6716
+ const alterColumns = _prepareAlterColumns(tableKey, schema4, altered, json2);
6635
6717
  if (dialect3 === "sqlite") {
6636
6718
  let jsonCreateFKStatements = Object.values(addedFk);
6637
6719
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -6681,19 +6763,22 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
6681
6763
  };
6682
6764
  });
6683
6765
  };
6684
- var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
6766
+ var _prepareAlterColumns = (tableKey, schema4, columns, json2) => {
6685
6767
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
6686
6768
  let statements = [];
6687
6769
  let dropPkStatements = [];
6688
6770
  let setPkStatements = [];
6689
6771
  for (const column4 of columns) {
6690
6772
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
6691
- const columnType = json2.tables[tableName].columns[columnName].type;
6692
- const columnDefault = json2.tables[tableName].columns[columnName].default;
6693
- const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
6694
- const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
6695
- const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
6696
- const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
6773
+ const table4 = json2.tables[tableKey];
6774
+ const tableName = table4.name;
6775
+ const snapshotColumn = table4.columns[columnName];
6776
+ const columnType = snapshotColumn.type;
6777
+ const columnDefault = snapshotColumn.default;
6778
+ const columnOnUpdate = "onUpdate" in snapshotColumn ? snapshotColumn.onUpdate : void 0;
6779
+ const columnNotNull = table4.columns[columnName].notNull;
6780
+ const columnAutoIncrement = "autoincrement" in snapshotColumn ? snapshotColumn.autoincrement ?? false : false;
6781
+ const columnPk = table4.columns[columnName].primaryKey;
6697
6782
  if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
6698
6783
  statements.push({
6699
6784
  type: "alter_table_alter_column_set_autoincrement",
@@ -6740,13 +6825,14 @@ var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
6740
6825
  }
6741
6826
  for (const column4 of columns) {
6742
6827
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
6743
- const columnType = json2.tables[tableName].columns[columnName].type;
6744
- const columnDefault = json2.tables[tableName].columns[columnName].default;
6745
- const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
6746
- const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
6747
- const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
6748
- const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
6749
- const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
6828
+ const tableName = json2.tables[tableKey].name;
6829
+ const columnType = json2.tables[tableKey].columns[columnName].type;
6830
+ const columnDefault = json2.tables[tableKey].columns[columnName].default;
6831
+ const columnOnUpdate = json2.tables[tableKey].columns[columnName].onUpdate;
6832
+ const columnNotNull = json2.tables[tableKey].columns[columnName].notNull;
6833
+ const columnAutoIncrement = json2.tables[tableKey].columns[columnName].autoincrement;
6834
+ const columnPk = json2.tables[tableKey].columns[columnName].primaryKey;
6835
+ const compositePk = json2.tables[tableKey].compositePrimaryKeys[`${tableName}_${columnName}`];
6750
6836
  if (typeof column4.name !== "string") {
6751
6837
  statements.push({
6752
6838
  type: "alter_table_rename_column",
@@ -7092,6 +7178,9 @@ var prepareAlterCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
7092
7178
  };
7093
7179
 
7094
7180
  // src/snapshotsDiffer.ts
7181
+ init_sqliteSchema();
7182
+ init_mysqlSchema();
7183
+ init_global();
7095
7184
  var makeChanged = (schema4) => {
7096
7185
  return objectType({
7097
7186
  type: enumType(["changed"]),
@@ -7130,7 +7219,7 @@ var makeSelfOrPatched = (schema4) => {
7130
7219
  return unionType([
7131
7220
  objectType({
7132
7221
  type: literalType("none"),
7133
- value: schema4.optional()
7222
+ value: schema4
7134
7223
  }),
7135
7224
  objectType({
7136
7225
  type: literalType("added"),
@@ -7254,7 +7343,6 @@ var diffResultScheme = objectType({
7254
7343
  }).strict();
7255
7344
  var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
7256
7345
  var _a, _b;
7257
- let diffResult;
7258
7346
  if (dialect3 === "mysql") {
7259
7347
  for (const tableName in json1.tables) {
7260
7348
  const table4 = json1.tables[tableName];
@@ -7282,13 +7370,26 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7282
7370
  }
7283
7371
  }
7284
7372
  }
7285
- diffResult = applyJsonDiff(json1, json2);
7286
7373
  }
7287
- diffResult = applyJsonDiff(json1, json2);
7374
+ const diffResult = applyJsonDiff(json1, json2);
7288
7375
  if (Object.keys(diffResult).length === 0) {
7289
7376
  return { statements: [], sqlStatements: [], _meta: void 0 };
7290
7377
  }
7291
7378
  const typedResult = diffResultScheme.parse(diffResult);
7379
+ typedResult.alteredTablesWithColumns = typedResult.alteredTablesWithColumns.map((it) => {
7380
+ let schemaToTrim;
7381
+ if (it.schema.type === "none") {
7382
+ schemaToTrim = it.schema.value || "public";
7383
+ } else if (it.schema.type === "deleted") {
7384
+ schemaToTrim = it.schema.value;
7385
+ } else if (it.schema.type === "added") {
7386
+ schemaToTrim = "public";
7387
+ } else {
7388
+ schemaToTrim = it.schema.old;
7389
+ }
7390
+ it.name = it.name.substring(schemaToTrim.length + 1);
7391
+ return it;
7392
+ });
7292
7393
  const {
7293
7394
  created: createdSchemas,
7294
7395
  deleted: deletedSchemas,
@@ -7440,7 +7541,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7440
7541
  prevFull,
7441
7542
  curFull
7442
7543
  );
7443
- } else {
7544
+ } else if (dialect3 === "mysql") {
7444
7545
  addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
7445
7546
  it.name,
7446
7547
  it.addedCompositePKs,
@@ -7458,6 +7559,8 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7458
7559
  prevFull,
7459
7560
  curFull
7460
7561
  );
7562
+ } else {
7563
+ assertUnreachable(dialect3);
7461
7564
  }
7462
7565
  let addedUniqueConstraints = [];
7463
7566
  let deletedUniqueConstraints = [];
@@ -7648,11 +7751,13 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7648
7751
  return preparePgCreateTableJson(it, curFull);
7649
7752
  });
7650
7753
  jsonStatements.push(...jsonPgCreateTables);
7651
- } else {
7754
+ } else if (dialect3 === "mysql") {
7652
7755
  const jsonMySqlCreateTables = created.map((it) => {
7653
7756
  return prepareMySqlCreateTableJson(it, curFull);
7654
7757
  });
7655
7758
  jsonStatements.push(...jsonMySqlCreateTables);
7759
+ } else {
7760
+ assertUnreachable(dialect3);
7656
7761
  }
7657
7762
  jsonStatements.push(...jsonDropTables);
7658
7763
  jsonStatements.push(...jsonRenameTables);
@@ -7702,9 +7807,15 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7702
7807
 
7703
7808
  // src/cli/commands/pgUp.ts
7704
7809
  init_source();
7810
+ init_global();
7811
+ init_pgSchema();
7812
+
7813
+ // src/cli/commands/upFolders.ts
7814
+ init_pgSchema();
7705
7815
 
7706
7816
  // src/cli/commands/mysqlUp.ts
7707
7817
  init_source();
7818
+ init_mysqlSchema();
7708
7819
 
7709
7820
  // src/cli/commands/upFolders.ts
7710
7821
  var resolveSchemas = (missingSchemas, newSchemas, predicate) => {
@@ -7805,7 +7916,7 @@ var resolveColumns = (missingColumns, newColumns, predicate) => {
7805
7916
  };
7806
7917
 
7807
7918
  // src/utils.ts
7808
- var assertV1OutFolder = (out, dialect3) => {
7919
+ var assertV1OutFolder = (out) => {
7809
7920
  if (!existsSync(out))
7810
7921
  return;
7811
7922
  const oldMigrationFolders = readdirSync(out).filter(
@@ -7814,7 +7925,7 @@ var assertV1OutFolder = (out, dialect3) => {
7814
7925
  if (oldMigrationFolders.length > 0) {
7815
7926
  console.log(
7816
7927
  `Your migrations folder format is outdated, please run ${source_default.green.bold(
7817
- `drizzle-kit up:${dialect3}`
7928
+ `drizzle-kit up`
7818
7929
  )}`
7819
7930
  );
7820
7931
  process.exit(1);
@@ -7838,7 +7949,7 @@ var snapshotsPriorV4 = (out) => {
7838
7949
  return pathJson;
7839
7950
  });
7840
7951
  };
7841
- var prepareOutFolder2 = (out, dialect3) => {
7952
+ var prepareOutFolder = (out, dialect3) => {
7842
7953
  const meta = join(out, "meta");
7843
7954
  const journalPath = join(meta, "_journal.json");
7844
7955
  if (!existsSync(join(out, "meta"))) {
@@ -7853,9 +7964,9 @@ var prepareOutFolder2 = (out, dialect3) => {
7853
7964
  var validatorForDialect = (dialect3) => {
7854
7965
  switch (dialect3) {
7855
7966
  case "pg":
7856
- return { validator: backwardCompatiblePgSchema, version: 5 };
7967
+ return { validator: backwardCompatiblePgSchema, version: 6 };
7857
7968
  case "sqlite":
7858
- return { validator: backwardCompatibleSqliteSchema, version: 5 };
7969
+ return { validator: backwardCompatibleSqliteSchema, version: 6 };
7859
7970
  case "mysql":
7860
7971
  return { validator: backwardCompatibleMysqlSchema, version: 5 };
7861
7972
  }
@@ -7903,13 +8014,13 @@ var validateWithReport = (snapshots, dialect3) => {
7903
8014
  return result;
7904
8015
  };
7905
8016
  var prepareMigrationFolder = (outFolder = "drizzle", dialect3) => {
7906
- const { snapshots, journal } = prepareOutFolder2(outFolder, dialect3);
8017
+ const { snapshots, journal } = prepareOutFolder(outFolder, dialect3);
7907
8018
  const report = validateWithReport(snapshots, dialect3);
7908
8019
  if (report.nonLatest.length > 0) {
7909
8020
  console.log(
7910
8021
  report.nonLatest.map((it) => {
7911
8022
  return `${it}/snapshot.json is not of the latest version`;
7912
- }).concat(`Run ${source_default.green.bold(`drizzle-kit up:${dialect3}`)}`).join("\n")
8023
+ }).concat(`Run ${source_default.green.bold(`drizzle-kit up`)}`).join("\n")
7913
8024
  );
7914
8025
  process.exit(0);
7915
8026
  }
@@ -8042,7 +8153,9 @@ var statementsForDiffs = async (in1, in2) => {
8042
8153
  "pg",
8043
8154
  schemasResolver,
8044
8155
  tablesResolver,
8045
- columnsResolver
8156
+ columnsResolver,
8157
+ left,
8158
+ right
8046
8159
  );
8047
8160
  return { ...result, left, right };
8048
8161
  };
@@ -8053,7 +8166,7 @@ export {
8053
8166
  kloudMeta,
8054
8167
  prepareMigrationFolder,
8055
8168
  prepareMigrationMeta,
8056
- prepareOutFolder2 as prepareOutFolder,
8169
+ prepareOutFolder,
8057
8170
  schemaRenameKey,
8058
8171
  snapshotsPriorV4,
8059
8172
  statementsForDiffs,