drizzle-kit 0.20.14-a183d8b → 0.20.14-c82ab68
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +4957 -4374
- package/cli/commands/migrate.d.ts +17 -17
- package/cli/commands/mysqlIntrospect.d.ts +8 -8
- package/cli/commands/mysqlUp.d.ts +2 -2
- package/cli/commands/pgIntrospect.d.ts +11 -8
- package/cli/commands/pgUp.d.ts +2 -2
- package/cli/commands/sqliteIntrospect.d.ts +8 -8
- package/cli/commands/utils.d.ts +4 -5
- package/cli/{index.d.ts → validations/cli.d.ts} +30 -20
- package/cli/validations/common.d.ts +1 -1
- package/global.d.ts +1 -1
- package/index.js +1 -0
- package/introspect-pg.d.ts +4 -1
- package/jsonStatements.d.ts +1 -1
- package/package.json +3 -1
- package/payload.js +565 -113
- package/payload.mjs +564 -113
- package/schemaValidator.d.ts +39 -39
- package/serializer/mysqlSchema.d.ts +1991 -753
- package/serializer/pgSchema.d.ts +1113 -788
- package/serializer/sqliteSchema.d.ts +144 -570
- package/snapshotsDiffer.d.ts +24 -20
- package/utils-studio.js +379 -9
- package/utils-studio.mjs +378 -9
- package/utils.d.ts +12 -12
- package/utils.js +146 -85
- package/utils.mjs +145 -85
- package/cli/commands/check.d.ts +0 -2
- package/cli/commands/drop.d.ts +0 -4
- package/cli/commands/push.d.ts +0 -6
- package/cli/commands/sqliteUp.d.ts +0 -2
- package/cli/utils.d.ts +0 -12
- package/cli/validations/studio.d.ts +0 -593
- package/orm-extenstions/d1-driver/driver.d.ts +0 -8
- package/orm-extenstions/d1-driver/session.d.ts +0 -51
- package/orm-extenstions/d1-driver/wrangler-client.d.ts +0 -3
- package/serializer/studioUtils.d.ts +0 -65
- package/utils/certs.d.ts +0 -4
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 = "") => {
|
@@ -1087,11 +1089,15 @@ var init_views = __esm({
|
|
1087
1089
|
});
|
1088
1090
|
|
1089
1091
|
// src/global.ts
|
1092
|
+
function assertUnreachable(x) {
|
1093
|
+
throw new Error("Didn't expect to get here");
|
1094
|
+
}
|
1090
1095
|
var originUUID, snapshotVersion, mapValues;
|
1091
1096
|
var init_global = __esm({
|
1092
1097
|
"src/global.ts"() {
|
1098
|
+
"use strict";
|
1093
1099
|
originUUID = "00000000-0000-0000-0000-000000000000";
|
1094
|
-
snapshotVersion = "
|
1100
|
+
snapshotVersion = "6";
|
1095
1101
|
mapValues = (obj, map) => {
|
1096
1102
|
const result = Object.keys(obj).reduce(function(result2, key) {
|
1097
1103
|
result2[key] = map(obj[key]);
|
@@ -4242,9 +4248,10 @@ var init_lib = __esm({
|
|
4242
4248
|
});
|
4243
4249
|
|
4244
4250
|
// src/serializer/mysqlSchema.ts
|
4245
|
-
var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4,
|
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;
|
4246
4252
|
var init_mysqlSchema = __esm({
|
4247
4253
|
"src/serializer/mysqlSchema.ts"() {
|
4254
|
+
"use strict";
|
4248
4255
|
init_global();
|
4249
4256
|
init_lib();
|
4250
4257
|
index = objectType({
|
@@ -4303,6 +4310,17 @@ var init_mysqlSchema = __esm({
|
|
4303
4310
|
compositePrimaryKeys: recordType(stringType(), compositePK),
|
4304
4311
|
uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
|
4305
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();
|
4306
4324
|
dialect = literalType("mysql");
|
4307
4325
|
schemaHash = objectType({
|
4308
4326
|
id: stringType(),
|
@@ -4319,18 +4337,7 @@ var init_mysqlSchema = __esm({
|
|
4319
4337
|
tables: recordType(stringType(), tableV4),
|
4320
4338
|
schemas: recordType(stringType(), stringType())
|
4321
4339
|
}).strict();
|
4322
|
-
|
4323
|
-
tables: recordType(
|
4324
|
-
stringType(),
|
4325
|
-
objectType({
|
4326
|
-
columns: recordType(
|
4327
|
-
stringType(),
|
4328
|
-
objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
|
4329
|
-
)
|
4330
|
-
}).optional()
|
4331
|
-
)
|
4332
|
-
}).optional();
|
4333
|
-
schemaInternal = objectType({
|
4340
|
+
schemaInternalV5 = objectType({
|
4334
4341
|
version: literalType("5"),
|
4335
4342
|
dialect,
|
4336
4343
|
tables: recordType(stringType(), table),
|
@@ -4342,8 +4349,33 @@ var init_mysqlSchema = __esm({
|
|
4342
4349
|
}),
|
4343
4350
|
internal: kitInternals
|
4344
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();
|
4345
4376
|
schemaV3 = schemaInternalV3.merge(schemaHash);
|
4346
4377
|
schemaV4 = schemaInternalV4.merge(schemaHash);
|
4378
|
+
schemaV5 = schemaInternalV5.merge(schemaHash);
|
4347
4379
|
schema = schemaInternal.merge(schemaHash);
|
4348
4380
|
tableSquashedV4 = objectType({
|
4349
4381
|
name: stringType(),
|
@@ -4430,11 +4462,8 @@ var init_mysqlSchema = __esm({
|
|
4430
4462
|
}
|
4431
4463
|
};
|
4432
4464
|
mysqlSchema = schema;
|
4433
|
-
|
4434
|
-
|
4435
|
-
schemaV4,
|
4436
|
-
schema
|
4437
|
-
]);
|
4465
|
+
mysqlSchemaV5 = schemaV5;
|
4466
|
+
backwardCompatibleMysqlSchema = unionType([mysqlSchemaV5, schema]);
|
4438
4467
|
dryMySql = mysqlSchema.parse({
|
4439
4468
|
version: snapshotVersion,
|
4440
4469
|
dialect: "mysql",
|
@@ -4452,9 +4481,10 @@ var init_mysqlSchema = __esm({
|
|
4452
4481
|
});
|
4453
4482
|
|
4454
4483
|
// src/serializer/pgSchema.ts
|
4455
|
-
var indexV2, columnV2, tableV2, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, table2, schemaHash2, pgSchemaInternalV3, pgSchemaInternalV4,
|
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;
|
4456
4485
|
var init_pgSchema = __esm({
|
4457
4486
|
"src/serializer/pgSchema.ts"() {
|
4487
|
+
"use strict";
|
4458
4488
|
init_global();
|
4459
4489
|
init_lib();
|
4460
4490
|
indexV2 = objectType({
|
@@ -4574,6 +4604,21 @@ var init_pgSchema = __esm({
|
|
4574
4604
|
id: stringType(),
|
4575
4605
|
prevId: stringType()
|
4576
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();
|
4577
4622
|
pgSchemaInternalV3 = objectType({
|
4578
4623
|
version: literalType("3"),
|
4579
4624
|
dialect: literalType("pg"),
|
@@ -4587,6 +4632,19 @@ var init_pgSchema = __esm({
|
|
4587
4632
|
enums: recordType(stringType(), enumSchema),
|
4588
4633
|
schemas: recordType(stringType(), stringType())
|
4589
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();
|
4590
4648
|
pgSchemaExternal = objectType({
|
4591
4649
|
version: literalType("5"),
|
4592
4650
|
dialect: literalType("pg"),
|
@@ -4599,23 +4657,8 @@ var init_pgSchema = __esm({
|
|
4599
4657
|
columns: recordType(stringType(), stringType())
|
4600
4658
|
})
|
4601
4659
|
}).strict();
|
4602
|
-
kitInternals2 = objectType({
|
4603
|
-
tables: recordType(
|
4604
|
-
stringType(),
|
4605
|
-
objectType({
|
4606
|
-
columns: recordType(
|
4607
|
-
stringType(),
|
4608
|
-
objectType({
|
4609
|
-
isArray: booleanType().optional(),
|
4610
|
-
dimensions: numberType().optional(),
|
4611
|
-
rawType: stringType().optional()
|
4612
|
-
}).optional()
|
4613
|
-
)
|
4614
|
-
}).optional()
|
4615
|
-
)
|
4616
|
-
}).optional();
|
4617
4660
|
pgSchemaInternal = objectType({
|
4618
|
-
version: literalType("
|
4661
|
+
version: literalType("6"),
|
4619
4662
|
dialect: literalType("pg"),
|
4620
4663
|
tables: recordType(stringType(), table2),
|
4621
4664
|
enums: recordType(stringType(), enumSchema),
|
@@ -4651,7 +4694,7 @@ var init_pgSchema = __esm({
|
|
4651
4694
|
schemas: recordType(stringType(), stringType())
|
4652
4695
|
}).strict();
|
4653
4696
|
pgSchemaSquashed = objectType({
|
4654
|
-
version: literalType("
|
4697
|
+
version: literalType("6"),
|
4655
4698
|
dialect: enumType(["pg"]),
|
4656
4699
|
tables: recordType(stringType(), tableSquashed2),
|
4657
4700
|
enums: recordType(stringType(), enumSchema),
|
@@ -4659,14 +4702,9 @@ var init_pgSchema = __esm({
|
|
4659
4702
|
}).strict();
|
4660
4703
|
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
4661
4704
|
pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
|
4705
|
+
pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
|
4662
4706
|
pgSchema = pgSchemaInternal.merge(schemaHash2);
|
4663
|
-
backwardCompatiblePgSchema = unionType([
|
4664
|
-
pgSchemaV1,
|
4665
|
-
pgSchemaV2,
|
4666
|
-
pgSchemaV3,
|
4667
|
-
pgSchemaV4,
|
4668
|
-
pgSchema
|
4669
|
-
]);
|
4707
|
+
backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema]);
|
4670
4708
|
PgSquasher = {
|
4671
4709
|
squashIdx: (idx) => {
|
4672
4710
|
index2.parse(idx);
|
@@ -4682,7 +4720,7 @@ var init_pgSchema = __esm({
|
|
4682
4720
|
return result;
|
4683
4721
|
},
|
4684
4722
|
squashFK: (fk4) => {
|
4685
|
-
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo
|
4723
|
+
return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo || "public"}`;
|
4686
4724
|
},
|
4687
4725
|
squashPK: (pk) => {
|
4688
4726
|
return `${pk.columns.join(",")};${pk.name}`;
|
@@ -4759,7 +4797,7 @@ var init_pgSchema = __esm({
|
|
4759
4797
|
})
|
4760
4798
|
);
|
4761
4799
|
return {
|
4762
|
-
version: "
|
4800
|
+
version: "6",
|
4763
4801
|
dialect: json.dialect,
|
4764
4802
|
tables: mappedTables,
|
4765
4803
|
enums: json.enums,
|
@@ -4787,6 +4825,7 @@ var init_pgSchema = __esm({
|
|
4787
4825
|
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema2, tableSquashed3, schemaSquashed2, SQLiteSquasher, drySQLite, backwardCompatibleSqliteSchema;
|
4788
4826
|
var init_sqliteSchema = __esm({
|
4789
4827
|
"src/serializer/sqliteSchema.ts"() {
|
4828
|
+
"use strict";
|
4790
4829
|
init_global();
|
4791
4830
|
init_lib();
|
4792
4831
|
index3 = objectType({
|
@@ -4933,7 +4972,7 @@ var init_sqliteSchema = __esm({
|
|
4933
4972
|
}
|
4934
4973
|
};
|
4935
4974
|
drySQLite = schema2.parse({
|
4936
|
-
version:
|
4975
|
+
version: "5",
|
4937
4976
|
dialect: "sqlite",
|
4938
4977
|
id: originUUID,
|
4939
4978
|
prevId: "",
|
@@ -4944,11 +4983,7 @@ var init_sqliteSchema = __esm({
|
|
4944
4983
|
columns: {}
|
4945
4984
|
}
|
4946
4985
|
});
|
4947
|
-
backwardCompatibleSqliteSchema =
|
4948
|
-
schemaV32,
|
4949
|
-
schemaV42,
|
4950
|
-
schema2
|
4951
|
-
]);
|
4986
|
+
backwardCompatibleSqliteSchema = schema2;
|
4952
4987
|
}
|
4953
4988
|
});
|
4954
4989
|
|
@@ -4956,6 +4991,7 @@ var init_sqliteSchema = __esm({
|
|
4956
4991
|
var glob;
|
4957
4992
|
var init_serializer = __esm({
|
4958
4993
|
"src/serializer/index.ts"() {
|
4994
|
+
"use strict";
|
4959
4995
|
glob = __toESM(require("glob"));
|
4960
4996
|
init_source();
|
4961
4997
|
init_views();
|
@@ -4965,6 +5001,7 @@ var init_serializer = __esm({
|
|
4965
5001
|
// src/cli/validations/outputs.ts
|
4966
5002
|
var init_outputs = __esm({
|
4967
5003
|
"src/cli/validations/outputs.ts"() {
|
5004
|
+
"use strict";
|
4968
5005
|
init_source();
|
4969
5006
|
}
|
4970
5007
|
});
|
@@ -4978,7 +5015,7 @@ __export(utils_exports, {
|
|
4978
5015
|
kloudMeta: () => kloudMeta,
|
4979
5016
|
prepareMigrationFolder: () => prepareMigrationFolder,
|
4980
5017
|
prepareMigrationMeta: () => prepareMigrationMeta,
|
4981
|
-
prepareOutFolder: () =>
|
5018
|
+
prepareOutFolder: () => prepareOutFolder,
|
4982
5019
|
schemaRenameKey: () => schemaRenameKey,
|
4983
5020
|
snapshotsPriorV4: () => snapshotsPriorV4,
|
4984
5021
|
statementsForDiffs: () => statementsForDiffs,
|
@@ -6575,15 +6612,15 @@ init_pgSchema();
|
|
6575
6612
|
init_sqliteSchema();
|
6576
6613
|
var preparePgCreateTableJson = (table4, json2) => {
|
6577
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 : "";
|
6578
6617
|
return {
|
6579
6618
|
type: "create_table",
|
6580
6619
|
tableName: name,
|
6581
6620
|
schema: schema4,
|
6582
6621
|
columns: Object.values(columns),
|
6583
6622
|
compositePKs: Object.values(compositePrimaryKeys),
|
6584
|
-
compositePkName
|
6585
|
-
Object.values(compositePrimaryKeys)[0]
|
6586
|
-
).name}`].name : "",
|
6623
|
+
compositePkName,
|
6587
6624
|
uniqueConstraints: Object.values(uniqueConstraints)
|
6588
6625
|
};
|
6589
6626
|
};
|
@@ -6685,7 +6722,8 @@ var prepareRenameColumns = (tableName, schema4, pairs) => {
|
|
6685
6722
|
var prepareAlterTableColumnsJson = (tableName, schema4, deleted, added, altered, addedFk, json2, dialect3) => {
|
6686
6723
|
const addColumns = [];
|
6687
6724
|
const dropColumns = _prepareDropColumns(tableName, schema4, deleted);
|
6688
|
-
const
|
6725
|
+
const tableKey = `${schema4 || "public"}.${tableName}`;
|
6726
|
+
const alterColumns = _prepareAlterColumns(tableKey, schema4, altered, json2);
|
6689
6727
|
if (dialect3 === "sqlite") {
|
6690
6728
|
let jsonCreateFKStatements = Object.values(addedFk);
|
6691
6729
|
const sqliteAddColumns = _prepareSQLiteAddColumns(
|
@@ -6735,19 +6773,22 @@ var _prepareSQLiteAddColumns = (tableName, columns, referenceData) => {
|
|
6735
6773
|
};
|
6736
6774
|
});
|
6737
6775
|
};
|
6738
|
-
var _prepareAlterColumns = (
|
6776
|
+
var _prepareAlterColumns = (tableKey, schema4, columns, json2) => {
|
6739
6777
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
6740
6778
|
let statements = [];
|
6741
6779
|
let dropPkStatements = [];
|
6742
6780
|
let setPkStatements = [];
|
6743
6781
|
for (const column4 of columns) {
|
6744
6782
|
const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
|
6745
|
-
const
|
6746
|
-
const
|
6747
|
-
const
|
6748
|
-
const
|
6749
|
-
const
|
6750
|
-
const
|
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;
|
6751
6792
|
if (((_a = column4.autoincrement) == null ? void 0 : _a.type) === "added") {
|
6752
6793
|
statements.push({
|
6753
6794
|
type: "alter_table_alter_column_set_autoincrement",
|
@@ -6794,13 +6835,14 @@ var _prepareAlterColumns = (tableName, schema4, columns, json2) => {
|
|
6794
6835
|
}
|
6795
6836
|
for (const column4 of columns) {
|
6796
6837
|
const columnName = typeof column4.name !== "string" ? column4.name.new : column4.name;
|
6797
|
-
const
|
6798
|
-
const
|
6799
|
-
const
|
6800
|
-
const
|
6801
|
-
const
|
6802
|
-
const
|
6803
|
-
const
|
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}`];
|
6804
6846
|
if (typeof column4.name !== "string") {
|
6805
6847
|
statements.push({
|
6806
6848
|
type: "alter_table_rename_column",
|
@@ -7148,6 +7190,7 @@ var prepareAlterCompositePrimaryKeyMySql = (tableName, pks, json1, json2) => {
|
|
7148
7190
|
// src/snapshotsDiffer.ts
|
7149
7191
|
init_sqliteSchema();
|
7150
7192
|
init_mysqlSchema();
|
7193
|
+
init_global();
|
7151
7194
|
var makeChanged = (schema4) => {
|
7152
7195
|
return objectType({
|
7153
7196
|
type: enumType(["changed"]),
|
@@ -7186,7 +7229,7 @@ var makeSelfOrPatched = (schema4) => {
|
|
7186
7229
|
return unionType([
|
7187
7230
|
objectType({
|
7188
7231
|
type: literalType("none"),
|
7189
|
-
value: schema4
|
7232
|
+
value: schema4
|
7190
7233
|
}),
|
7191
7234
|
objectType({
|
7192
7235
|
type: literalType("added"),
|
@@ -7310,7 +7353,6 @@ var diffResultScheme = objectType({
|
|
7310
7353
|
}).strict();
|
7311
7354
|
var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesResolver, columnsResolver, prevFull, curFull) => {
|
7312
7355
|
var _a, _b;
|
7313
|
-
let diffResult;
|
7314
7356
|
if (dialect3 === "mysql") {
|
7315
7357
|
for (const tableName in json1.tables) {
|
7316
7358
|
const table4 = json1.tables[tableName];
|
@@ -7338,13 +7380,26 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
7338
7380
|
}
|
7339
7381
|
}
|
7340
7382
|
}
|
7341
|
-
diffResult = applyJsonDiff(json1, json2);
|
7342
7383
|
}
|
7343
|
-
diffResult = applyJsonDiff(json1, json2);
|
7384
|
+
const diffResult = applyJsonDiff(json1, json2);
|
7344
7385
|
if (Object.keys(diffResult).length === 0) {
|
7345
7386
|
return { statements: [], sqlStatements: [], _meta: void 0 };
|
7346
7387
|
}
|
7347
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
|
+
});
|
7348
7403
|
const {
|
7349
7404
|
created: createdSchemas,
|
7350
7405
|
deleted: deletedSchemas,
|
@@ -7496,7 +7551,7 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
7496
7551
|
prevFull,
|
7497
7552
|
curFull
|
7498
7553
|
);
|
7499
|
-
} else {
|
7554
|
+
} else if (dialect3 === "mysql") {
|
7500
7555
|
addedCompositePKs = prepareAddCompositePrimaryKeyMySql(
|
7501
7556
|
it.name,
|
7502
7557
|
it.addedCompositePKs,
|
@@ -7514,6 +7569,8 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
7514
7569
|
prevFull,
|
7515
7570
|
curFull
|
7516
7571
|
);
|
7572
|
+
} else {
|
7573
|
+
assertUnreachable(dialect3);
|
7517
7574
|
}
|
7518
7575
|
let addedUniqueConstraints = [];
|
7519
7576
|
let deletedUniqueConstraints = [];
|
@@ -7704,11 +7761,13 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
7704
7761
|
return preparePgCreateTableJson(it, curFull);
|
7705
7762
|
});
|
7706
7763
|
jsonStatements.push(...jsonPgCreateTables);
|
7707
|
-
} else {
|
7764
|
+
} else if (dialect3 === "mysql") {
|
7708
7765
|
const jsonMySqlCreateTables = created.map((it) => {
|
7709
7766
|
return prepareMySqlCreateTableJson(it, curFull);
|
7710
7767
|
});
|
7711
7768
|
jsonStatements.push(...jsonMySqlCreateTables);
|
7769
|
+
} else {
|
7770
|
+
assertUnreachable(dialect3);
|
7712
7771
|
}
|
7713
7772
|
jsonStatements.push(...jsonDropTables);
|
7714
7773
|
jsonStatements.push(...jsonRenameTables);
|
@@ -7867,7 +7926,7 @@ var resolveColumns = (missingColumns, newColumns, predicate) => {
|
|
7867
7926
|
};
|
7868
7927
|
|
7869
7928
|
// src/utils.ts
|
7870
|
-
var assertV1OutFolder = (out
|
7929
|
+
var assertV1OutFolder = (out) => {
|
7871
7930
|
if (!(0, import_fs.existsSync)(out))
|
7872
7931
|
return;
|
7873
7932
|
const oldMigrationFolders = (0, import_fs.readdirSync)(out).filter(
|
@@ -7876,7 +7935,7 @@ var assertV1OutFolder = (out, dialect3) => {
|
|
7876
7935
|
if (oldMigrationFolders.length > 0) {
|
7877
7936
|
console.log(
|
7878
7937
|
`Your migrations folder format is outdated, please run ${source_default.green.bold(
|
7879
|
-
`drizzle-kit up
|
7938
|
+
`drizzle-kit up`
|
7880
7939
|
)}`
|
7881
7940
|
);
|
7882
7941
|
process.exit(1);
|
@@ -7900,7 +7959,7 @@ var snapshotsPriorV4 = (out) => {
|
|
7900
7959
|
return pathJson;
|
7901
7960
|
});
|
7902
7961
|
};
|
7903
|
-
var
|
7962
|
+
var prepareOutFolder = (out, dialect3) => {
|
7904
7963
|
const meta = (0, import_path.join)(out, "meta");
|
7905
7964
|
const journalPath = (0, import_path.join)(meta, "_journal.json");
|
7906
7965
|
if (!(0, import_fs.existsSync)((0, import_path.join)(out, "meta"))) {
|
@@ -7915,9 +7974,9 @@ var prepareOutFolder2 = (out, dialect3) => {
|
|
7915
7974
|
var validatorForDialect = (dialect3) => {
|
7916
7975
|
switch (dialect3) {
|
7917
7976
|
case "pg":
|
7918
|
-
return { validator: backwardCompatiblePgSchema, version:
|
7977
|
+
return { validator: backwardCompatiblePgSchema, version: 6 };
|
7919
7978
|
case "sqlite":
|
7920
|
-
return { validator: backwardCompatibleSqliteSchema, version:
|
7979
|
+
return { validator: backwardCompatibleSqliteSchema, version: 6 };
|
7921
7980
|
case "mysql":
|
7922
7981
|
return { validator: backwardCompatibleMysqlSchema, version: 5 };
|
7923
7982
|
}
|
@@ -7965,13 +8024,13 @@ var validateWithReport = (snapshots, dialect3) => {
|
|
7965
8024
|
return result;
|
7966
8025
|
};
|
7967
8026
|
var prepareMigrationFolder = (outFolder = "drizzle", dialect3) => {
|
7968
|
-
const { snapshots, journal } =
|
8027
|
+
const { snapshots, journal } = prepareOutFolder(outFolder, dialect3);
|
7969
8028
|
const report = validateWithReport(snapshots, dialect3);
|
7970
8029
|
if (report.nonLatest.length > 0) {
|
7971
8030
|
console.log(
|
7972
8031
|
report.nonLatest.map((it) => {
|
7973
8032
|
return `${it}/snapshot.json is not of the latest version`;
|
7974
|
-
}).concat(`Run ${source_default.green.bold(`drizzle-kit up
|
8033
|
+
}).concat(`Run ${source_default.green.bold(`drizzle-kit up`)}`).join("\n")
|
7975
8034
|
);
|
7976
8035
|
process.exit(0);
|
7977
8036
|
}
|
@@ -8104,7 +8163,9 @@ var statementsForDiffs = async (in1, in2) => {
|
|
8104
8163
|
"pg",
|
8105
8164
|
schemasResolver,
|
8106
8165
|
tablesResolver,
|
8107
|
-
columnsResolver
|
8166
|
+
columnsResolver,
|
8167
|
+
left,
|
8168
|
+
right
|
8108
8169
|
);
|
8109
8170
|
return { ...result, left, right };
|
8110
8171
|
};
|