drizzle-kit 0.19.6-8f467f3 → 0.19.6-e96052c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +139 -70
- package/package.json +1 -1
- package/utils.js +13 -1
package/index.cjs
CHANGED
|
@@ -4551,7 +4551,7 @@ var init_global = __esm({
|
|
|
4551
4551
|
});
|
|
4552
4552
|
|
|
4553
4553
|
// src/serializer/mysqlSchema.ts
|
|
4554
|
-
var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternal, schemaV3, schemaV4, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlSchemeV4, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
4554
|
+
var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, dialect, schemaHash, schemaInternalV3, schemaInternalV4, kitInternals, schemaInternal, schemaV3, schemaV4, schema2, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, MySqlSquasher, squashMysqlSchemeV4, squashMysqlScheme, mysqlSchema, mysqlSchemaV4, mysqlSchemaV3, backwardCompatibleMysqlSchema, dryMySql;
|
|
4555
4555
|
var init_mysqlSchema = __esm({
|
|
4556
4556
|
"src/serializer/mysqlSchema.ts"() {
|
|
4557
4557
|
init_global();
|
|
@@ -4629,6 +4629,17 @@ var init_mysqlSchema = __esm({
|
|
|
4629
4629
|
tables: recordType(stringType(), tableV4),
|
|
4630
4630
|
schemas: recordType(stringType(), stringType())
|
|
4631
4631
|
}).strict();
|
|
4632
|
+
kitInternals = objectType({
|
|
4633
|
+
tables: recordType(
|
|
4634
|
+
stringType(),
|
|
4635
|
+
objectType({
|
|
4636
|
+
columns: recordType(
|
|
4637
|
+
stringType(),
|
|
4638
|
+
objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
|
|
4639
|
+
)
|
|
4640
|
+
}).optional()
|
|
4641
|
+
)
|
|
4642
|
+
}).optional();
|
|
4632
4643
|
schemaInternal = objectType({
|
|
4633
4644
|
version: literalType("5"),
|
|
4634
4645
|
dialect,
|
|
@@ -4638,7 +4649,8 @@ var init_mysqlSchema = __esm({
|
|
|
4638
4649
|
schemas: recordType(stringType(), stringType()),
|
|
4639
4650
|
tables: recordType(stringType(), stringType()),
|
|
4640
4651
|
columns: recordType(stringType(), stringType())
|
|
4641
|
-
})
|
|
4652
|
+
}),
|
|
4653
|
+
internal: kitInternals
|
|
4642
4654
|
}).strict();
|
|
4643
4655
|
schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
4644
4656
|
schemaV4 = schemaInternalV4.merge(schemaHash);
|
|
@@ -4767,9 +4779,12 @@ var init_mysqlSchema = __esm({
|
|
|
4767
4779
|
const squashedPKs = mapValues(it[1].compositePrimaryKeys, (pk) => {
|
|
4768
4780
|
return MySqlSquasher.squashPK(pk);
|
|
4769
4781
|
});
|
|
4770
|
-
const squashedUniqueConstraints = mapValues(
|
|
4771
|
-
|
|
4772
|
-
|
|
4782
|
+
const squashedUniqueConstraints = mapValues(
|
|
4783
|
+
it[1].uniqueConstraints,
|
|
4784
|
+
(unq) => {
|
|
4785
|
+
return MySqlSquasher.squashUnique(unq);
|
|
4786
|
+
}
|
|
4787
|
+
);
|
|
4773
4788
|
return [
|
|
4774
4789
|
it[0],
|
|
4775
4790
|
{
|
|
@@ -11467,12 +11482,12 @@ function clearDefaults(defaultValue, collate) {
|
|
|
11467
11482
|
if (defaultValue.startsWith(collate)) {
|
|
11468
11483
|
resultDefault = resultDefault.substring(collate.length, defaultValue.length).replace(/\\/g, "");
|
|
11469
11484
|
if (resultDefault.startsWith("'") && resultDefault.endsWith("'")) {
|
|
11470
|
-
return `
|
|
11485
|
+
return `'${resultDefault.substring(1, resultDefault.length - 1)}'`;
|
|
11471
11486
|
} else {
|
|
11472
|
-
return `
|
|
11487
|
+
return `'${resultDefault}'`;
|
|
11473
11488
|
}
|
|
11474
11489
|
} else {
|
|
11475
|
-
return
|
|
11490
|
+
return `${resultDefault}`;
|
|
11476
11491
|
}
|
|
11477
11492
|
}
|
|
11478
11493
|
var import_mysql_core2, import_drizzle_orm2, import_mysql_core3, import_drizzle_orm3, dialect3, indexName, generateMySqlSnapshot, fromDatabase;
|
|
@@ -11517,14 +11532,6 @@ var init_mysqlSerializer = __esm({
|
|
|
11517
11532
|
notNull,
|
|
11518
11533
|
autoincrement: typeof column7.autoIncrement === "undefined" ? false : column7.autoIncrement,
|
|
11519
11534
|
onUpdate: column7.hasOnUpdateNow
|
|
11520
|
-
// autoincrement:
|
|
11521
|
-
// column instanceof MySqlColumnWithAutoIncrement
|
|
11522
|
-
// ? column.autoIncrement
|
|
11523
|
-
// : false,
|
|
11524
|
-
// onUpdate:
|
|
11525
|
-
// column instanceof MySqlDateBaseColumn
|
|
11526
|
-
// ? column.hasOnUpdateNow
|
|
11527
|
-
// : undefined,
|
|
11528
11535
|
};
|
|
11529
11536
|
if (column7.isUnique) {
|
|
11530
11537
|
const existingUnique = uniqueConstraintObject[column7.uniqueName];
|
|
@@ -11647,6 +11654,43 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11647
11654
|
return it.name;
|
|
11648
11655
|
}
|
|
11649
11656
|
});
|
|
11657
|
+
if (value.config.unique) {
|
|
11658
|
+
if (typeof uniqueConstraintObject[name] !== "undefined") {
|
|
11659
|
+
console.log(
|
|
11660
|
+
`
|
|
11661
|
+
${withStyle.errorWarning(
|
|
11662
|
+
`We've found duplicated unique constraint names in ${source_default.underline.blue(
|
|
11663
|
+
tableName
|
|
11664
|
+
)} table.
|
|
11665
|
+
The unique index ${source_default.underline.blue(
|
|
11666
|
+
name
|
|
11667
|
+
)} on the ${source_default.underline.blue(
|
|
11668
|
+
indexColumns.join(",")
|
|
11669
|
+
)} columns is confilcting with a unique constraint name already defined for ${source_default.underline.blue(
|
|
11670
|
+
uniqueConstraintObject[name].columns.join(",")
|
|
11671
|
+
)} columns
|
|
11672
|
+
`
|
|
11673
|
+
)}`
|
|
11674
|
+
);
|
|
11675
|
+
process.exit(1);
|
|
11676
|
+
}
|
|
11677
|
+
} else {
|
|
11678
|
+
if (typeof foreignKeysObject[name] !== "undefined") {
|
|
11679
|
+
console.log(
|
|
11680
|
+
`
|
|
11681
|
+
${withStyle.errorWarning(`In MySQL, when creating a foreign key, an index is automatically generated with the same name as the foreign key constraint.
|
|
11682
|
+
|
|
11683
|
+
We have encountered a collision between the index name on columns ${source_default.underline.blue(
|
|
11684
|
+
indexColumns.join(",")
|
|
11685
|
+
)} and the foreign key on columns ${source_default.underline.blue(
|
|
11686
|
+
foreignKeysObject[name].columnsFrom.join(",")
|
|
11687
|
+
)}. Please change either the index name or the foreign key name. For more information, please refer to https://dev.mysql.com/doc/refman/8.0/en/constraint-foreign-key.html
|
|
11688
|
+
|
|
11689
|
+
`)}`
|
|
11690
|
+
);
|
|
11691
|
+
process.exit(1);
|
|
11692
|
+
}
|
|
11693
|
+
}
|
|
11650
11694
|
indexesObject[name] = {
|
|
11651
11695
|
name,
|
|
11652
11696
|
columns: indexColumns,
|
|
@@ -11683,6 +11727,7 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11683
11727
|
};
|
|
11684
11728
|
fromDatabase = async (db, inputSchema, tablesFilter = (table4) => true, progressCallback) => {
|
|
11685
11729
|
const result = {};
|
|
11730
|
+
const internals = { tables: {} };
|
|
11686
11731
|
const columns = await db.execute(`select * from information_schema.columns
|
|
11687
11732
|
where table_schema = '${inputSchema}' and table_name != '__drizzle_migrations'
|
|
11688
11733
|
order by table_name, ordinal_position;`);
|
|
@@ -11741,6 +11786,25 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11741
11786
|
notNull: !isNullable,
|
|
11742
11787
|
onUpdate
|
|
11743
11788
|
};
|
|
11789
|
+
if (isDefaultAnExpression) {
|
|
11790
|
+
if (typeof internals.tables[tableName] === "undefined") {
|
|
11791
|
+
internals.tables[tableName] = {
|
|
11792
|
+
columns: {
|
|
11793
|
+
[columnName]: {
|
|
11794
|
+
isDefaultAnExpression: true
|
|
11795
|
+
}
|
|
11796
|
+
}
|
|
11797
|
+
};
|
|
11798
|
+
} else {
|
|
11799
|
+
if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
|
|
11800
|
+
internals.tables[tableName].columns[columnName] = {
|
|
11801
|
+
isDefaultAnExpression: true
|
|
11802
|
+
};
|
|
11803
|
+
} else {
|
|
11804
|
+
internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
|
|
11805
|
+
}
|
|
11806
|
+
}
|
|
11807
|
+
}
|
|
11744
11808
|
if (!table4) {
|
|
11745
11809
|
result[tableName] = {
|
|
11746
11810
|
name: tableName,
|
|
@@ -11763,8 +11827,9 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11763
11827
|
LEFT JOIN information_schema.key_column_usage k
|
|
11764
11828
|
USING(constraint_name,table_schema,table_name)
|
|
11765
11829
|
WHERE t.constraint_type='PRIMARY KEY'
|
|
11766
|
-
|
|
11767
|
-
|
|
11830
|
+
and table_name != '__drizzle_migrations'
|
|
11831
|
+
AND t.table_schema = ?`,
|
|
11832
|
+
[inputSchema]
|
|
11768
11833
|
);
|
|
11769
11834
|
const tableToPk = {};
|
|
11770
11835
|
const tableToPkRows = tablePks[0];
|
|
@@ -11882,14 +11947,16 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11882
11947
|
};
|
|
11883
11948
|
}
|
|
11884
11949
|
} else {
|
|
11885
|
-
if (typeof tableInResult.
|
|
11886
|
-
tableInResult.indexes[constraintName]
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11950
|
+
if (typeof tableInResult.foreignKeys[constraintName] === "undefined") {
|
|
11951
|
+
if (typeof tableInResult.indexes[constraintName] !== "undefined") {
|
|
11952
|
+
tableInResult.indexes[constraintName].columns.push(columnName);
|
|
11953
|
+
} else {
|
|
11954
|
+
tableInResult.indexes[constraintName] = {
|
|
11955
|
+
name: constraintName,
|
|
11956
|
+
columns: [columnName],
|
|
11957
|
+
isUnique
|
|
11958
|
+
};
|
|
11959
|
+
}
|
|
11893
11960
|
}
|
|
11894
11961
|
}
|
|
11895
11962
|
}
|
|
@@ -11907,7 +11974,8 @@ The unique constraint ${source_default.underline.blue(
|
|
|
11907
11974
|
schemas: {},
|
|
11908
11975
|
tables: {},
|
|
11909
11976
|
columns: {}
|
|
11910
|
-
}
|
|
11977
|
+
},
|
|
11978
|
+
internal: internals
|
|
11911
11979
|
};
|
|
11912
11980
|
};
|
|
11913
11981
|
}
|
|
@@ -35776,8 +35844,8 @@ var init_mysql_introspect = __esm({
|
|
|
35776
35844
|
`;
|
|
35777
35845
|
}).join();
|
|
35778
35846
|
const tableStatements = Object.values(schema4.tables).map((table4) => {
|
|
35779
|
-
const
|
|
35780
|
-
const func =
|
|
35847
|
+
const tableSchema = schemas[table4.schema];
|
|
35848
|
+
const func = tableSchema ? tableSchema : "mysqlTable";
|
|
35781
35849
|
let statement = "";
|
|
35782
35850
|
if (imports.mysql.includes(withCasing(table4.name, casing))) {
|
|
35783
35851
|
statement = `// Table name is in conflict with ${withCasing(
|
|
@@ -35792,7 +35860,9 @@ var init_mysql_introspect = __esm({
|
|
|
35792
35860
|
statement += createTableColumns(
|
|
35793
35861
|
Object.values(table4.columns),
|
|
35794
35862
|
Object.values(table4.foreignKeys),
|
|
35795
|
-
casing
|
|
35863
|
+
casing,
|
|
35864
|
+
table4.name,
|
|
35865
|
+
schema4
|
|
35796
35866
|
);
|
|
35797
35867
|
statement += "}";
|
|
35798
35868
|
const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
|
|
@@ -35847,8 +35917,8 @@ import { sql } from "drizzle-orm"
|
|
|
35847
35917
|
isSelf = (fk4) => {
|
|
35848
35918
|
return fk4.tableFrom === fk4.tableTo;
|
|
35849
35919
|
};
|
|
35850
|
-
mapColumnDefault = (defaultValue) => {
|
|
35851
|
-
if (
|
|
35920
|
+
mapColumnDefault = (defaultValue, isExpression) => {
|
|
35921
|
+
if (isExpression) {
|
|
35852
35922
|
return `sql\`${defaultValue}\``;
|
|
35853
35923
|
}
|
|
35854
35924
|
return defaultValue;
|
|
@@ -35859,7 +35929,7 @@ import { sql } from "drizzle-orm"
|
|
|
35859
35929
|
}
|
|
35860
35930
|
return defaultValue;
|
|
35861
35931
|
};
|
|
35862
|
-
column4 = (type, name, defaultValue, autoincrement, onUpdate, casing) => {
|
|
35932
|
+
column4 = (type, name, defaultValue, autoincrement, onUpdate, casing, isExpression) => {
|
|
35863
35933
|
let lowered = type;
|
|
35864
35934
|
if (!type.startsWith("enum(")) {
|
|
35865
35935
|
lowered = type.toLowerCase();
|
|
@@ -35870,25 +35940,25 @@ import { sql } from "drizzle-orm"
|
|
|
35870
35940
|
if (lowered.startsWith("int")) {
|
|
35871
35941
|
let out = `${withCasing(name, casing)}: int("${name}")`;
|
|
35872
35942
|
out += autoincrement ? `.autoincrement()` : "";
|
|
35873
|
-
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35943
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35874
35944
|
return out;
|
|
35875
35945
|
}
|
|
35876
35946
|
if (lowered.startsWith("tinyint")) {
|
|
35877
35947
|
let out = `${withCasing(name, casing)}: tinyint("${name}")`;
|
|
35878
35948
|
out += autoincrement ? `.autoincrement()` : "";
|
|
35879
|
-
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35949
|
+
out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35880
35950
|
return out;
|
|
35881
35951
|
}
|
|
35882
35952
|
if (lowered.startsWith("smallint")) {
|
|
35883
35953
|
let out = `${withCasing(name, casing)}: smallint("${name}")`;
|
|
35884
35954
|
out += autoincrement ? `.autoincrement()` : "";
|
|
35885
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35955
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35886
35956
|
return out;
|
|
35887
35957
|
}
|
|
35888
35958
|
if (lowered.startsWith("mediumint")) {
|
|
35889
35959
|
let out = `${withCasing(name, casing)}: mediumint("${name}")`;
|
|
35890
35960
|
out += autoincrement ? `.autoincrement()` : "";
|
|
35891
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35961
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35892
35962
|
return out;
|
|
35893
35963
|
}
|
|
35894
35964
|
if (lowered.startsWith("bigint")) {
|
|
@@ -35897,12 +35967,12 @@ import { sql } from "drizzle-orm"
|
|
|
35897
35967
|
casing
|
|
35898
35968
|
)}: bigint("${name}", { mode: "number" })`;
|
|
35899
35969
|
out += autoincrement ? `.autoincrement()` : "";
|
|
35900
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35970
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35901
35971
|
return out;
|
|
35902
35972
|
}
|
|
35903
35973
|
if (lowered === "boolean") {
|
|
35904
35974
|
let out = `${withCasing(name, casing)}: boolean("${name}")`;
|
|
35905
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35975
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35906
35976
|
return out;
|
|
35907
35977
|
}
|
|
35908
35978
|
if (lowered.startsWith("double")) {
|
|
@@ -35912,17 +35982,17 @@ import { sql } from "drizzle-orm"
|
|
|
35912
35982
|
params = { precision, scale };
|
|
35913
35983
|
}
|
|
35914
35984
|
let out = params ? `${withCasing(name, casing)}: double("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: double("${name}")`;
|
|
35915
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35985
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35916
35986
|
return out;
|
|
35917
35987
|
}
|
|
35918
35988
|
if (lowered === "float") {
|
|
35919
35989
|
let out = `${withCasing(name, casing)}: float("${name}")`;
|
|
35920
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35990
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35921
35991
|
return out;
|
|
35922
35992
|
}
|
|
35923
35993
|
if (lowered === "real") {
|
|
35924
35994
|
let out = `${withCasing(name, casing)}: real("${name}")`;
|
|
35925
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
35995
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35926
35996
|
return out;
|
|
35927
35997
|
}
|
|
35928
35998
|
if (lowered.startsWith("timestamp")) {
|
|
@@ -35931,7 +36001,7 @@ import { sql } from "drizzle-orm"
|
|
|
35931
36001
|
fsp = fsp ? fsp : null;
|
|
35932
36002
|
const params = timeConfig({ fsp, mode: "'string'" });
|
|
35933
36003
|
let out = params ? `${withCasing(name, casing)}: timestamp("${name}", ${params})` : `${withCasing(name, casing)}: timestamp("${name}")`;
|
|
35934
|
-
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36004
|
+
defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35935
36005
|
out += defaultValue;
|
|
35936
36006
|
let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
|
|
35937
36007
|
out += onUpdateNow;
|
|
@@ -35943,7 +36013,7 @@ import { sql } from "drizzle-orm"
|
|
|
35943
36013
|
fsp = fsp ? fsp : null;
|
|
35944
36014
|
const params = timeConfig({ fsp });
|
|
35945
36015
|
let out = params ? `${withCasing(name, casing)}: time("${name}", ${params})` : `${withCasing(name, casing)}: time("${name}")`;
|
|
35946
|
-
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36016
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35947
36017
|
out += defaultValue;
|
|
35948
36018
|
return out;
|
|
35949
36019
|
}
|
|
@@ -35953,33 +36023,33 @@ import { sql } from "drizzle-orm"
|
|
|
35953
36023
|
name,
|
|
35954
36024
|
casing
|
|
35955
36025
|
)}: date("${name}", { mode: 'string' })`;
|
|
35956
|
-
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36026
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35957
36027
|
out += defaultValue;
|
|
35958
36028
|
return out;
|
|
35959
36029
|
}
|
|
35960
36030
|
if (lowered === "text") {
|
|
35961
36031
|
let out = `${withCasing(name, casing)}: text("${name}")`;
|
|
35962
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36032
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35963
36033
|
return out;
|
|
35964
36034
|
}
|
|
35965
36035
|
if (lowered === "tinytext") {
|
|
35966
36036
|
let out = `${withCasing(name, casing)}: tinytext("${name}")`;
|
|
35967
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36037
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35968
36038
|
return out;
|
|
35969
36039
|
}
|
|
35970
36040
|
if (lowered === "mediumtext") {
|
|
35971
36041
|
let out = `${withCasing(name, casing)}: mediumtext("${name}")`;
|
|
35972
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36042
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35973
36043
|
return out;
|
|
35974
36044
|
}
|
|
35975
36045
|
if (lowered === "longtext") {
|
|
35976
36046
|
let out = `${withCasing(name, casing)}: longtext("${name}")`;
|
|
35977
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36047
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35978
36048
|
return out;
|
|
35979
36049
|
}
|
|
35980
36050
|
if (lowered === "year") {
|
|
35981
36051
|
let out = `${withCasing(name, casing)}: year("${name}")`;
|
|
35982
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36052
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35983
36053
|
return out;
|
|
35984
36054
|
}
|
|
35985
36055
|
if (lowered === "json") {
|
|
@@ -35995,7 +36065,7 @@ import { sql } from "drizzle-orm"
|
|
|
35995
36065
|
"varchar".length + 1,
|
|
35996
36066
|
lowered.length - 1
|
|
35997
36067
|
)} })`;
|
|
35998
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36068
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
35999
36069
|
return out;
|
|
36000
36070
|
}
|
|
36001
36071
|
if (lowered.startsWith("char")) {
|
|
@@ -36006,7 +36076,7 @@ import { sql } from "drizzle-orm"
|
|
|
36006
36076
|
"char".length + 1,
|
|
36007
36077
|
lowered.length - 1
|
|
36008
36078
|
)} })`;
|
|
36009
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36079
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36010
36080
|
return out;
|
|
36011
36081
|
}
|
|
36012
36082
|
if (lowered.startsWith("datetime")) {
|
|
@@ -36020,7 +36090,7 @@ import { sql } from "drizzle-orm"
|
|
|
36020
36090
|
"datetime".length + 1,
|
|
36021
36091
|
lowered.length - 1
|
|
36022
36092
|
)} })` : `${withCasing(name, casing)}: datetime("${name}", { mode: 'string'})`;
|
|
36023
|
-
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36093
|
+
defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36024
36094
|
out += defaultValue;
|
|
36025
36095
|
return out;
|
|
36026
36096
|
}
|
|
@@ -36031,7 +36101,7 @@ import { sql } from "drizzle-orm"
|
|
|
36031
36101
|
params = { precision, scale };
|
|
36032
36102
|
}
|
|
36033
36103
|
let out = params ? `${withCasing(name, casing)}: decimal("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: decimal("${name}")`;
|
|
36034
|
-
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36104
|
+
defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36035
36105
|
out += defaultValue;
|
|
36036
36106
|
return out;
|
|
36037
36107
|
}
|
|
@@ -36041,14 +36111,14 @@ import { sql } from "drizzle-orm"
|
|
|
36041
36111
|
length = length ? length : null;
|
|
36042
36112
|
const params = binaryConfig({ length });
|
|
36043
36113
|
let out = params ? `${withCasing(name, casing)}: binary("${name}", ${params})` : `${withCasing(name, casing)}: binary("${name}")`;
|
|
36044
|
-
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36114
|
+
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36045
36115
|
out += defaultValue;
|
|
36046
36116
|
return out;
|
|
36047
36117
|
}
|
|
36048
36118
|
if (lowered.startsWith("enum")) {
|
|
36049
36119
|
const values = lowered.substring("enum".length + 1, lowered.length - 1);
|
|
36050
36120
|
let out = `${withCasing(name, casing)}: mysqlEnum("${name}", [${values}])`;
|
|
36051
|
-
out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36121
|
+
out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36052
36122
|
return out;
|
|
36053
36123
|
}
|
|
36054
36124
|
if (lowered.startsWith("varbinary")) {
|
|
@@ -36057,7 +36127,7 @@ import { sql } from "drizzle-orm"
|
|
|
36057
36127
|
length = length ? length : null;
|
|
36058
36128
|
const params = binaryConfig({ length });
|
|
36059
36129
|
let out = params ? `${withCasing(name, casing)}: varbinary("${name}", ${params})` : `${withCasing(name, casing)}: varbinary("${name}")`;
|
|
36060
|
-
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
|
|
36130
|
+
defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
|
|
36061
36131
|
out += defaultValue;
|
|
36062
36132
|
return out;
|
|
36063
36133
|
}
|
|
@@ -36065,7 +36135,7 @@ import { sql } from "drizzle-orm"
|
|
|
36065
36135
|
return `// Warning: Can't parse ${type} from database
|
|
36066
36136
|
// ${type}Type: ${type}("${name}")`;
|
|
36067
36137
|
};
|
|
36068
|
-
createTableColumns = (columns, fks, casing) => {
|
|
36138
|
+
createTableColumns = (columns, fks, casing, tableName, schema4) => {
|
|
36069
36139
|
let statement = "";
|
|
36070
36140
|
const oneColumnsFKs = Object.values(fks).filter((it) => {
|
|
36071
36141
|
return !isSelf(it);
|
|
@@ -36077,6 +36147,7 @@ import { sql } from "drizzle-orm"
|
|
|
36077
36147
|
return res;
|
|
36078
36148
|
}, {});
|
|
36079
36149
|
columns.forEach((it) => {
|
|
36150
|
+
var _a, _b, _c;
|
|
36080
36151
|
statement += " ";
|
|
36081
36152
|
statement += column4(
|
|
36082
36153
|
it.type,
|
|
@@ -36084,7 +36155,8 @@ import { sql } from "drizzle-orm"
|
|
|
36084
36155
|
it.default,
|
|
36085
36156
|
it.autoincrement,
|
|
36086
36157
|
it.onUpdate,
|
|
36087
|
-
casing
|
|
36158
|
+
casing,
|
|
36159
|
+
((_c = (_b = (_a = schema4.internal) == null ? void 0 : _a.tables[tableName]) == null ? void 0 : _b.columns[it.name]) == null ? void 0 : _c.isDefaultAnExpression) ?? false
|
|
36088
36160
|
);
|
|
36089
36161
|
statement += it.primaryKey ? ".primaryKey()" : "";
|
|
36090
36162
|
statement += it.notNull ? ".notNull()" : "";
|
|
@@ -37521,18 +37593,14 @@ var init_mysqlIntrospect = __esm({
|
|
|
37521
37593
|
const progress = new IntrospectProgress();
|
|
37522
37594
|
const res = await (0, import_hanji6.renderWithTask)(
|
|
37523
37595
|
progress,
|
|
37524
|
-
fromDatabase(
|
|
37525
|
-
|
|
37526
|
-
|
|
37527
|
-
filter2,
|
|
37528
|
-
(stage, count, status) => {
|
|
37529
|
-
progress.update(stage, count, status);
|
|
37530
|
-
}
|
|
37531
|
-
)
|
|
37596
|
+
fromDatabase(client, databaseName, filter2, (stage, count, status) => {
|
|
37597
|
+
progress.update(stage, count, status);
|
|
37598
|
+
})
|
|
37532
37599
|
);
|
|
37533
37600
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
37534
37601
|
const ts = schemaToTypeScript(schema4, config.introspect.casing);
|
|
37535
|
-
|
|
37602
|
+
const { internal, ...schemaWithoutInternals } = schema4;
|
|
37603
|
+
return { schema: schemaWithoutInternals, ts };
|
|
37536
37604
|
};
|
|
37537
37605
|
mysqlPushIntrospect = async (connection, filters) => {
|
|
37538
37606
|
const { client, databaseName } = connection;
|
|
@@ -37551,7 +37619,8 @@ var init_mysqlIntrospect = __esm({
|
|
|
37551
37619
|
};
|
|
37552
37620
|
const res = await fromDatabase(client, databaseName, filter2);
|
|
37553
37621
|
const schema4 = { id: originUUID, prevId: "", ...res };
|
|
37554
|
-
|
|
37622
|
+
const { internal, ...schemaWithoutInternals } = schema4;
|
|
37623
|
+
return { schema: schemaWithoutInternals };
|
|
37555
37624
|
};
|
|
37556
37625
|
}
|
|
37557
37626
|
});
|
|
@@ -52229,7 +52298,7 @@ var logSuggestionsAndReturn = async ({
|
|
|
52229
52298
|
shouldAskForApprove = true;
|
|
52230
52299
|
}
|
|
52231
52300
|
} else if (statement.type === "alter_table_add_column") {
|
|
52232
|
-
if (statement.column.notNull &&
|
|
52301
|
+
if (statement.column.notNull && typeof statement.column.default === "undefined") {
|
|
52233
52302
|
const res = await connection.query(
|
|
52234
52303
|
`select count(*) as count from \`${statement.tableName}\``
|
|
52235
52304
|
);
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -12795,6 +12795,17 @@ var schemaInternalV4 = objectType({
|
|
|
12795
12795
|
tables: recordType(stringType(), tableV4),
|
|
12796
12796
|
schemas: recordType(stringType(), stringType())
|
|
12797
12797
|
}).strict();
|
|
12798
|
+
var kitInternals = objectType({
|
|
12799
|
+
tables: recordType(
|
|
12800
|
+
stringType(),
|
|
12801
|
+
objectType({
|
|
12802
|
+
columns: recordType(
|
|
12803
|
+
stringType(),
|
|
12804
|
+
objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
|
|
12805
|
+
)
|
|
12806
|
+
}).optional()
|
|
12807
|
+
)
|
|
12808
|
+
}).optional();
|
|
12798
12809
|
var schemaInternal = objectType({
|
|
12799
12810
|
version: literalType("5"),
|
|
12800
12811
|
dialect,
|
|
@@ -12804,7 +12815,8 @@ var schemaInternal = objectType({
|
|
|
12804
12815
|
schemas: recordType(stringType(), stringType()),
|
|
12805
12816
|
tables: recordType(stringType(), stringType()),
|
|
12806
12817
|
columns: recordType(stringType(), stringType())
|
|
12807
|
-
})
|
|
12818
|
+
}),
|
|
12819
|
+
internal: kitInternals
|
|
12808
12820
|
}).strict();
|
|
12809
12821
|
var schemaV3 = schemaInternalV3.merge(schemaHash);
|
|
12810
12822
|
var schemaV4 = schemaInternalV4.merge(schemaHash);
|