drizzle-kit 0.20.14-1f2c838 → 0.20.14-1f99bf7

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 +6833 -6983
  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 +9 -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 +1 -1
  26. package/introspect-sqlite.d.ts +1 -1
  27. package/jsonStatements.d.ts +1 -1
  28. package/package.json +4 -3
  29. package/payload.js +3035 -2721
  30. package/payload.mjs +2448 -2135
  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 +21 -8
  39. package/utils-studio.mjs +20 -8
  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.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1078,6 +1079,7 @@ var require_hanji = __commonJS({
1078
1079
  var import_hanji, info;
1079
1080
  var init_views = __esm({
1080
1081
  "src/cli/views.ts"() {
1082
+ "use strict";
1081
1083
  init_source();
1082
1084
  import_hanji = __toESM(require_hanji());
1083
1085
  info = (msg, greyMsg = "") => {
@@ -1086,6 +1088,26 @@ var init_views = __esm({
1086
1088
  }
1087
1089
  });
1088
1090
 
1091
+ // src/global.ts
1092
+ function assertUnreachable(x) {
1093
+ throw new Error("Didn't expect to get here");
1094
+ }
1095
+ var originUUID, snapshotVersion, mapValues;
1096
+ var init_global = __esm({
1097
+ "src/global.ts"() {
1098
+ "use strict";
1099
+ originUUID = "00000000-0000-0000-0000-000000000000";
1100
+ snapshotVersion = "6";
1101
+ mapValues = (obj, map) => {
1102
+ const result = Object.keys(obj).reduce(function(result2, key) {
1103
+ result2[key] = map(obj[key]);
1104
+ return result2;
1105
+ }, {});
1106
+ return result;
1107
+ };
1108
+ }
1109
+ });
1110
+
1089
1111
  // node_modules/.pnpm/zod@3.20.2/node_modules/zod/lib/index.mjs
1090
1112
  function getErrorMap() {
1091
1113
  return overrideErrorMap;
@@ -4225,10 +4247,751 @@ var init_lib = __esm({
4225
4247
  }
4226
4248
  });
4227
4249
 
4250
+ // src/serializer/mysqlSchema.ts
4251
+ 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;
4252
+ var init_mysqlSchema = __esm({
4253
+ "src/serializer/mysqlSchema.ts"() {
4254
+ "use strict";
4255
+ init_global();
4256
+ init_lib();
4257
+ index = objectType({
4258
+ name: stringType(),
4259
+ columns: stringType().array(),
4260
+ isUnique: booleanType(),
4261
+ using: enumType(["btree", "hash"]).optional(),
4262
+ algorithm: enumType(["default", "inplace", "copy"]).optional(),
4263
+ lock: enumType(["default", "none", "shared", "exclusive"]).optional()
4264
+ }).strict();
4265
+ fk = objectType({
4266
+ name: stringType(),
4267
+ tableFrom: stringType(),
4268
+ columnsFrom: stringType().array(),
4269
+ tableTo: stringType(),
4270
+ columnsTo: stringType().array(),
4271
+ onUpdate: stringType().optional(),
4272
+ onDelete: stringType().optional()
4273
+ }).strict();
4274
+ column = objectType({
4275
+ name: stringType(),
4276
+ type: stringType(),
4277
+ primaryKey: booleanType(),
4278
+ notNull: booleanType(),
4279
+ autoincrement: booleanType().optional(),
4280
+ default: anyType().optional(),
4281
+ onUpdate: anyType().optional()
4282
+ }).strict();
4283
+ tableV3 = objectType({
4284
+ name: stringType(),
4285
+ columns: recordType(stringType(), column),
4286
+ indexes: recordType(stringType(), index),
4287
+ foreignKeys: recordType(stringType(), fk)
4288
+ }).strict();
4289
+ compositePK = objectType({
4290
+ name: stringType(),
4291
+ columns: stringType().array()
4292
+ }).strict();
4293
+ uniqueConstraint = objectType({
4294
+ name: stringType(),
4295
+ columns: stringType().array()
4296
+ }).strict();
4297
+ tableV4 = objectType({
4298
+ name: stringType(),
4299
+ schema: stringType().optional(),
4300
+ columns: recordType(stringType(), column),
4301
+ indexes: recordType(stringType(), index),
4302
+ foreignKeys: recordType(stringType(), fk)
4303
+ }).strict();
4304
+ table = objectType({
4305
+ name: stringType(),
4306
+ schema: stringType().optional(),
4307
+ columns: recordType(stringType(), column),
4308
+ indexes: recordType(stringType(), index),
4309
+ foreignKeys: recordType(stringType(), fk),
4310
+ compositePrimaryKeys: recordType(stringType(), compositePK),
4311
+ uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
4312
+ }).strict();
4313
+ kitInternals = objectType({
4314
+ tables: recordType(
4315
+ stringType(),
4316
+ objectType({
4317
+ columns: recordType(
4318
+ stringType(),
4319
+ objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
4320
+ )
4321
+ }).optional()
4322
+ )
4323
+ }).optional();
4324
+ dialect = literalType("mysql");
4325
+ schemaHash = objectType({
4326
+ id: stringType(),
4327
+ prevId: stringType()
4328
+ });
4329
+ schemaInternalV3 = objectType({
4330
+ version: literalType("3"),
4331
+ dialect,
4332
+ tables: recordType(stringType(), tableV3)
4333
+ }).strict();
4334
+ schemaInternalV4 = objectType({
4335
+ version: literalType("4"),
4336
+ dialect,
4337
+ tables: recordType(stringType(), tableV4),
4338
+ schemas: recordType(stringType(), stringType())
4339
+ }).strict();
4340
+ schemaInternalV5 = objectType({
4341
+ version: literalType("5"),
4342
+ dialect,
4343
+ tables: recordType(stringType(), table),
4344
+ schemas: recordType(stringType(), stringType()),
4345
+ _meta: objectType({
4346
+ schemas: recordType(stringType(), stringType()),
4347
+ tables: recordType(stringType(), stringType()),
4348
+ columns: recordType(stringType(), stringType())
4349
+ }),
4350
+ internal: kitInternals
4351
+ }).strict();
4352
+ schemaInternalV6 = objectType({
4353
+ version: literalType("6"),
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
+ schemaInternal = objectType({
4365
+ version: literalType("6"),
4366
+ dialect,
4367
+ tables: recordType(stringType(), table),
4368
+ schemas: recordType(stringType(), stringType()),
4369
+ _meta: objectType({
4370
+ schemas: recordType(stringType(), stringType()),
4371
+ tables: recordType(stringType(), stringType()),
4372
+ columns: recordType(stringType(), stringType())
4373
+ }),
4374
+ internal: kitInternals
4375
+ }).strict();
4376
+ schemaV3 = schemaInternalV3.merge(schemaHash);
4377
+ schemaV4 = schemaInternalV4.merge(schemaHash);
4378
+ schemaV5 = schemaInternalV5.merge(schemaHash);
4379
+ schema = schemaInternal.merge(schemaHash);
4380
+ tableSquashedV4 = objectType({
4381
+ name: stringType(),
4382
+ schema: stringType().optional(),
4383
+ columns: recordType(stringType(), column),
4384
+ indexes: recordType(stringType(), stringType()),
4385
+ foreignKeys: recordType(stringType(), stringType())
4386
+ }).strict();
4387
+ tableSquashed = objectType({
4388
+ name: stringType(),
4389
+ schema: stringType().optional(),
4390
+ columns: recordType(stringType(), column),
4391
+ indexes: recordType(stringType(), stringType()),
4392
+ foreignKeys: recordType(stringType(), stringType()),
4393
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4394
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4395
+ }).strict();
4396
+ schemaSquashed = objectType({
4397
+ version: literalType("5"),
4398
+ dialect,
4399
+ tables: recordType(stringType(), tableSquashed),
4400
+ schemas: recordType(stringType(), stringType())
4401
+ }).strict();
4402
+ schemaSquashedV4 = objectType({
4403
+ version: literalType("4"),
4404
+ dialect,
4405
+ tables: recordType(stringType(), tableSquashedV4),
4406
+ schemas: recordType(stringType(), stringType())
4407
+ }).strict();
4408
+ MySqlSquasher = {
4409
+ squashIdx: (idx) => {
4410
+ index.parse(idx);
4411
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.using ?? ""};${idx.algorithm ?? ""};${idx.lock ?? ""}`;
4412
+ },
4413
+ unsquashIdx: (input) => {
4414
+ const [name, columnsString, isUnique, using, algorithm, lock] = input.split(";");
4415
+ const destructed = {
4416
+ name,
4417
+ columns: columnsString.split(","),
4418
+ isUnique: isUnique === "true",
4419
+ using: using ? using : void 0,
4420
+ algorithm: algorithm ? algorithm : void 0,
4421
+ lock: lock ? lock : void 0
4422
+ };
4423
+ return index.parse(destructed);
4424
+ },
4425
+ squashPK: (pk) => {
4426
+ return `${pk.name};${pk.columns.join(",")}`;
4427
+ },
4428
+ unsquashPK: (pk) => {
4429
+ const splitted = pk.split(";");
4430
+ return { name: splitted[0], columns: splitted[1].split(",") };
4431
+ },
4432
+ squashUnique: (unq) => {
4433
+ return `${unq.name};${unq.columns.join(",")}`;
4434
+ },
4435
+ unsquashUnique: (unq) => {
4436
+ const [name, columns] = unq.split(";");
4437
+ return { name, columns: columns.split(",") };
4438
+ },
4439
+ squashFK: (fk4) => {
4440
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4441
+ },
4442
+ unsquashFK: (input) => {
4443
+ const [
4444
+ name,
4445
+ tableFrom,
4446
+ columnsFromStr,
4447
+ tableTo,
4448
+ columnsToStr,
4449
+ onUpdate,
4450
+ onDelete
4451
+ ] = input.split(";");
4452
+ const result = fk.parse({
4453
+ name,
4454
+ tableFrom,
4455
+ columnsFrom: columnsFromStr.split(","),
4456
+ tableTo,
4457
+ columnsTo: columnsToStr.split(","),
4458
+ onUpdate,
4459
+ onDelete
4460
+ });
4461
+ return result;
4462
+ }
4463
+ };
4464
+ mysqlSchema = schema;
4465
+ mysqlSchemaV5 = schemaV5;
4466
+ backwardCompatibleMysqlSchema = unionType([mysqlSchemaV5, schema]);
4467
+ dryMySql = mysqlSchema.parse({
4468
+ version: snapshotVersion,
4469
+ dialect: "mysql",
4470
+ id: originUUID,
4471
+ prevId: "",
4472
+ tables: {},
4473
+ schemas: {},
4474
+ _meta: {
4475
+ schemas: {},
4476
+ tables: {},
4477
+ columns: {}
4478
+ }
4479
+ });
4480
+ }
4481
+ });
4482
+
4483
+ // src/serializer/pgSchema.ts
4484
+ 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;
4485
+ var init_pgSchema = __esm({
4486
+ "src/serializer/pgSchema.ts"() {
4487
+ "use strict";
4488
+ init_global();
4489
+ init_lib();
4490
+ indexV2 = objectType({
4491
+ name: stringType(),
4492
+ columns: recordType(
4493
+ stringType(),
4494
+ objectType({
4495
+ name: stringType()
4496
+ })
4497
+ ),
4498
+ isUnique: booleanType()
4499
+ }).strict();
4500
+ columnV2 = objectType({
4501
+ name: stringType(),
4502
+ type: stringType(),
4503
+ primaryKey: booleanType(),
4504
+ notNull: booleanType(),
4505
+ default: anyType().optional(),
4506
+ references: stringType().optional()
4507
+ }).strict();
4508
+ tableV2 = objectType({
4509
+ name: stringType(),
4510
+ columns: recordType(stringType(), columnV2),
4511
+ indexes: recordType(stringType(), indexV2)
4512
+ }).strict();
4513
+ enumSchema = objectType({
4514
+ name: stringType(),
4515
+ values: recordType(stringType(), stringType())
4516
+ }).strict();
4517
+ pgSchemaV2 = objectType({
4518
+ version: literalType("2"),
4519
+ tables: recordType(stringType(), tableV2),
4520
+ enums: recordType(stringType(), enumSchema)
4521
+ }).strict();
4522
+ references = objectType({
4523
+ foreignKeyName: stringType(),
4524
+ table: stringType(),
4525
+ column: stringType(),
4526
+ onDelete: stringType().optional(),
4527
+ onUpdate: stringType().optional()
4528
+ }).strict();
4529
+ columnV1 = objectType({
4530
+ name: stringType(),
4531
+ type: stringType(),
4532
+ primaryKey: booleanType(),
4533
+ notNull: booleanType(),
4534
+ default: anyType().optional(),
4535
+ references: references.optional()
4536
+ }).strict();
4537
+ tableV1 = objectType({
4538
+ name: stringType(),
4539
+ columns: recordType(stringType(), columnV1),
4540
+ indexes: recordType(stringType(), indexV2)
4541
+ }).strict();
4542
+ pgSchemaV1 = objectType({
4543
+ version: literalType("1"),
4544
+ tables: recordType(stringType(), tableV1),
4545
+ enums: recordType(stringType(), enumSchema)
4546
+ }).strict();
4547
+ index2 = objectType({
4548
+ name: stringType(),
4549
+ columns: stringType().array(),
4550
+ isUnique: booleanType()
4551
+ }).strict();
4552
+ fk2 = objectType({
4553
+ name: stringType(),
4554
+ tableFrom: stringType(),
4555
+ columnsFrom: stringType().array(),
4556
+ tableTo: stringType(),
4557
+ schemaTo: stringType().optional(),
4558
+ columnsTo: stringType().array(),
4559
+ onUpdate: stringType().optional(),
4560
+ onDelete: stringType().optional()
4561
+ }).strict();
4562
+ column2 = objectType({
4563
+ name: stringType(),
4564
+ type: stringType(),
4565
+ primaryKey: booleanType(),
4566
+ notNull: booleanType(),
4567
+ default: anyType().optional(),
4568
+ isUnique: anyType().optional(),
4569
+ uniqueName: stringType().optional(),
4570
+ nullsNotDistinct: booleanType().optional()
4571
+ }).strict();
4572
+ tableV32 = objectType({
4573
+ name: stringType(),
4574
+ columns: recordType(stringType(), column2),
4575
+ indexes: recordType(stringType(), index2),
4576
+ foreignKeys: recordType(stringType(), fk2)
4577
+ }).strict();
4578
+ compositePK2 = objectType({
4579
+ name: stringType(),
4580
+ columns: stringType().array()
4581
+ }).strict();
4582
+ uniqueConstraint2 = objectType({
4583
+ name: stringType(),
4584
+ columns: stringType().array(),
4585
+ nullsNotDistinct: booleanType()
4586
+ }).strict();
4587
+ tableV42 = objectType({
4588
+ name: stringType(),
4589
+ schema: stringType(),
4590
+ columns: recordType(stringType(), column2),
4591
+ indexes: recordType(stringType(), index2),
4592
+ foreignKeys: recordType(stringType(), fk2)
4593
+ }).strict();
4594
+ table2 = objectType({
4595
+ name: stringType(),
4596
+ schema: stringType(),
4597
+ columns: recordType(stringType(), column2),
4598
+ indexes: recordType(stringType(), index2),
4599
+ foreignKeys: recordType(stringType(), fk2),
4600
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
4601
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
4602
+ }).strict();
4603
+ schemaHash2 = objectType({
4604
+ id: stringType(),
4605
+ prevId: stringType()
4606
+ });
4607
+ kitInternals2 = objectType({
4608
+ tables: recordType(
4609
+ stringType(),
4610
+ objectType({
4611
+ columns: recordType(
4612
+ stringType(),
4613
+ objectType({
4614
+ isArray: booleanType().optional(),
4615
+ dimensions: numberType().optional(),
4616
+ rawType: stringType().optional()
4617
+ }).optional()
4618
+ )
4619
+ }).optional()
4620
+ )
4621
+ }).optional();
4622
+ pgSchemaInternalV3 = objectType({
4623
+ version: literalType("3"),
4624
+ dialect: literalType("pg"),
4625
+ tables: recordType(stringType(), tableV32),
4626
+ enums: recordType(stringType(), enumSchema)
4627
+ }).strict();
4628
+ pgSchemaInternalV4 = objectType({
4629
+ version: literalType("4"),
4630
+ dialect: literalType("pg"),
4631
+ tables: recordType(stringType(), tableV42),
4632
+ enums: recordType(stringType(), enumSchema),
4633
+ schemas: recordType(stringType(), stringType())
4634
+ }).strict();
4635
+ pgSchemaInternalV5 = objectType({
4636
+ version: literalType("5"),
4637
+ dialect: literalType("pg"),
4638
+ tables: recordType(stringType(), table2),
4639
+ enums: recordType(stringType(), enumSchema),
4640
+ schemas: recordType(stringType(), stringType()),
4641
+ _meta: objectType({
4642
+ schemas: recordType(stringType(), stringType()),
4643
+ tables: recordType(stringType(), stringType()),
4644
+ columns: recordType(stringType(), stringType())
4645
+ }),
4646
+ internal: kitInternals2
4647
+ }).strict();
4648
+ pgSchemaExternal = objectType({
4649
+ version: literalType("5"),
4650
+ dialect: literalType("pg"),
4651
+ tables: arrayType(table2),
4652
+ enums: arrayType(enumSchema),
4653
+ schemas: arrayType(objectType({ name: stringType() })),
4654
+ _meta: objectType({
4655
+ schemas: recordType(stringType(), stringType()),
4656
+ tables: recordType(stringType(), stringType()),
4657
+ columns: recordType(stringType(), stringType())
4658
+ })
4659
+ }).strict();
4660
+ pgSchemaInternal = objectType({
4661
+ version: literalType("6"),
4662
+ dialect: literalType("pg"),
4663
+ tables: recordType(stringType(), table2),
4664
+ enums: recordType(stringType(), enumSchema),
4665
+ schemas: recordType(stringType(), stringType()),
4666
+ _meta: objectType({
4667
+ schemas: recordType(stringType(), stringType()),
4668
+ tables: recordType(stringType(), stringType()),
4669
+ columns: recordType(stringType(), stringType())
4670
+ }),
4671
+ internal: kitInternals2
4672
+ }).strict();
4673
+ tableSquashed2 = objectType({
4674
+ name: stringType(),
4675
+ schema: stringType(),
4676
+ columns: recordType(stringType(), column2),
4677
+ indexes: recordType(stringType(), stringType()),
4678
+ foreignKeys: recordType(stringType(), stringType()),
4679
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4680
+ uniqueConstraints: recordType(stringType(), stringType())
4681
+ }).strict();
4682
+ tableSquashedV42 = objectType({
4683
+ name: stringType(),
4684
+ schema: stringType(),
4685
+ columns: recordType(stringType(), column2),
4686
+ indexes: recordType(stringType(), stringType()),
4687
+ foreignKeys: recordType(stringType(), stringType())
4688
+ }).strict();
4689
+ pgSchemaSquashedV4 = objectType({
4690
+ version: literalType("4"),
4691
+ dialect: enumType(["pg"]),
4692
+ tables: recordType(stringType(), tableSquashedV42),
4693
+ enums: recordType(stringType(), enumSchema),
4694
+ schemas: recordType(stringType(), stringType())
4695
+ }).strict();
4696
+ pgSchemaSquashed = objectType({
4697
+ version: literalType("6"),
4698
+ dialect: enumType(["pg"]),
4699
+ tables: recordType(stringType(), tableSquashed2),
4700
+ enums: recordType(stringType(), enumSchema),
4701
+ schemas: recordType(stringType(), stringType())
4702
+ }).strict();
4703
+ pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
4704
+ pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
4705
+ pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
4706
+ pgSchema = pgSchemaInternal.merge(schemaHash2);
4707
+ backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema]);
4708
+ PgSquasher = {
4709
+ squashIdx: (idx) => {
4710
+ index2.parse(idx);
4711
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique}`;
4712
+ },
4713
+ unsquashIdx: (input) => {
4714
+ const [name, columnsString, isUnique] = input.split(";");
4715
+ const result = index2.parse({
4716
+ name,
4717
+ columns: columnsString.split(","),
4718
+ isUnique: isUnique === "true"
4719
+ });
4720
+ return result;
4721
+ },
4722
+ squashFK: (fk4) => {
4723
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo ?? ""}`;
4724
+ },
4725
+ squashPK: (pk) => {
4726
+ return `${pk.columns.join(",")};${pk.name}`;
4727
+ },
4728
+ unsquashPK: (pk) => {
4729
+ const splitted = pk.split(";");
4730
+ return { name: splitted[1], columns: splitted[0].split(",") };
4731
+ },
4732
+ squashUnique: (unq) => {
4733
+ return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
4734
+ },
4735
+ unsquashUnique: (unq) => {
4736
+ const [name, columns, nullsNotDistinct] = unq.split(";");
4737
+ return {
4738
+ name,
4739
+ columns: columns.split(","),
4740
+ nullsNotDistinct: nullsNotDistinct === "true"
4741
+ };
4742
+ },
4743
+ unsquashFK: (input) => {
4744
+ const [
4745
+ name,
4746
+ tableFrom,
4747
+ columnsFromStr,
4748
+ tableTo,
4749
+ columnsToStr,
4750
+ onUpdate,
4751
+ onDelete,
4752
+ schemaTo
4753
+ ] = input.split(";");
4754
+ const result = fk2.parse({
4755
+ name,
4756
+ tableFrom,
4757
+ columnsFrom: columnsFromStr.split(","),
4758
+ schemaTo,
4759
+ tableTo,
4760
+ columnsTo: columnsToStr.split(","),
4761
+ onUpdate,
4762
+ onDelete
4763
+ });
4764
+ return result;
4765
+ }
4766
+ };
4767
+ squashPgScheme = (json) => {
4768
+ const mappedTables = Object.fromEntries(
4769
+ Object.entries(json.tables).map((it) => {
4770
+ const squashedIndexes = mapValues(it[1].indexes, (index4) => {
4771
+ return PgSquasher.squashIdx(index4);
4772
+ });
4773
+ const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
4774
+ return PgSquasher.squashFK(fk4);
4775
+ });
4776
+ const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
4777
+ return PgSquasher.squashPK(pk);
4778
+ });
4779
+ const squashedUniqueConstraints = mapValues(
4780
+ it[1].uniqueConstraints,
4781
+ (unq) => {
4782
+ return PgSquasher.squashUnique(unq);
4783
+ }
4784
+ );
4785
+ return [
4786
+ it[0],
4787
+ {
4788
+ name: it[1].name,
4789
+ schema: it[1].schema,
4790
+ columns: it[1].columns,
4791
+ indexes: squashedIndexes,
4792
+ foreignKeys: squashedFKs,
4793
+ compositePrimaryKeys: squashedPKs,
4794
+ uniqueConstraints: squashedUniqueConstraints
4795
+ }
4796
+ ];
4797
+ })
4798
+ );
4799
+ return {
4800
+ version: "6",
4801
+ dialect: json.dialect,
4802
+ tables: mappedTables,
4803
+ enums: json.enums,
4804
+ schemas: json.schemas
4805
+ };
4806
+ };
4807
+ dryPg = pgSchema.parse({
4808
+ version: snapshotVersion,
4809
+ dialect: "pg",
4810
+ id: originUUID,
4811
+ prevId: "",
4812
+ tables: {},
4813
+ enums: {},
4814
+ schemas: {},
4815
+ _meta: {
4816
+ schemas: {},
4817
+ tables: {},
4818
+ columns: {}
4819
+ }
4820
+ });
4821
+ }
4822
+ });
4823
+
4824
+ // src/serializer/sqliteSchema.ts
4825
+ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, drySQLite, backwardCompatibleSqliteSchema;
4826
+ var init_sqliteSchema = __esm({
4827
+ "src/serializer/sqliteSchema.ts"() {
4828
+ "use strict";
4829
+ init_global();
4830
+ init_lib();
4831
+ index3 = objectType({
4832
+ name: stringType(),
4833
+ columns: stringType().array(),
4834
+ where: stringType().optional(),
4835
+ isUnique: booleanType()
4836
+ }).strict();
4837
+ fk3 = objectType({
4838
+ name: stringType(),
4839
+ tableFrom: stringType(),
4840
+ columnsFrom: stringType().array(),
4841
+ tableTo: stringType(),
4842
+ columnsTo: stringType().array(),
4843
+ onUpdate: stringType().optional(),
4844
+ onDelete: stringType().optional()
4845
+ }).strict();
4846
+ compositePK3 = objectType({
4847
+ columns: stringType().array(),
4848
+ name: stringType().optional()
4849
+ }).strict();
4850
+ column3 = objectType({
4851
+ name: stringType(),
4852
+ type: stringType(),
4853
+ primaryKey: booleanType(),
4854
+ notNull: booleanType(),
4855
+ autoincrement: booleanType().optional(),
4856
+ default: anyType().optional()
4857
+ }).strict();
4858
+ tableV33 = objectType({
4859
+ name: stringType(),
4860
+ columns: recordType(stringType(), column3),
4861
+ indexes: recordType(stringType(), index3),
4862
+ foreignKeys: recordType(stringType(), fk3)
4863
+ }).strict();
4864
+ uniqueConstraint3 = objectType({
4865
+ name: stringType(),
4866
+ columns: stringType().array()
4867
+ }).strict();
4868
+ table3 = objectType({
4869
+ name: stringType(),
4870
+ columns: recordType(stringType(), column3),
4871
+ indexes: recordType(stringType(), index3),
4872
+ foreignKeys: recordType(stringType(), fk3),
4873
+ compositePrimaryKeys: recordType(stringType(), compositePK3),
4874
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
4875
+ }).strict();
4876
+ dialect2 = enumType(["sqlite"]);
4877
+ schemaHash3 = objectType({
4878
+ id: stringType(),
4879
+ prevId: stringType()
4880
+ }).strict();
4881
+ schemaInternalV32 = objectType({
4882
+ version: literalType("3"),
4883
+ dialect: dialect2,
4884
+ tables: recordType(stringType(), tableV33),
4885
+ enums: objectType({})
4886
+ }).strict();
4887
+ schemaInternalV42 = objectType({
4888
+ version: literalType("4"),
4889
+ dialect: dialect2,
4890
+ tables: recordType(stringType(), table3),
4891
+ enums: objectType({})
4892
+ }).strict();
4893
+ latestVersion = literalType("5");
4894
+ schemaInternal2 = objectType({
4895
+ version: latestVersion,
4896
+ dialect: dialect2,
4897
+ tables: recordType(stringType(), table3),
4898
+ enums: objectType({}),
4899
+ _meta: objectType({
4900
+ tables: recordType(stringType(), stringType()),
4901
+ columns: recordType(stringType(), stringType())
4902
+ })
4903
+ }).strict();
4904
+ schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
4905
+ schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
4906
+ schema2 = schemaInternal2.merge(schemaHash3).strict();
4907
+ tableSquashed3 = objectType({
4908
+ name: stringType(),
4909
+ columns: recordType(stringType(), column3),
4910
+ indexes: recordType(stringType(), stringType()),
4911
+ foreignKeys: recordType(stringType(), stringType()),
4912
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4913
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4914
+ }).strict();
4915
+ schemaSquashed2 = objectType({
4916
+ version: latestVersion,
4917
+ dialect: dialect2,
4918
+ tables: recordType(stringType(), tableSquashed3),
4919
+ enums: anyType()
4920
+ }).strict();
4921
+ SQLiteSquasher = {
4922
+ squashIdx: (idx) => {
4923
+ index3.parse(idx);
4924
+ return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.where ?? ""}`;
4925
+ },
4926
+ unsquashIdx: (input) => {
4927
+ const [name, columnsString, isUnique, where] = input.split(";");
4928
+ const result = index3.parse({
4929
+ name,
4930
+ columns: columnsString.split(","),
4931
+ isUnique: isUnique === "true",
4932
+ where: where ?? void 0
4933
+ });
4934
+ return result;
4935
+ },
4936
+ squashUnique: (unq) => {
4937
+ return `${unq.name};${unq.columns.join(",")}`;
4938
+ },
4939
+ unsquashUnique: (unq) => {
4940
+ const [name, columns] = unq.split(";");
4941
+ return { name, columns: columns.split(",") };
4942
+ },
4943
+ squashFK: (fk4) => {
4944
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4945
+ },
4946
+ unsquashFK: (input) => {
4947
+ const [
4948
+ name,
4949
+ tableFrom,
4950
+ columnsFromStr,
4951
+ tableTo,
4952
+ columnsToStr,
4953
+ onUpdate,
4954
+ onDelete
4955
+ ] = input.split(";");
4956
+ const result = fk3.parse({
4957
+ name,
4958
+ tableFrom,
4959
+ columnsFrom: columnsFromStr.split(","),
4960
+ tableTo,
4961
+ columnsTo: columnsToStr.split(","),
4962
+ onUpdate,
4963
+ onDelete
4964
+ });
4965
+ return result;
4966
+ },
4967
+ squashPK: (pk) => {
4968
+ return pk.columns.join(",");
4969
+ },
4970
+ unsquashPK: (pk) => {
4971
+ return pk.split(",");
4972
+ }
4973
+ };
4974
+ drySQLite = schema2.parse({
4975
+ version: "5",
4976
+ dialect: "sqlite",
4977
+ id: originUUID,
4978
+ prevId: "",
4979
+ tables: {},
4980
+ enums: {},
4981
+ _meta: {
4982
+ tables: {},
4983
+ columns: {}
4984
+ }
4985
+ });
4986
+ backwardCompatibleSqliteSchema = schema2;
4987
+ }
4988
+ });
4989
+
4228
4990
  // src/serializer/index.ts
4229
4991
  var glob;
4230
4992
  var init_serializer = __esm({
4231
4993
  "src/serializer/index.ts"() {
4994
+ "use strict";
4232
4995
  glob = __toESM(require("glob"));
4233
4996
  init_source();
4234
4997
  init_views();
@@ -4238,6 +5001,7 @@ var init_serializer = __esm({
4238
5001
  // src/cli/validations/outputs.ts
4239
5002
  var init_outputs = __esm({
4240
5003
  "src/cli/validations/outputs.ts"() {
5004
+ "use strict";
4241
5005
  init_source();
4242
5006
  }
4243
5007
  });
@@ -4251,7 +5015,7 @@ __export(utils_exports, {
4251
5015
  kloudMeta: () => kloudMeta,
4252
5016
  prepareMigrationFolder: () => prepareMigrationFolder,
4253
5017
  prepareMigrationMeta: () => prepareMigrationMeta,
4254
- prepareOutFolder: () => prepareOutFolder2,
5018
+ prepareOutFolder: () => prepareOutFolder,
4255
5019
  schemaRenameKey: () => schemaRenameKey,
4256
5020
  snapshotsPriorV4: () => snapshotsPriorV4,
4257
5021
  statementsForDiffs: () => statementsForDiffs,
@@ -4261,710 +5025,12 @@ __export(utils_exports, {
4261
5025
  module.exports = __toCommonJS(utils_exports);
4262
5026
  var import_fs = require("fs");
4263
5027
  init_views();
4264
-
4265
- // src/global.ts
4266
- var originUUID = "00000000-0000-0000-0000-000000000000";
4267
- var snapshotVersion = "5";
4268
- var mapValues = (obj, map) => {
4269
- const result = Object.keys(obj).reduce(function(result2, key) {
4270
- result2[key] = map(obj[key]);
4271
- return result2;
4272
- }, {});
4273
- return result;
4274
- };
4275
-
4276
- // src/serializer/mysqlSchema.ts
4277
- init_lib();
4278
- var index = objectType({
4279
- name: stringType(),
4280
- columns: stringType().array(),
4281
- isUnique: booleanType(),
4282
- using: enumType(["btree", "hash"]).optional(),
4283
- algorithm: enumType(["default", "inplace", "copy"]).optional(),
4284
- lock: enumType(["default", "none", "shared", "exclusive"]).optional()
4285
- }).strict();
4286
- var fk = objectType({
4287
- name: stringType(),
4288
- tableFrom: stringType(),
4289
- columnsFrom: stringType().array(),
4290
- tableTo: stringType(),
4291
- columnsTo: stringType().array(),
4292
- onUpdate: stringType().optional(),
4293
- onDelete: stringType().optional()
4294
- }).strict();
4295
- var column = objectType({
4296
- name: stringType(),
4297
- type: stringType(),
4298
- primaryKey: booleanType(),
4299
- notNull: booleanType(),
4300
- autoincrement: booleanType().optional(),
4301
- default: anyType().optional(),
4302
- onUpdate: anyType().optional()
4303
- }).strict();
4304
- var tableV3 = objectType({
4305
- name: stringType(),
4306
- columns: recordType(stringType(), column),
4307
- indexes: recordType(stringType(), index),
4308
- foreignKeys: recordType(stringType(), fk)
4309
- }).strict();
4310
- var compositePK = objectType({
4311
- name: stringType(),
4312
- columns: stringType().array()
4313
- }).strict();
4314
- var uniqueConstraint = objectType({
4315
- name: stringType(),
4316
- columns: stringType().array()
4317
- }).strict();
4318
- var tableV4 = objectType({
4319
- name: stringType(),
4320
- schema: stringType().optional(),
4321
- columns: recordType(stringType(), column),
4322
- indexes: recordType(stringType(), index),
4323
- foreignKeys: recordType(stringType(), fk)
4324
- }).strict();
4325
- var table = objectType({
4326
- name: stringType(),
4327
- schema: stringType().optional(),
4328
- columns: recordType(stringType(), column),
4329
- indexes: recordType(stringType(), index),
4330
- foreignKeys: recordType(stringType(), fk),
4331
- compositePrimaryKeys: recordType(stringType(), compositePK),
4332
- uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
4333
- }).strict();
4334
- var dialect = literalType("mysql");
4335
- var schemaHash = objectType({
4336
- id: stringType(),
4337
- prevId: stringType()
4338
- });
4339
- var schemaInternalV3 = objectType({
4340
- version: literalType("3"),
4341
- dialect,
4342
- tables: recordType(stringType(), tableV3)
4343
- }).strict();
4344
- var schemaInternalV4 = objectType({
4345
- version: literalType("4"),
4346
- dialect,
4347
- tables: recordType(stringType(), tableV4),
4348
- schemas: recordType(stringType(), stringType())
4349
- }).strict();
4350
- var kitInternals = objectType({
4351
- tables: recordType(
4352
- stringType(),
4353
- objectType({
4354
- columns: recordType(
4355
- stringType(),
4356
- objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
4357
- )
4358
- }).optional()
4359
- )
4360
- }).optional();
4361
- var schemaInternal = objectType({
4362
- version: literalType("5"),
4363
- dialect,
4364
- tables: recordType(stringType(), table),
4365
- schemas: recordType(stringType(), stringType()),
4366
- _meta: objectType({
4367
- schemas: recordType(stringType(), stringType()),
4368
- tables: recordType(stringType(), stringType()),
4369
- columns: recordType(stringType(), stringType())
4370
- }),
4371
- internal: kitInternals
4372
- }).strict();
4373
- var schemaV3 = schemaInternalV3.merge(schemaHash);
4374
- var schemaV4 = schemaInternalV4.merge(schemaHash);
4375
- var schema = schemaInternal.merge(schemaHash);
4376
- var tableSquashedV4 = objectType({
4377
- name: stringType(),
4378
- schema: stringType().optional(),
4379
- columns: recordType(stringType(), column),
4380
- indexes: recordType(stringType(), stringType()),
4381
- foreignKeys: recordType(stringType(), stringType())
4382
- }).strict();
4383
- var tableSquashed = objectType({
4384
- name: stringType(),
4385
- schema: stringType().optional(),
4386
- columns: recordType(stringType(), column),
4387
- indexes: recordType(stringType(), stringType()),
4388
- foreignKeys: recordType(stringType(), stringType()),
4389
- compositePrimaryKeys: recordType(stringType(), stringType()),
4390
- uniqueConstraints: recordType(stringType(), stringType()).default({})
4391
- }).strict();
4392
- var schemaSquashed = objectType({
4393
- version: literalType("5"),
4394
- dialect,
4395
- tables: recordType(stringType(), tableSquashed),
4396
- schemas: recordType(stringType(), stringType())
4397
- }).strict();
4398
- var schemaSquashedV4 = objectType({
4399
- version: literalType("4"),
4400
- dialect,
4401
- tables: recordType(stringType(), tableSquashedV4),
4402
- schemas: recordType(stringType(), stringType())
4403
- }).strict();
4404
- var MySqlSquasher = {
4405
- squashIdx: (idx) => {
4406
- index.parse(idx);
4407
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.using ?? ""};${idx.algorithm ?? ""};${idx.lock ?? ""}`;
4408
- },
4409
- unsquashIdx: (input) => {
4410
- const [name, columnsString, isUnique, using, algorithm, lock] = input.split(";");
4411
- const destructed = {
4412
- name,
4413
- columns: columnsString.split(","),
4414
- isUnique: isUnique === "true",
4415
- using: using ? using : void 0,
4416
- algorithm: algorithm ? algorithm : void 0,
4417
- lock: lock ? lock : void 0
4418
- };
4419
- return index.parse(destructed);
4420
- },
4421
- squashPK: (pk) => {
4422
- return `${pk.name};${pk.columns.join(",")}`;
4423
- },
4424
- unsquashPK: (pk) => {
4425
- const splitted = pk.split(";");
4426
- return { name: splitted[0], columns: splitted[1].split(",") };
4427
- },
4428
- squashUnique: (unq) => {
4429
- return `${unq.name};${unq.columns.join(",")}`;
4430
- },
4431
- unsquashUnique: (unq) => {
4432
- const [name, columns] = unq.split(";");
4433
- return { name, columns: columns.split(",") };
4434
- },
4435
- squashFK: (fk4) => {
4436
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4437
- },
4438
- unsquashFK: (input) => {
4439
- const [
4440
- name,
4441
- tableFrom,
4442
- columnsFromStr,
4443
- tableTo,
4444
- columnsToStr,
4445
- onUpdate,
4446
- onDelete
4447
- ] = input.split(";");
4448
- const result = fk.parse({
4449
- name,
4450
- tableFrom,
4451
- columnsFrom: columnsFromStr.split(","),
4452
- tableTo,
4453
- columnsTo: columnsToStr.split(","),
4454
- onUpdate,
4455
- onDelete
4456
- });
4457
- return result;
4458
- }
4459
- };
4460
- var mysqlSchema = schema;
4461
- var backwardCompatibleMysqlSchema = unionType([
4462
- schemaV3,
4463
- schemaV4,
4464
- schema
4465
- ]);
4466
- var dryMySql = mysqlSchema.parse({
4467
- version: snapshotVersion,
4468
- dialect: "mysql",
4469
- id: originUUID,
4470
- prevId: "",
4471
- tables: {},
4472
- schemas: {},
4473
- _meta: {
4474
- schemas: {},
4475
- tables: {},
4476
- columns: {}
4477
- }
4478
- });
4479
-
4480
- // src/serializer/pgSchema.ts
4481
- init_lib();
4482
- var indexV2 = objectType({
4483
- name: stringType(),
4484
- columns: recordType(
4485
- stringType(),
4486
- objectType({
4487
- name: stringType()
4488
- })
4489
- ),
4490
- isUnique: booleanType()
4491
- }).strict();
4492
- var columnV2 = objectType({
4493
- name: stringType(),
4494
- type: stringType(),
4495
- primaryKey: booleanType(),
4496
- notNull: booleanType(),
4497
- default: anyType().optional(),
4498
- references: stringType().optional()
4499
- }).strict();
4500
- var tableV2 = objectType({
4501
- name: stringType(),
4502
- columns: recordType(stringType(), columnV2),
4503
- indexes: recordType(stringType(), indexV2)
4504
- }).strict();
4505
- var enumSchema = objectType({
4506
- name: stringType(),
4507
- values: recordType(stringType(), stringType())
4508
- }).strict();
4509
- var pgSchemaV2 = objectType({
4510
- version: literalType("2"),
4511
- tables: recordType(stringType(), tableV2),
4512
- enums: recordType(stringType(), enumSchema)
4513
- }).strict();
4514
- var references = objectType({
4515
- foreignKeyName: stringType(),
4516
- table: stringType(),
4517
- column: stringType(),
4518
- onDelete: stringType().optional(),
4519
- onUpdate: stringType().optional()
4520
- }).strict();
4521
- var columnV1 = objectType({
4522
- name: stringType(),
4523
- type: stringType(),
4524
- primaryKey: booleanType(),
4525
- notNull: booleanType(),
4526
- default: anyType().optional(),
4527
- references: references.optional()
4528
- }).strict();
4529
- var tableV1 = objectType({
4530
- name: stringType(),
4531
- columns: recordType(stringType(), columnV1),
4532
- indexes: recordType(stringType(), indexV2)
4533
- }).strict();
4534
- var pgSchemaV1 = objectType({
4535
- version: literalType("1"),
4536
- tables: recordType(stringType(), tableV1),
4537
- enums: recordType(stringType(), enumSchema)
4538
- }).strict();
4539
- var index2 = objectType({
4540
- name: stringType(),
4541
- columns: stringType().array(),
4542
- isUnique: booleanType()
4543
- }).strict();
4544
- var fk2 = objectType({
4545
- name: stringType(),
4546
- tableFrom: stringType(),
4547
- columnsFrom: stringType().array(),
4548
- tableTo: stringType(),
4549
- schemaTo: stringType().optional(),
4550
- columnsTo: stringType().array(),
4551
- onUpdate: stringType().optional(),
4552
- onDelete: stringType().optional()
4553
- }).strict();
4554
- var column2 = objectType({
4555
- name: stringType(),
4556
- type: stringType(),
4557
- primaryKey: booleanType(),
4558
- notNull: booleanType(),
4559
- default: anyType().optional(),
4560
- isUnique: anyType().optional(),
4561
- uniqueName: stringType().optional(),
4562
- nullsNotDistinct: booleanType().optional()
4563
- }).strict();
4564
- var tableV32 = objectType({
4565
- name: stringType(),
4566
- columns: recordType(stringType(), column2),
4567
- indexes: recordType(stringType(), index2),
4568
- foreignKeys: recordType(stringType(), fk2)
4569
- }).strict();
4570
- var compositePK2 = objectType({
4571
- name: stringType(),
4572
- columns: stringType().array()
4573
- }).strict();
4574
- var uniqueConstraint2 = objectType({
4575
- name: stringType(),
4576
- columns: stringType().array(),
4577
- nullsNotDistinct: booleanType()
4578
- }).strict();
4579
- var tableV42 = objectType({
4580
- name: stringType(),
4581
- schema: stringType(),
4582
- columns: recordType(stringType(), column2),
4583
- indexes: recordType(stringType(), index2),
4584
- foreignKeys: recordType(stringType(), fk2)
4585
- }).strict();
4586
- var table2 = objectType({
4587
- name: stringType(),
4588
- schema: stringType(),
4589
- columns: recordType(stringType(), column2),
4590
- indexes: recordType(stringType(), index2),
4591
- foreignKeys: recordType(stringType(), fk2),
4592
- compositePrimaryKeys: recordType(stringType(), compositePK2),
4593
- uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
4594
- }).strict();
4595
- var schemaHash2 = objectType({
4596
- id: stringType(),
4597
- prevId: stringType()
4598
- });
4599
- var pgSchemaInternalV3 = objectType({
4600
- version: literalType("3"),
4601
- dialect: literalType("pg"),
4602
- tables: recordType(stringType(), tableV32),
4603
- enums: recordType(stringType(), enumSchema)
4604
- }).strict();
4605
- var pgSchemaInternalV4 = objectType({
4606
- version: literalType("4"),
4607
- dialect: literalType("pg"),
4608
- tables: recordType(stringType(), tableV42),
4609
- enums: recordType(stringType(), enumSchema),
4610
- schemas: recordType(stringType(), stringType())
4611
- }).strict();
4612
- var pgSchemaExternal = objectType({
4613
- version: literalType("5"),
4614
- dialect: literalType("pg"),
4615
- tables: arrayType(table2),
4616
- enums: arrayType(enumSchema),
4617
- schemas: arrayType(objectType({ name: stringType() })),
4618
- _meta: objectType({
4619
- schemas: recordType(stringType(), stringType()),
4620
- tables: recordType(stringType(), stringType()),
4621
- columns: recordType(stringType(), stringType())
4622
- })
4623
- }).strict();
4624
- var kitInternals2 = objectType({
4625
- tables: recordType(
4626
- stringType(),
4627
- objectType({
4628
- columns: recordType(
4629
- stringType(),
4630
- objectType({
4631
- isArray: booleanType().optional(),
4632
- dimensions: numberType().optional(),
4633
- rawType: stringType().optional()
4634
- }).optional()
4635
- )
4636
- }).optional()
4637
- )
4638
- }).optional();
4639
- var pgSchemaInternal = objectType({
4640
- version: literalType("5"),
4641
- dialect: literalType("pg"),
4642
- tables: recordType(stringType(), table2),
4643
- enums: recordType(stringType(), enumSchema),
4644
- schemas: recordType(stringType(), stringType()),
4645
- _meta: objectType({
4646
- schemas: recordType(stringType(), stringType()),
4647
- tables: recordType(stringType(), stringType()),
4648
- columns: recordType(stringType(), stringType())
4649
- }),
4650
- internal: kitInternals2
4651
- }).strict();
4652
- var tableSquashed2 = objectType({
4653
- name: stringType(),
4654
- schema: stringType(),
4655
- columns: recordType(stringType(), column2),
4656
- indexes: recordType(stringType(), stringType()),
4657
- foreignKeys: recordType(stringType(), stringType()),
4658
- compositePrimaryKeys: recordType(stringType(), stringType()),
4659
- uniqueConstraints: recordType(stringType(), stringType())
4660
- }).strict();
4661
- var tableSquashedV42 = objectType({
4662
- name: stringType(),
4663
- schema: stringType(),
4664
- columns: recordType(stringType(), column2),
4665
- indexes: recordType(stringType(), stringType()),
4666
- foreignKeys: recordType(stringType(), stringType())
4667
- }).strict();
4668
- var pgSchemaSquashedV4 = objectType({
4669
- version: literalType("4"),
4670
- dialect: enumType(["pg"]),
4671
- tables: recordType(stringType(), tableSquashedV42),
4672
- enums: recordType(stringType(), enumSchema),
4673
- schemas: recordType(stringType(), stringType())
4674
- }).strict();
4675
- var pgSchemaSquashed = objectType({
4676
- version: literalType("5"),
4677
- dialect: enumType(["pg"]),
4678
- tables: recordType(stringType(), tableSquashed2),
4679
- enums: recordType(stringType(), enumSchema),
4680
- schemas: recordType(stringType(), stringType())
4681
- }).strict();
4682
- var pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
4683
- var pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
4684
- var pgSchema = pgSchemaInternal.merge(schemaHash2);
4685
- var backwardCompatiblePgSchema = unionType([
4686
- pgSchemaV1,
4687
- pgSchemaV2,
4688
- pgSchemaV3,
4689
- pgSchemaV4,
4690
- pgSchema
4691
- ]);
4692
- var PgSquasher = {
4693
- squashIdx: (idx) => {
4694
- index2.parse(idx);
4695
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique}`;
4696
- },
4697
- unsquashIdx: (input) => {
4698
- const [name, columnsString, isUnique] = input.split(";");
4699
- const result = index2.parse({
4700
- name,
4701
- columns: columnsString.split(","),
4702
- isUnique: isUnique === "true"
4703
- });
4704
- return result;
4705
- },
4706
- squashFK: (fk4) => {
4707
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo ?? ""}`;
4708
- },
4709
- squashPK: (pk) => {
4710
- return `${pk.columns.join(",")};${pk.name}`;
4711
- },
4712
- unsquashPK: (pk) => {
4713
- const splitted = pk.split(";");
4714
- return { name: splitted[1], columns: splitted[0].split(",") };
4715
- },
4716
- squashUnique: (unq) => {
4717
- return `${unq.name};${unq.columns.join(",")};${unq.nullsNotDistinct}`;
4718
- },
4719
- unsquashUnique: (unq) => {
4720
- const [name, columns, nullsNotDistinct] = unq.split(";");
4721
- return {
4722
- name,
4723
- columns: columns.split(","),
4724
- nullsNotDistinct: nullsNotDistinct === "true"
4725
- };
4726
- },
4727
- unsquashFK: (input) => {
4728
- const [
4729
- name,
4730
- tableFrom,
4731
- columnsFromStr,
4732
- tableTo,
4733
- columnsToStr,
4734
- onUpdate,
4735
- onDelete,
4736
- schemaTo
4737
- ] = input.split(";");
4738
- const result = fk2.parse({
4739
- name,
4740
- tableFrom,
4741
- columnsFrom: columnsFromStr.split(","),
4742
- schemaTo,
4743
- tableTo,
4744
- columnsTo: columnsToStr.split(","),
4745
- onUpdate,
4746
- onDelete
4747
- });
4748
- return result;
4749
- }
4750
- };
4751
- var squashPgScheme = (json) => {
4752
- const mappedTables = Object.fromEntries(
4753
- Object.entries(json.tables).map((it) => {
4754
- const squashedIndexes = mapValues(it[1].indexes, (index4) => {
4755
- return PgSquasher.squashIdx(index4);
4756
- });
4757
- const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
4758
- return PgSquasher.squashFK(fk4);
4759
- });
4760
- const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
4761
- return PgSquasher.squashPK(pk);
4762
- });
4763
- const squashedUniqueConstraints = mapValues(
4764
- it[1].uniqueConstraints,
4765
- (unq) => {
4766
- return PgSquasher.squashUnique(unq);
4767
- }
4768
- );
4769
- return [
4770
- it[0],
4771
- {
4772
- name: it[1].name,
4773
- schema: it[1].schema,
4774
- columns: it[1].columns,
4775
- indexes: squashedIndexes,
4776
- foreignKeys: squashedFKs,
4777
- compositePrimaryKeys: squashedPKs,
4778
- uniqueConstraints: squashedUniqueConstraints
4779
- }
4780
- ];
4781
- })
4782
- );
4783
- return {
4784
- version: "5",
4785
- dialect: json.dialect,
4786
- tables: mappedTables,
4787
- enums: json.enums,
4788
- schemas: json.schemas
4789
- };
4790
- };
4791
- var dryPg = pgSchema.parse({
4792
- version: snapshotVersion,
4793
- dialect: "pg",
4794
- id: originUUID,
4795
- prevId: "",
4796
- tables: {},
4797
- enums: {},
4798
- schemas: {},
4799
- _meta: {
4800
- schemas: {},
4801
- tables: {},
4802
- columns: {}
4803
- }
4804
- });
4805
-
4806
- // src/serializer/sqliteSchema.ts
4807
- init_lib();
4808
- var index3 = objectType({
4809
- name: stringType(),
4810
- columns: stringType().array(),
4811
- where: stringType().optional(),
4812
- isUnique: booleanType()
4813
- }).strict();
4814
- var fk3 = objectType({
4815
- name: stringType(),
4816
- tableFrom: stringType(),
4817
- columnsFrom: stringType().array(),
4818
- tableTo: stringType(),
4819
- columnsTo: stringType().array(),
4820
- onUpdate: stringType().optional(),
4821
- onDelete: stringType().optional()
4822
- }).strict();
4823
- var compositePK3 = objectType({
4824
- columns: stringType().array(),
4825
- name: stringType().optional()
4826
- }).strict();
4827
- var column3 = objectType({
4828
- name: stringType(),
4829
- type: stringType(),
4830
- primaryKey: booleanType(),
4831
- notNull: booleanType(),
4832
- autoincrement: booleanType().optional(),
4833
- default: anyType().optional()
4834
- }).strict();
4835
- var tableV33 = objectType({
4836
- name: stringType(),
4837
- columns: recordType(stringType(), column3),
4838
- indexes: recordType(stringType(), index3),
4839
- foreignKeys: recordType(stringType(), fk3)
4840
- }).strict();
4841
- var uniqueConstraint3 = objectType({
4842
- name: stringType(),
4843
- columns: stringType().array()
4844
- }).strict();
4845
- var table3 = objectType({
4846
- name: stringType(),
4847
- columns: recordType(stringType(), column3),
4848
- indexes: recordType(stringType(), index3),
4849
- foreignKeys: recordType(stringType(), fk3),
4850
- compositePrimaryKeys: recordType(stringType(), compositePK3),
4851
- uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
4852
- }).strict();
4853
- var dialect2 = enumType(["sqlite"]);
4854
- var schemaHash3 = objectType({
4855
- id: stringType(),
4856
- prevId: stringType()
4857
- }).strict();
4858
- var schemaInternalV32 = objectType({
4859
- version: literalType("3"),
4860
- dialect: dialect2,
4861
- tables: recordType(stringType(), tableV33),
4862
- enums: objectType({})
4863
- }).strict();
4864
- var schemaInternalV42 = objectType({
4865
- version: literalType("4"),
4866
- dialect: dialect2,
4867
- tables: recordType(stringType(), table3),
4868
- enums: objectType({})
4869
- }).strict();
4870
- var latestVersion = literalType("5");
4871
- var schemaInternal2 = objectType({
4872
- version: latestVersion,
4873
- dialect: dialect2,
4874
- tables: recordType(stringType(), table3),
4875
- enums: objectType({}),
4876
- _meta: objectType({
4877
- tables: recordType(stringType(), stringType()),
4878
- columns: recordType(stringType(), stringType())
4879
- })
4880
- }).strict();
4881
- var schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
4882
- var schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
4883
- var schema2 = schemaInternal2.merge(schemaHash3).strict();
4884
- var tableSquashed3 = objectType({
4885
- name: stringType(),
4886
- columns: recordType(stringType(), column3),
4887
- indexes: recordType(stringType(), stringType()),
4888
- foreignKeys: recordType(stringType(), stringType()),
4889
- compositePrimaryKeys: recordType(stringType(), stringType()),
4890
- uniqueConstraints: recordType(stringType(), stringType()).default({})
4891
- }).strict();
4892
- var schemaSquashed2 = objectType({
4893
- version: latestVersion,
4894
- dialect: dialect2,
4895
- tables: recordType(stringType(), tableSquashed3),
4896
- enums: anyType()
4897
- }).strict();
4898
- var SQLiteSquasher = {
4899
- squashIdx: (idx) => {
4900
- index3.parse(idx);
4901
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique};${idx.where ?? ""}`;
4902
- },
4903
- unsquashIdx: (input) => {
4904
- const [name, columnsString, isUnique, where] = input.split(";");
4905
- const result = index3.parse({
4906
- name,
4907
- columns: columnsString.split(","),
4908
- isUnique: isUnique === "true",
4909
- where: where ?? void 0
4910
- });
4911
- return result;
4912
- },
4913
- squashUnique: (unq) => {
4914
- return `${unq.name};${unq.columns.join(",")}`;
4915
- },
4916
- unsquashUnique: (unq) => {
4917
- const [name, columns] = unq.split(";");
4918
- return { name, columns: columns.split(",") };
4919
- },
4920
- squashFK: (fk4) => {
4921
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4922
- },
4923
- unsquashFK: (input) => {
4924
- const [
4925
- name,
4926
- tableFrom,
4927
- columnsFromStr,
4928
- tableTo,
4929
- columnsToStr,
4930
- onUpdate,
4931
- onDelete
4932
- ] = input.split(";");
4933
- const result = fk3.parse({
4934
- name,
4935
- tableFrom,
4936
- columnsFrom: columnsFromStr.split(","),
4937
- tableTo,
4938
- columnsTo: columnsToStr.split(","),
4939
- onUpdate,
4940
- onDelete
4941
- });
4942
- return result;
4943
- },
4944
- squashPK: (pk) => {
4945
- return pk.columns.join(",");
4946
- },
4947
- unsquashPK: (pk) => {
4948
- return pk.split(",");
4949
- }
4950
- };
4951
- var drySQLite = schema2.parse({
4952
- version: snapshotVersion,
4953
- dialect: "sqlite",
4954
- id: originUUID,
4955
- prevId: "",
4956
- tables: {},
4957
- enums: {},
4958
- _meta: {
4959
- tables: {},
4960
- columns: {}
4961
- }
4962
- });
4963
- var backwardCompatibleSqliteSchema = unionType([schemaV32, schemaV42, schema2]);
4964
-
4965
- // src/utils.ts
5028
+ init_mysqlSchema();
5029
+ init_pgSchema();
5030
+ init_sqliteSchema();
4966
5031
  init_source();
4967
5032
  var import_path = require("path");
5033
+ init_global();
4968
5034
 
4969
5035
  // src/jsonDiffer.js
4970
5036
  var import_json_diff = require("json-diff");
@@ -5206,17 +5272,30 @@ var alternationsInColumn = (column4) => {
5206
5272
  return result[0];
5207
5273
  };
5208
5274
 
5275
+ // src/cli/commands/upFolders.ts
5276
+ init_mysqlSchema();
5277
+ init_sqliteSchema();
5278
+
5209
5279
  // src/migrationPreparator.ts
5210
5280
  init_serializer();
5281
+ init_pgSchema();
5282
+ init_sqliteSchema();
5283
+ init_mysqlSchema();
5211
5284
 
5212
5285
  // src/cli/commands/migrate.ts
5213
5286
  var import_hanji2 = __toESM(require_hanji());
5214
5287
  init_views();
5215
5288
  init_source();
5289
+ init_pgSchema();
5290
+ init_sqliteSchema();
5291
+ init_mysqlSchema();
5216
5292
  init_outputs();
5217
5293
  var BREAKPOINT = "--> statement-breakpoint\n";
5218
5294
 
5219
5295
  // src/sqlgenerator.ts
5296
+ init_mysqlSchema();
5297
+ init_pgSchema();
5298
+ init_sqliteSchema();
5220
5299
  var pgNativeTypes = /* @__PURE__ */ new Set([
5221
5300
  "uuid",
5222
5301
  "smallint",
@@ -6528,17 +6607,20 @@ drop type __venum;
6528
6607
  init_lib();
6529
6608
 
6530
6609
  // src/jsonStatements.ts
6610
+ init_mysqlSchema();
6611
+ init_pgSchema();
6612
+ init_sqliteSchema();
6531
6613
  var preparePgCreateTableJson = (table4, json2) => {
6532
6614
  const { name, schema: schema4, columns, compositePrimaryKeys, uniqueConstraints } = table4;
6615
+ const tableKey = `${schema4 || "public"}.${name}`;
6616
+ const compositePkName = Object.values(compositePrimaryKeys).length > 0 ? json2.tables[tableKey].compositePrimaryKeys[`${PgSquasher.unsquashPK(Object.values(compositePrimaryKeys)[0]).name}`].name : "";
6533
6617
  return {
6534
6618
  type: "create_table",
6535
6619
  tableName: name,
6536
6620
  schema: schema4,
6537
6621
  columns: Object.values(columns),
6538
6622
  compositePKs: Object.values(compositePrimaryKeys),
6539
- compositePkName: Object.values(compositePrimaryKeys).length > 0 ? json2.tables[name].compositePrimaryKeys[`${PgSquasher.unsquashPK(
6540
- Object.values(compositePrimaryKeys)[0]
6541
- ).name}`].name : "",
6623
+ compositePkName,
6542
6624
  uniqueConstraints: Object.values(uniqueConstraints)
6543
6625
  };
6544
6626
  };
@@ -6640,7 +6722,8 @@ var prepareRenameColumns = (tableName, schema4, pairs) => {
6640
6722
  var prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, json2, dialect3) => {
6641
6723
  const addColumns = [];
6642
6724
  const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
6643
- const alterColumns = _prepareAlterColumns(tableName, schema4, altered, json2);
6725
+ const tableKey = `${schema4 || "public"}.${tableName}`;
6726
+ const alterColumns = _prepareAlterColumns(tableKey, schema4, altered, json2);
6644
6727
  if (dialect3 === "sqlite") {
6645
6728
  let jsonCreateFKStatements = Object.values(addedFk);
6646
6729
  const sqliteAddColumns = _prepareSQLiteAddColumns(
@@ -6690,19 +6773,22 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
6690
6773
  };
6691
6774
  });
6692
6775
  };
6693
- var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
6776
+ var _prepareAlterColumns = (tableKey, schema4, columns, json2) => {
6694
6777
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
6695
6778
  let statements = [];
6696
6779
  let dropPkStatements = [];
6697
6780
  let setPkStatements = [];
6698
6781
  for (const column4 of columns) {
6699
6782
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
6700
- const columnType = json2.tables[tableName].columns[columnName].type;
6701
- const columnDefault = json2.tables[tableName].columns[columnName].default;
6702
- const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
6703
- const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
6704
- const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
6705
- const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
6783
+ const table4 = json2.tables[tableKey];
6784
+ const tableName = table4.name;
6785
+ const snapshotColumn = table4.columns[columnName];
6786
+ const columnType = snapshotColumn.type;
6787
+ const columnDefault = snapshotColumn.default;
6788
+ const columnOnUpdate = "onUpdate" in snapshotColumn ? snapshotColumn.onUpdate : void 0;
6789
+ const columnNotNull = table4.columns[columnName].notNull;
6790
+ const columnAutoIncrement = "autoincrement" in snapshotColumn ? snapshotColumn.autoincrement ?? false : false;
6791
+ const columnPk = table4.columns[columnName].primaryKey;
6706
6792
  if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
6707
6793
  statements.push({
6708
6794
  type: "alter_table_alter_column_set_autoincrement",
@@ -6749,13 +6835,14 @@ var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
6749
6835
  }
6750
6836
  for (const column4 of columns) {
6751
6837
  const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
6752
- const columnType = json2.tables[tableName].columns[columnName].type;
6753
- const columnDefault = json2.tables[tableName].columns[columnName].default;
6754
- const columnOnUpdate = json2.tables[tableName].columns[columnName].onUpdate;
6755
- const columnNotNull = json2.tables[tableName].columns[columnName].notNull;
6756
- const columnAutoIncrement = json2.tables[tableName].columns[columnName].autoincrement;
6757
- const columnPk = json2.tables[tableName].columns[columnName].primaryKey;
6758
- const compositePk = json2.tables[tableName].compositePrimaryKeys[`${tableName}_${columnName}`];
6838
+ const tableName = json2.tables[tableKey].name;
6839
+ const columnType = json2.tables[tableKey].columns[columnName].type;
6840
+ const columnDefault = json2.tables[tableKey].columns[columnName].default;
6841
+ const columnOnUpdate = json2.tables[tableKey].columns[columnName].onUpdate;
6842
+ const columnNotNull = json2.tables[tableKey].columns[columnName].notNull;
6843
+ const columnAutoIncrement = json2.tables[tableKey].columns[columnName].autoincrement;
6844
+ const columnPk = json2.tables[tableKey].columns[columnName].primaryKey;
6845
+ const compositePk = json2.tables[tableKey].compositePrimaryKeys[`${tableName}_${columnName}`];
6759
6846
  if (typeof column4.name !== "string") {
6760
6847
  statements.push({
6761
6848
  type: "alter_table_rename_column",
@@ -7101,6 +7188,9 @@ var prepareAlterCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
7101
7188
  };
7102
7189
 
7103
7190
  // src/snapshotsDiffer.ts
7191
+ init_sqliteSchema();
7192
+ init_mysqlSchema();
7193
+ init_global();
7104
7194
  var makeChanged = (schema4) => {
7105
7195
  return objectType({
7106
7196
  type: enumType(["changed"]),
@@ -7139,7 +7229,7 @@ var makeSelfOrPatched = (schema4) => {
7139
7229
  return unionType([
7140
7230
  objectType({
7141
7231
  type: literalType("none"),
7142
- value: schema4.optional()
7232
+ value: schema4
7143
7233
  }),
7144
7234
  objectType({
7145
7235
  type: literalType("added"),
@@ -7263,7 +7353,6 @@ var diffResultScheme = objectType({
7263
7353
  }).strict();
7264
7354
  var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
7265
7355
  var _a, _b;
7266
- let diffResult;
7267
7356
  if (dialect3 === "mysql") {
7268
7357
  for (const tableName in json1.tables) {
7269
7358
  const table4 = json1.tables[tableName];
@@ -7291,13 +7380,26 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7291
7380
  }
7292
7381
  }
7293
7382
  }
7294
- diffResult = applyJsonDiff(json1, json2);
7295
7383
  }
7296
- diffResult = applyJsonDiff(json1, json2);
7384
+ const diffResult = applyJsonDiff(json1, json2);
7297
7385
  if (Object.keys(diffResult).length === 0) {
7298
7386
  return { statements: [], sqlStatements: [], _meta: void 0 };
7299
7387
  }
7300
7388
  const typedResult = diffResultScheme.parse(diffResult);
7389
+ typedResult.alteredTablesWithColumns = typedResult.alteredTablesWithColumns.map((it) => {
7390
+ let schemaToTrim;
7391
+ if (it.schema.type === "none") {
7392
+ schemaToTrim = it.schema.value || "public";
7393
+ } else if (it.schema.type === "deleted") {
7394
+ schemaToTrim = it.schema.value;
7395
+ } else if (it.schema.type === "added") {
7396
+ schemaToTrim = "public";
7397
+ } else {
7398
+ schemaToTrim = it.schema.old;
7399
+ }
7400
+ it.name = it.name.substring(schemaToTrim.length + 1);
7401
+ return it;
7402
+ });
7301
7403
  const {
7302
7404
  created: createdSchemas,
7303
7405
  deleted: deletedSchemas,
@@ -7449,7 +7551,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7449
7551
  prevFull,
7450
7552
  curFull
7451
7553
  );
7452
- } else {
7554
+ } else if (dialect3 === "mysql") {
7453
7555
  addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
7454
7556
  it.name,
7455
7557
  it.addedCompositePKs,
@@ -7467,6 +7569,8 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7467
7569
  prevFull,
7468
7570
  curFull
7469
7571
  );
7572
+ } else {
7573
+ assertUnreachable(dialect3);
7470
7574
  }
7471
7575
  let addedUniqueConstraints = [];
7472
7576
  let deletedUniqueConstraints = [];
@@ -7657,11 +7761,13 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7657
7761
  return preparePgCreateTableJson(it, curFull);
7658
7762
  });
7659
7763
  jsonStatements.push(...jsonPgCreateTables);
7660
- } else {
7764
+ } else if (dialect3 === "mysql") {
7661
7765
  const jsonMySqlCreateTables = created.map((it) => {
7662
7766
  return prepareMySqlCreateTableJson(it, curFull);
7663
7767
  });
7664
7768
  jsonStatements.push(...jsonMySqlCreateTables);
7769
+ } else {
7770
+ assertUnreachable(dialect3);
7665
7771
  }
7666
7772
  jsonStatements.push(...jsonDropTables);
7667
7773
  jsonStatements.push(...jsonRenameTables);
@@ -7711,9 +7817,15 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
7711
7817
 
7712
7818
  // src/cli/commands/pgUp.ts
7713
7819
  init_source();
7820
+ init_global();
7821
+ init_pgSchema();
7822
+
7823
+ // src/cli/commands/upFolders.ts
7824
+ init_pgSchema();
7714
7825
 
7715
7826
  // src/cli/commands/mysqlUp.ts
7716
7827
  init_source();
7828
+ init_mysqlSchema();
7717
7829
 
7718
7830
  // src/cli/commands/upFolders.ts
7719
7831
  var resolveSchemas = (missingSchemas, newSchemas, predicate) => {
@@ -7814,7 +7926,7 @@ var resolveColumns = (missingColumns, newColumns, predicate) => {
7814
7926
  };
7815
7927
 
7816
7928
  // src/utils.ts
7817
- var assertV1OutFolder = (out, dialect3) => {
7929
+ var assertV1OutFolder = (out) => {
7818
7930
  if (!(0, import_fs.existsSync)(out))
7819
7931
  return;
7820
7932
  const oldMigrationFolders = (0, import_fs.readdirSync)(out).filter(
@@ -7823,7 +7935,7 @@ var assertV1OutFolder = (out, dialect3) => {
7823
7935
  if (oldMigrationFolders.length > 0) {
7824
7936
  console.log(
7825
7937
  `Your migrations folder format is outdated, please run ${source_default.green.bold(
7826
- `drizzle-kit up:${dialect3}`
7938
+ `drizzle-kit up`
7827
7939
  )}`
7828
7940
  );
7829
7941
  process.exit(1);
@@ -7847,7 +7959,7 @@ var snapshotsPriorV4 = (out) => {
7847
7959
  return pathJson;
7848
7960
  });
7849
7961
  };
7850
- var prepareOutFolder2 = (out, dialect3) => {
7962
+ var prepareOutFolder = (out, dialect3) => {
7851
7963
  const meta = (0, import_path.join)(out, "meta");
7852
7964
  const journalPath = (0, import_path.join)(meta, "_journal.json");
7853
7965
  if (!(0, import_fs.existsSync)((0, import_path.join)(out, "meta"))) {
@@ -7862,9 +7974,9 @@ var prepareOutFolder2 = (out, dialect3) => {
7862
7974
  var validatorForDialect = (dialect3) => {
7863
7975
  switch (dialect3) {
7864
7976
  case "pg":
7865
- return { validator: backwardCompatiblePgSchema, version: 5 };
7977
+ return { validator: backwardCompatiblePgSchema, version: 6 };
7866
7978
  case "sqlite":
7867
- return { validator: backwardCompatibleSqliteSchema, version: 5 };
7979
+ return { validator: backwardCompatibleSqliteSchema, version: 6 };
7868
7980
  case "mysql":
7869
7981
  return { validator: backwardCompatibleMysqlSchema, version: 5 };
7870
7982
  }
@@ -7912,13 +8024,13 @@ var validateWithReport = (snapshots, dialect3) => {
7912
8024
  return result;
7913
8025
  };
7914
8026
  var prepareMigrationFolder = (outFolder = "drizzle", dialect3) => {
7915
- const { snapshots, journal } = prepareOutFolder2(outFolder, dialect3);
8027
+ const { snapshots, journal } = prepareOutFolder(outFolder, dialect3);
7916
8028
  const report = validateWithReport(snapshots, dialect3);
7917
8029
  if (report.nonLatest.length > 0) {
7918
8030
  console.log(
7919
8031
  report.nonLatest.map((it) => {
7920
8032
  return `${it}/snapshot.json is not of the latest version`;
7921
- }).concat(`Run ${source_default.green.bold(`drizzle-kit up:${dialect3}`)}`).join("\n")
8033
+ }).concat(`Run ${source_default.green.bold(`drizzle-kit up`)}`).join("\n")
7922
8034
  );
7923
8035
  process.exit(0);
7924
8036
  }
@@ -8051,7 +8163,9 @@ var statementsForDiffs = async (in1, in2) => {
8051
8163
  "pg",
8052
8164
  schemasResolver,
8053
8165
  tablesResolver,
8054
- columnsResolver
8166
+ columnsResolver,
8167
+ left,
8168
+ right
8055
8169
  );
8056
8170
  return { ...result, left, right };
8057
8171
  };