drizzle-kit 0.19.6 → 0.19.7-d4fc71e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +119 -71
  2. package/package.json +1 -1
  3. 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(it[1].uniqueConstraints, (unq) => {
4771
- return MySqlSquasher.squashUnique(unq);
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 `('${resultDefault.substring(1, resultDefault.length - 1)}')`;
11485
+ return `'${resultDefault.substring(1, resultDefault.length - 1)}'`;
11471
11486
  } else {
11472
- return `('${resultDefault}')`;
11487
+ return `'${resultDefault}'`;
11473
11488
  }
11474
11489
  } else {
11475
- return `(${resultDefault})`;
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];
@@ -11667,6 +11674,22 @@ The unique index ${source_default.underline.blue(
11667
11674
  );
11668
11675
  process.exit(1);
11669
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
+ }
11670
11693
  }
11671
11694
  indexesObject[name] = {
11672
11695
  name,
@@ -11704,6 +11727,7 @@ The unique index ${source_default.underline.blue(
11704
11727
  };
11705
11728
  fromDatabase = async (db, inputSchema, tablesFilter = (table4) => true, progressCallback) => {
11706
11729
  const result = {};
11730
+ const internals = { tables: {} };
11707
11731
  const columns = await db.execute(`select * from information_schema.columns
11708
11732
  where table_schema = '${inputSchema}' and table_name != '__drizzle_migrations'
11709
11733
  order by table_name, ordinal_position;`);
@@ -11762,6 +11786,25 @@ The unique index ${source_default.underline.blue(
11762
11786
  notNull: !isNullable,
11763
11787
  onUpdate
11764
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
+ }
11765
11808
  if (!table4) {
11766
11809
  result[tableName] = {
11767
11810
  name: tableName,
@@ -11784,8 +11827,9 @@ The unique index ${source_default.underline.blue(
11784
11827
  LEFT JOIN information_schema.key_column_usage k
11785
11828
  USING(constraint_name,table_schema,table_name)
11786
11829
  WHERE t.constraint_type='PRIMARY KEY'
11787
- AND t.table_schema='${inputSchema}'`,
11788
- []
11830
+ and table_name != '__drizzle_migrations'
11831
+ AND t.table_schema = ?`,
11832
+ [inputSchema]
11789
11833
  );
11790
11834
  const tableToPk = {};
11791
11835
  const tableToPkRows = tablePks[0];
@@ -11903,14 +11947,16 @@ The unique index ${source_default.underline.blue(
11903
11947
  };
11904
11948
  }
11905
11949
  } else {
11906
- if (typeof tableInResult.indexes[constraintName] !== "undefined") {
11907
- tableInResult.indexes[constraintName].columns.push(columnName);
11908
- } else {
11909
- tableInResult.indexes[constraintName] = {
11910
- name: constraintName,
11911
- columns: [columnName],
11912
- isUnique
11913
- };
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
+ }
11914
11960
  }
11915
11961
  }
11916
11962
  }
@@ -11928,7 +11974,8 @@ The unique index ${source_default.underline.blue(
11928
11974
  schemas: {},
11929
11975
  tables: {},
11930
11976
  columns: {}
11931
- }
11977
+ },
11978
+ internal: internals
11932
11979
  };
11933
11980
  };
11934
11981
  }
@@ -35797,8 +35844,8 @@ var init_mysql_introspect = __esm({
35797
35844
  `;
35798
35845
  }).join();
35799
35846
  const tableStatements = Object.values(schema4.tables).map((table4) => {
35800
- const schema5 = schemas[table4.schema];
35801
- const func = schema5 ? schema5 : "mysqlTable";
35847
+ const tableSchema = schemas[table4.schema];
35848
+ const func = tableSchema ? tableSchema : "mysqlTable";
35802
35849
  let statement = "";
35803
35850
  if (imports.mysql.includes(withCasing(table4.name, casing))) {
35804
35851
  statement = `// Table name is in conflict with ${withCasing(
@@ -35813,7 +35860,9 @@ var init_mysql_introspect = __esm({
35813
35860
  statement += createTableColumns(
35814
35861
  Object.values(table4.columns),
35815
35862
  Object.values(table4.foreignKeys),
35816
- casing
35863
+ casing,
35864
+ table4.name,
35865
+ schema4
35817
35866
  );
35818
35867
  statement += "}";
35819
35868
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
@@ -35868,8 +35917,8 @@ import { sql } from "drizzle-orm"
35868
35917
  isSelf = (fk4) => {
35869
35918
  return fk4.tableFrom === fk4.tableTo;
35870
35919
  };
35871
- mapColumnDefault = (defaultValue) => {
35872
- if (typeof defaultValue === "string" && defaultValue.startsWith("(") && defaultValue.endsWith(")")) {
35920
+ mapColumnDefault = (defaultValue, isExpression) => {
35921
+ if (isExpression) {
35873
35922
  return `sql\`${defaultValue}\``;
35874
35923
  }
35875
35924
  return defaultValue;
@@ -35880,7 +35929,7 @@ import { sql } from "drizzle-orm"
35880
35929
  }
35881
35930
  return defaultValue;
35882
35931
  };
35883
- column4 = (type, name, defaultValue, autoincrement, onUpdate, casing) => {
35932
+ column4 = (type, name, defaultValue, autoincrement, onUpdate, casing, isExpression) => {
35884
35933
  let lowered = type;
35885
35934
  if (!type.startsWith("enum(")) {
35886
35935
  lowered = type.toLowerCase();
@@ -35891,25 +35940,25 @@ import { sql } from "drizzle-orm"
35891
35940
  if (lowered.startsWith("int")) {
35892
35941
  let out = `${withCasing(name, casing)}: int("${name}")`;
35893
35942
  out += autoincrement ? `.autoincrement()` : "";
35894
- out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
35943
+ out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35895
35944
  return out;
35896
35945
  }
35897
35946
  if (lowered.startsWith("tinyint")) {
35898
35947
  let out = `${withCasing(name, casing)}: tinyint("${name}")`;
35899
35948
  out += autoincrement ? `.autoincrement()` : "";
35900
- out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
35949
+ out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35901
35950
  return out;
35902
35951
  }
35903
35952
  if (lowered.startsWith("smallint")) {
35904
35953
  let out = `${withCasing(name, casing)}: smallint("${name}")`;
35905
35954
  out += autoincrement ? `.autoincrement()` : "";
35906
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35955
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35907
35956
  return out;
35908
35957
  }
35909
35958
  if (lowered.startsWith("mediumint")) {
35910
35959
  let out = `${withCasing(name, casing)}: mediumint("${name}")`;
35911
35960
  out += autoincrement ? `.autoincrement()` : "";
35912
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35961
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35913
35962
  return out;
35914
35963
  }
35915
35964
  if (lowered.startsWith("bigint")) {
@@ -35918,12 +35967,12 @@ import { sql } from "drizzle-orm"
35918
35967
  casing
35919
35968
  )}: bigint("${name}", { mode: "number" })`;
35920
35969
  out += autoincrement ? `.autoincrement()` : "";
35921
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35970
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35922
35971
  return out;
35923
35972
  }
35924
35973
  if (lowered === "boolean") {
35925
35974
  let out = `${withCasing(name, casing)}: boolean("${name}")`;
35926
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35975
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35927
35976
  return out;
35928
35977
  }
35929
35978
  if (lowered.startsWith("double")) {
@@ -35933,17 +35982,17 @@ import { sql } from "drizzle-orm"
35933
35982
  params = { precision, scale };
35934
35983
  }
35935
35984
  let out = params ? `${withCasing(name, casing)}: double("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: double("${name}")`;
35936
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35985
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35937
35986
  return out;
35938
35987
  }
35939
35988
  if (lowered === "float") {
35940
35989
  let out = `${withCasing(name, casing)}: float("${name}")`;
35941
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35990
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35942
35991
  return out;
35943
35992
  }
35944
35993
  if (lowered === "real") {
35945
35994
  let out = `${withCasing(name, casing)}: real("${name}")`;
35946
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
35995
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35947
35996
  return out;
35948
35997
  }
35949
35998
  if (lowered.startsWith("timestamp")) {
@@ -35952,7 +36001,7 @@ import { sql } from "drizzle-orm"
35952
36001
  fsp = fsp ? fsp : null;
35953
36002
  const params = timeConfig({ fsp, mode: "'string'" });
35954
36003
  let out = params ? `${withCasing(name, casing)}: timestamp("${name}", ${params})` : `${withCasing(name, casing)}: timestamp("${name}")`;
35955
- defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36004
+ defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35956
36005
  out += defaultValue;
35957
36006
  let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
35958
36007
  out += onUpdateNow;
@@ -35964,7 +36013,7 @@ import { sql } from "drizzle-orm"
35964
36013
  fsp = fsp ? fsp : null;
35965
36014
  const params = timeConfig({ fsp });
35966
36015
  let out = params ? `${withCasing(name, casing)}: time("${name}", ${params})` : `${withCasing(name, casing)}: time("${name}")`;
35967
- defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36016
+ defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35968
36017
  out += defaultValue;
35969
36018
  return out;
35970
36019
  }
@@ -35974,33 +36023,33 @@ import { sql } from "drizzle-orm"
35974
36023
  name,
35975
36024
  casing
35976
36025
  )}: date("${name}", { mode: 'string' })`;
35977
- defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36026
+ defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35978
36027
  out += defaultValue;
35979
36028
  return out;
35980
36029
  }
35981
36030
  if (lowered === "text") {
35982
36031
  let out = `${withCasing(name, casing)}: text("${name}")`;
35983
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36032
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35984
36033
  return out;
35985
36034
  }
35986
36035
  if (lowered === "tinytext") {
35987
36036
  let out = `${withCasing(name, casing)}: tinytext("${name}")`;
35988
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36037
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35989
36038
  return out;
35990
36039
  }
35991
36040
  if (lowered === "mediumtext") {
35992
36041
  let out = `${withCasing(name, casing)}: mediumtext("${name}")`;
35993
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36042
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35994
36043
  return out;
35995
36044
  }
35996
36045
  if (lowered === "longtext") {
35997
36046
  let out = `${withCasing(name, casing)}: longtext("${name}")`;
35998
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36047
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
35999
36048
  return out;
36000
36049
  }
36001
36050
  if (lowered === "year") {
36002
36051
  let out = `${withCasing(name, casing)}: year("${name}")`;
36003
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36052
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36004
36053
  return out;
36005
36054
  }
36006
36055
  if (lowered === "json") {
@@ -36016,7 +36065,7 @@ import { sql } from "drizzle-orm"
36016
36065
  "varchar".length + 1,
36017
36066
  lowered.length - 1
36018
36067
  )} })`;
36019
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36068
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36020
36069
  return out;
36021
36070
  }
36022
36071
  if (lowered.startsWith("char")) {
@@ -36027,7 +36076,7 @@ import { sql } from "drizzle-orm"
36027
36076
  "char".length + 1,
36028
36077
  lowered.length - 1
36029
36078
  )} })`;
36030
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36079
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36031
36080
  return out;
36032
36081
  }
36033
36082
  if (lowered.startsWith("datetime")) {
@@ -36041,7 +36090,7 @@ import { sql } from "drizzle-orm"
36041
36090
  "datetime".length + 1,
36042
36091
  lowered.length - 1
36043
36092
  )} })` : `${withCasing(name, casing)}: datetime("${name}", { mode: 'string'})`;
36044
- defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36093
+ defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36045
36094
  out += defaultValue;
36046
36095
  return out;
36047
36096
  }
@@ -36052,7 +36101,7 @@ import { sql } from "drizzle-orm"
36052
36101
  params = { precision, scale };
36053
36102
  }
36054
36103
  let out = params ? `${withCasing(name, casing)}: decimal("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: decimal("${name}")`;
36055
- defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
36104
+ defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36056
36105
  out += defaultValue;
36057
36106
  return out;
36058
36107
  }
@@ -36062,14 +36111,14 @@ import { sql } from "drizzle-orm"
36062
36111
  length = length ? length : null;
36063
36112
  const params = binaryConfig({ length });
36064
36113
  let out = params ? `${withCasing(name, casing)}: binary("${name}", ${params})` : `${withCasing(name, casing)}: binary("${name}")`;
36065
- defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36114
+ defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36066
36115
  out += defaultValue;
36067
36116
  return out;
36068
36117
  }
36069
36118
  if (lowered.startsWith("enum")) {
36070
36119
  const values = lowered.substring("enum".length + 1, lowered.length - 1);
36071
36120
  let out = `${withCasing(name, casing)}: mysqlEnum("${name}", [${values}])`;
36072
- out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36121
+ out += defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36073
36122
  return out;
36074
36123
  }
36075
36124
  if (lowered.startsWith("varbinary")) {
@@ -36078,7 +36127,7 @@ import { sql } from "drizzle-orm"
36078
36127
  length = length ? length : null;
36079
36128
  const params = binaryConfig({ length });
36080
36129
  let out = params ? `${withCasing(name, casing)}: varbinary("${name}", ${params})` : `${withCasing(name, casing)}: varbinary("${name}")`;
36081
- defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
36130
+ defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue, isExpression)})` : "";
36082
36131
  out += defaultValue;
36083
36132
  return out;
36084
36133
  }
@@ -36086,7 +36135,7 @@ import { sql } from "drizzle-orm"
36086
36135
  return `// Warning: Can't parse ${type} from database
36087
36136
  // ${type}Type: ${type}("${name}")`;
36088
36137
  };
36089
- createTableColumns = (columns, fks, casing) => {
36138
+ createTableColumns = (columns, fks, casing, tableName, schema4) => {
36090
36139
  let statement = "";
36091
36140
  const oneColumnsFKs = Object.values(fks).filter((it) => {
36092
36141
  return !isSelf(it);
@@ -36098,6 +36147,7 @@ import { sql } from "drizzle-orm"
36098
36147
  return res;
36099
36148
  }, {});
36100
36149
  columns.forEach((it) => {
36150
+ var _a, _b, _c;
36101
36151
  statement += " ";
36102
36152
  statement += column4(
36103
36153
  it.type,
@@ -36105,7 +36155,8 @@ import { sql } from "drizzle-orm"
36105
36155
  it.default,
36106
36156
  it.autoincrement,
36107
36157
  it.onUpdate,
36108
- 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
36109
36160
  );
36110
36161
  statement += it.primaryKey ? ".primaryKey()" : "";
36111
36162
  statement += it.notNull ? ".notNull()" : "";
@@ -37542,18 +37593,14 @@ var init_mysqlIntrospect = __esm({
37542
37593
  const progress = new IntrospectProgress();
37543
37594
  const res = await (0, import_hanji6.renderWithTask)(
37544
37595
  progress,
37545
- fromDatabase(
37546
- client,
37547
- databaseName,
37548
- filter2,
37549
- (stage, count, status) => {
37550
- progress.update(stage, count, status);
37551
- }
37552
- )
37596
+ fromDatabase(client, databaseName, filter2, (stage, count, status) => {
37597
+ progress.update(stage, count, status);
37598
+ })
37553
37599
  );
37554
37600
  const schema4 = { id: originUUID, prevId: "", ...res };
37555
37601
  const ts = schemaToTypeScript(schema4, config.introspect.casing);
37556
- return { schema: schema4, ts };
37602
+ const { internal, ...schemaWithoutInternals } = schema4;
37603
+ return { schema: schemaWithoutInternals, ts };
37557
37604
  };
37558
37605
  mysqlPushIntrospect = async (connection, filters) => {
37559
37606
  const { client, databaseName } = connection;
@@ -37572,7 +37619,8 @@ var init_mysqlIntrospect = __esm({
37572
37619
  };
37573
37620
  const res = await fromDatabase(client, databaseName, filter2);
37574
37621
  const schema4 = { id: originUUID, prevId: "", ...res };
37575
- return { schema: schema4 };
37622
+ const { internal, ...schemaWithoutInternals } = schema4;
37623
+ return { schema: schemaWithoutInternals };
37576
37624
  };
37577
37625
  }
37578
37626
  });
@@ -51923,7 +51971,7 @@ init_source();
51923
51971
  // package.json
51924
51972
  var package_default = {
51925
51973
  name: "drizzle-kit",
51926
- version: "0.19.6",
51974
+ version: "0.19.7",
51927
51975
  repository: "https://github.com/drizzle-team/drizzle-kit-mirror",
51928
51976
  author: "Drizzle Team",
51929
51977
  license: "MIT",
@@ -52250,7 +52298,7 @@ var logSuggestionsAndReturn = async ({
52250
52298
  shouldAskForApprove = true;
52251
52299
  }
52252
52300
  } else if (statement.type === "alter_table_add_column") {
52253
- if (statement.column.notNull && !statement.column.default) {
52301
+ if (statement.column.notNull && typeof statement.column.default === "undefined") {
52254
52302
  const res = await connection.query(
52255
52303
  `select count(*) as count from \`${statement.tableName}\``
52256
52304
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.19.6",
3
+ "version": "0.19.7-d4fc71e",
4
4
  "repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
5
5
  "author": "Drizzle Team",
6
6
  "license": "MIT",
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);