drizzle-kit 0.19.0-c1c76b7 → 0.19.0-e63c5cb

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 CHANGED
@@ -5620,7 +5620,7 @@ var init_mysqlSerializer = __esm({
5620
5620
  // : undefined,
5621
5621
  };
5622
5622
  if (column7.default !== void 0) {
5623
- if (column7.default instanceof import_drizzle_orm3.SQL) {
5623
+ if ((0, import_drizzle_orm2.is)(column7.default, import_drizzle_orm3.SQL)) {
5624
5624
  columnToSet.default = sqlToStr(column7.default);
5625
5625
  } else {
5626
5626
  if (typeof column7.default === "string") {
@@ -5682,7 +5682,7 @@ var init_mysqlSerializer = __esm({
5682
5682
  const columns2 = value.config.columns;
5683
5683
  const name = value.config.name;
5684
5684
  let indexColumns = columns2.map((it) => {
5685
- if (it instanceof import_drizzle_orm3.SQL) {
5685
+ if ((0, import_drizzle_orm2.is)(it, import_drizzle_orm3.SQL)) {
5686
5686
  return dialect3.sqlToQuery(it).sql;
5687
5687
  } else {
5688
5688
  return it.name;
@@ -6009,7 +6009,7 @@ var init_pgSerializer = __esm({
6009
6009
  notNull
6010
6010
  };
6011
6011
  if (column7.default !== void 0) {
6012
- if (column7.default instanceof import_drizzle_orm5.SQL) {
6012
+ if ((0, import_drizzle_orm5.is)(column7.default, import_drizzle_orm5.SQL)) {
6013
6013
  columnToSet.default = sqlToStr(column7.default);
6014
6014
  } else {
6015
6015
  if (typeof column7.default === "string") {
@@ -6072,7 +6072,7 @@ var init_pgSerializer = __esm({
6072
6072
  columns2.map((it) => it.name)
6073
6073
  );
6074
6074
  let indexColumns = columns2.map((it) => {
6075
- if (it instanceof import_drizzle_orm5.SQL) {
6075
+ if ((0, import_drizzle_orm5.is)(it, import_drizzle_orm5.SQL)) {
6076
6076
  return dialect4.sqlToQuery(it).sql;
6077
6077
  } else {
6078
6078
  return it.name;
@@ -6127,22 +6127,23 @@ var init_pgSerializer = __esm({
6127
6127
  --end;
6128
6128
  return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
6129
6129
  };
6130
- fromDatabase2 = async (db, progressCallback) => {
6130
+ fromDatabase2 = async (db, tablesFilter = (table4) => true, progressCallback) => {
6131
6131
  const result = {};
6132
6132
  const allTables = await db.query(
6133
6133
  `SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'public';`
6134
6134
  );
6135
6135
  const schemas = new Set(allTables.rows.map((it) => it.table_schema));
6136
6136
  schemas.delete("public");
6137
- if (progressCallback) {
6138
- progressCallback("tables", allTables.rows.length, "done");
6139
- }
6140
6137
  let columnsCount = 0;
6141
6138
  let indexesCount = 0;
6142
6139
  let foreignKeysCount = 0;
6140
+ let tableCount = 0;
6143
6141
  const all = allTables.rows.map((row) => {
6144
6142
  return new Promise(async (res, rej) => {
6145
6143
  const tableName = row.table_name;
6144
+ if (!tablesFilter(tableName))
6145
+ return res("");
6146
+ tableCount += 1;
6146
6147
  const tableSchema = row.table_schema;
6147
6148
  try {
6148
6149
  const columnToReturn = {};
@@ -6350,6 +6351,9 @@ var init_pgSerializer = __esm({
6350
6351
  res("");
6351
6352
  });
6352
6353
  });
6354
+ if (progressCallback) {
6355
+ progressCallback("tables", tableCount, "done");
6356
+ }
6353
6357
  for await (const _ of all) {
6354
6358
  }
6355
6359
  if (progressCallback) {
@@ -6553,10 +6557,10 @@ var init_sqliteSerializer = __esm({
6553
6557
  type: column7.getSQLType(),
6554
6558
  primaryKey,
6555
6559
  notNull,
6556
- autoincrement: column7 instanceof import_sqlite_core2.SQLiteBaseInteger ? column7.autoIncrement : false
6560
+ autoincrement: (0, import_drizzle_orm8.is)(column7, import_sqlite_core2.SQLiteBaseInteger) ? column7.autoIncrement : false
6557
6561
  };
6558
6562
  if (column7.default !== void 0) {
6559
- if (column7.default instanceof import_drizzle_orm9.SQL) {
6563
+ if ((0, import_drizzle_orm8.is)(column7.default, import_drizzle_orm9.SQL)) {
6560
6564
  columnToSet.default = sqlToStr(column7.default);
6561
6565
  } else {
6562
6566
  columnToSet.default = typeof column7.default === "string" ? `'${column7.default}'` : column7.default;
@@ -6591,7 +6595,7 @@ var init_sqliteSerializer = __esm({
6591
6595
  const columns2 = value.config.columns;
6592
6596
  const name = value.config.name;
6593
6597
  let indexColumns = columns2.map((it) => {
6594
- if (it instanceof import_drizzle_orm9.SQL) {
6598
+ if ((0, import_drizzle_orm8.is)(it, import_drizzle_orm9.SQL)) {
6595
6599
  return dialect5.sqlToQuery(it).sql;
6596
6600
  } else {
6597
6601
  return it.name;
@@ -6599,7 +6603,7 @@ var init_sqliteSerializer = __esm({
6599
6603
  });
6600
6604
  let where = void 0;
6601
6605
  if (value.config.where !== void 0) {
6602
- if (value.config.where instanceof import_drizzle_orm9.SQL) {
6606
+ if ((0, import_drizzle_orm8.is)(value.config.where, import_drizzle_orm9.SQL)) {
6603
6607
  where = dialect5.sqlToQuery(value.config.where).sql;
6604
6608
  }
6605
6609
  }
@@ -7821,7 +7825,7 @@ var init_words = __esm({
7821
7825
  "mesmero",
7822
7826
  "metal_master",
7823
7827
  "meteorite",
7824
- "micro/macro",
7828
+ "micromacro",
7825
7829
  "microbe",
7826
7830
  "microchip",
7827
7831
  "micromax",
@@ -8397,7 +8401,7 @@ var init_migrate = __esm({
8397
8401
  prepareSQLitePush = async (config, snapshot) => {
8398
8402
  const schemaPath = config.schema;
8399
8403
  try {
8400
- const { prev, cur } = prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
8404
+ const { prev, cur } = await prepareSQLiteDbPushSnapshot(snapshot, schemaPath);
8401
8405
  const validatedPrev = sqliteSchema.parse(prev);
8402
8406
  const validatedCur = sqliteSchema.parse(cur);
8403
8407
  const squashedPrev = squashSqliteScheme(validatedPrev);
@@ -8822,7 +8826,7 @@ var init_sqlgenerator = __esm({
8822
8826
  const primaryKeyStatement = column7.primaryKey ? "PRIMARY KEY" : "";
8823
8827
  const notNullStatement = column7.notNull ? "NOT NULL" : "";
8824
8828
  const defaultStatement = column7.default !== void 0 ? `DEFAULT ${column7.default}` : "";
8825
- const type = isPgNativeType(column7.type) ? column7.type : `${column7.type}`;
8829
+ const type = isPgNativeType(column7.type) ? column7.type : `"${column7.type}"`;
8826
8830
  statement += " " + `"${column7.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
8827
8831
  statement += (i === columns.length - 1 ? "" : ",") + "\n";
8828
8832
  }
@@ -8986,9 +8990,9 @@ var init_sqlgenerator = __esm({
8986
8990
  return statement.type === "rename_table" && dialect6 === "pg";
8987
8991
  }
8988
8992
  convert(statement) {
8989
- const { tableNameFrom, tableNameTo, toSchema: schema4 } = statement;
8990
- const from = schema4 ? `"${schema4}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
8991
- const to = schema4 ? `"${schema4}"."${tableNameTo}"` : `"${tableNameTo}"`;
8993
+ const { tableNameFrom, tableNameTo, toSchema, fromSchema } = statement;
8994
+ const from = fromSchema ? `"${fromSchema}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
8995
+ const to = `"${tableNameTo}"`;
8992
8996
  return `ALTER TABLE ${from} RENAME TO ${to};`;
8993
8997
  }
8994
8998
  };
@@ -10916,7 +10920,11 @@ var init_snapshotsDiffer = __esm({
10916
10920
  }).flat();
10917
10921
  const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
10918
10922
  const schema4 = valueFromSelfOrPatchedNew(it.schema);
10919
- const forAdded = dialect6 !== "sqlite" ? prepareCreateReferencesJson(it.name, schema4, it.addedForeignKeys) : [];
10923
+ const forAdded = prepareCreateReferencesJson(
10924
+ it.name,
10925
+ schema4,
10926
+ it.addedForeignKeys
10927
+ );
10920
10928
  const forAltered = prepareDropReferencesJson(
10921
10929
  it.name,
10922
10930
  schema4,
@@ -28744,7 +28752,7 @@ var require_promise = __commonJS({
28744
28752
  });
28745
28753
 
28746
28754
  // src/mysql-introspect.ts
28747
- var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
28755
+ var mysqlImportsList, objToStatement2, timeConfig, binaryConfig, importsPatch, relations, withCasing, schemaToTypeScript, isCyclic, isSelf, mapColumnDefault, mapColumnDefaultForJson, column4, createTableColumns, createTableIndexes, createTablePKs, createTableFKs;
28748
28756
  var init_mysql_introspect = __esm({
28749
28757
  "src/mysql-introspect.ts"() {
28750
28758
  init_utils2();
@@ -28814,7 +28822,16 @@ var init_mysql_introspect = __esm({
28814
28822
  "timestamp without time zone": "timestamp"
28815
28823
  };
28816
28824
  relations = /* @__PURE__ */ new Set();
28817
- schemaToTypeScript = (schema4) => {
28825
+ withCasing = (value, casing) => {
28826
+ if (typeof casing === "undefined") {
28827
+ return value;
28828
+ }
28829
+ if (casing === "camel") {
28830
+ return value.camelCase();
28831
+ }
28832
+ return value;
28833
+ };
28834
+ schemaToTypeScript = (schema4, casing) => {
28818
28835
  Object.values(schema4.tables).forEach((table4) => {
28819
28836
  Object.values(table4.foreignKeys).forEach((fk4) => {
28820
28837
  const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -28823,7 +28840,7 @@ var init_mysql_introspect = __esm({
28823
28840
  });
28824
28841
  const schemas = Object.fromEntries(
28825
28842
  Object.entries(schema4.schemas).map((it) => {
28826
- return [it[0], it[1].camelCase()];
28843
+ return [it[0], withCasing(it[1], casing)];
28827
28844
  })
28828
28845
  );
28829
28846
  const imports = Object.values(schema4.tables).reduce(
@@ -28865,16 +28882,20 @@ var init_mysql_introspect = __esm({
28865
28882
  const schema5 = schemas[table4.schema];
28866
28883
  const func = schema5 ? schema5 : "mysqlTable";
28867
28884
  let statement = "";
28868
- if (imports.mysql.includes(table4.name.camelCase())) {
28869
- statement = `// Table name is in conflict with ${table4.name.camelCase()} import.
28885
+ if (imports.mysql.includes(withCasing(table4.name, casing))) {
28886
+ statement = `// Table name is in conflict with ${withCasing(
28887
+ table4.name,
28888
+ casing
28889
+ )} import.
28870
28890
  // Please change to any other name, that is not in imports list
28871
28891
  `;
28872
28892
  }
28873
- statement += `export const ${table4.name.camelCase()} = ${func}("${table4.name}", {
28893
+ statement += `export const ${withCasing(table4.name, casing)} = ${func}("${table4.name}", {
28874
28894
  `;
28875
28895
  statement += createTableColumns(
28876
28896
  Object.values(table4.columns),
28877
- Object.values(table4.foreignKeys)
28897
+ Object.values(table4.foreignKeys),
28898
+ casing
28878
28899
  );
28879
28900
  statement += "}";
28880
28901
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
@@ -28884,9 +28905,16 @@ var init_mysql_introspect = __esm({
28884
28905
  statement += ",\n";
28885
28906
  statement += "(table) => {\n";
28886
28907
  statement += " return {\n";
28887
- statement += createTableIndexes(table4.name, Object.values(table4.indexes));
28888
- statement += createTableFKs(Object.values(filteredFKs));
28889
- statement += createTablePKs(Object.values(table4.compositePrimaryKeys));
28908
+ statement += createTableIndexes(
28909
+ table4.name,
28910
+ Object.values(table4.indexes),
28911
+ casing
28912
+ );
28913
+ statement += createTableFKs(Object.values(filteredFKs), casing);
28914
+ statement += createTablePKs(
28915
+ Object.values(table4.compositePrimaryKeys),
28916
+ casing
28917
+ );
28890
28918
  statement += " }\n";
28891
28919
  statement += "}";
28892
28920
  }
@@ -28930,46 +28958,49 @@ import { sql } from "drizzle-orm"
28930
28958
  }
28931
28959
  return defaultValue;
28932
28960
  };
28933
- column4 = (type, name, defaultValue, autoincrement, onUpdate) => {
28961
+ column4 = (type, name, defaultValue, autoincrement, onUpdate, casing) => {
28934
28962
  let lowered = type;
28935
28963
  if (!type.startsWith("enum(")) {
28936
28964
  lowered = type.toLowerCase();
28937
28965
  }
28938
28966
  if (lowered === "serial") {
28939
- return `${name.camelCase()}: serial("${name}")`;
28967
+ return `${withCasing(name, casing)}: serial("${name}")`;
28940
28968
  }
28941
28969
  if (lowered.startsWith("int")) {
28942
- let out = `${name.camelCase()}: int("${name}")`;
28970
+ let out = `${withCasing(name, casing)}: int("${name}")`;
28943
28971
  out += autoincrement ? `.autoincrement()` : "";
28944
28972
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
28945
28973
  return out;
28946
28974
  }
28947
28975
  if (lowered.startsWith("tinyint")) {
28948
- let out = `${name.camelCase()}: tinyint("${name}")`;
28976
+ let out = `${withCasing(name, casing)}: tinyint("${name}")`;
28949
28977
  out += autoincrement ? `.autoincrement()` : "";
28950
28978
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
28951
28979
  return out;
28952
28980
  }
28953
28981
  if (lowered.startsWith("smallint")) {
28954
- let out = `${name.camelCase()}: smallint("${name}")`;
28982
+ let out = `${withCasing(name, casing)}: smallint("${name}")`;
28955
28983
  out += autoincrement ? `.autoincrement()` : "";
28956
28984
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28957
28985
  return out;
28958
28986
  }
28959
28987
  if (lowered.startsWith("mediumint")) {
28960
- let out = `${name.camelCase()}: mediumint("${name}")`;
28988
+ let out = `${withCasing(name, casing)}: mediumint("${name}")`;
28961
28989
  out += autoincrement ? `.autoincrement()` : "";
28962
28990
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28963
28991
  return out;
28964
28992
  }
28965
28993
  if (lowered.startsWith("bigint")) {
28966
- let out = `${name.camelCase()}: bigint("${name}", { mode: "number" })`;
28994
+ let out = `${withCasing(
28995
+ name,
28996
+ casing
28997
+ )}: bigint("${name}", { mode: "number" })`;
28967
28998
  out += autoincrement ? `.autoincrement()` : "";
28968
28999
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28969
29000
  return out;
28970
29001
  }
28971
29002
  if (lowered === "boolean") {
28972
- let out = `${name.camelCase()}: boolean("${name}")`;
29003
+ let out = `${withCasing(name, casing)}: boolean("${name}")`;
28973
29004
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28974
29005
  return out;
28975
29006
  }
@@ -28979,17 +29010,17 @@ import { sql } from "drizzle-orm"
28979
29010
  const [precision, scale] = lowered.slice(7, lowered.length - 1).split(",");
28980
29011
  params = { precision, scale };
28981
29012
  }
28982
- let out = params ? `${name.camelCase()}: double("${name}", ${timeConfig(params)})` : `${name.camelCase()}: double("${name}")`;
29013
+ let out = params ? `${withCasing(name, casing)}: double("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: double("${name}")`;
28983
29014
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28984
29015
  return out;
28985
29016
  }
28986
29017
  if (lowered === "float") {
28987
- let out = `${name.camelCase()}: float("${name}")`;
29018
+ let out = `${withCasing(name, casing)}: float("${name}")`;
28988
29019
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28989
29020
  return out;
28990
29021
  }
28991
29022
  if (lowered === "real") {
28992
- let out = `${name.camelCase()}: real("${name}")`;
29023
+ let out = `${withCasing(name, casing)}: real("${name}")`;
28993
29024
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
28994
29025
  return out;
28995
29026
  }
@@ -28998,7 +29029,7 @@ import { sql } from "drizzle-orm"
28998
29029
  let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
28999
29030
  fsp = fsp ? fsp : null;
29000
29031
  const params = timeConfig({ fsp, mode: "'string'" });
29001
- let out = params ? `${name.camelCase()}: timestamp("${name}", ${params})` : `${name.camelCase()}: timestamp("${name}")`;
29032
+ let out = params ? `${withCasing(name, casing)}: timestamp("${name}", ${params})` : `${withCasing(name, casing)}: timestamp("${name}")`;
29002
29033
  defaultValue = defaultValue === "now()" || defaultValue === "(CURRENT_TIMESTAMP)" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29003
29034
  out += defaultValue;
29004
29035
  let onUpdateNow = onUpdate ? ".onUpdateNow()" : "";
@@ -29010,50 +29041,56 @@ import { sql } from "drizzle-orm"
29010
29041
  let fsp = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
29011
29042
  fsp = fsp ? fsp : null;
29012
29043
  const params = timeConfig({ fsp });
29013
- let out = params ? `${name.camelCase()}: time("${name}", ${params})` : `${name.camelCase()}: time("${name}")`;
29044
+ let out = params ? `${withCasing(name, casing)}: time("${name}", ${params})` : `${withCasing(name, casing)}: time("${name}")`;
29014
29045
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29015
29046
  out += defaultValue;
29016
29047
  return out;
29017
29048
  }
29018
29049
  if (lowered === "date") {
29019
29050
  let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
29020
- ${name.camelCase()}: date("${name}", { mode: 'string' })`;
29051
+ ${withCasing(
29052
+ name,
29053
+ casing
29054
+ )}: date("${name}", { mode: 'string' })`;
29021
29055
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29022
29056
  out += defaultValue;
29023
29057
  return out;
29024
29058
  }
29025
29059
  if (lowered === "text") {
29026
- let out = `${name.camelCase()}: text("${name}")`;
29060
+ let out = `${withCasing(name, casing)}: text("${name}")`;
29027
29061
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29028
29062
  return out;
29029
29063
  }
29030
29064
  if (lowered === "tinytext") {
29031
- let out = `${name.camelCase()}: tinytext("${name}")`;
29065
+ let out = `${withCasing(name, casing)}: tinytext("${name}")`;
29032
29066
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29033
29067
  return out;
29034
29068
  }
29035
29069
  if (lowered === "mediumtext") {
29036
- let out = `${name.camelCase()}: mediumtext("${name}")`;
29070
+ let out = `${withCasing(name, casing)}: mediumtext("${name}")`;
29037
29071
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29038
29072
  return out;
29039
29073
  }
29040
29074
  if (lowered === "longtext") {
29041
- let out = `${name.camelCase()}: longtext("${name}")`;
29075
+ let out = `${withCasing(name, casing)}: longtext("${name}")`;
29042
29076
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29043
29077
  return out;
29044
29078
  }
29045
29079
  if (lowered === "year") {
29046
- let out = `${name.camelCase()}: year("${name}")`;
29080
+ let out = `${withCasing(name, casing)}: year("${name}")`;
29047
29081
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29048
29082
  return out;
29049
29083
  }
29050
29084
  if (lowered === "json") {
29051
- let out = `${name.camelCase()}: json("${name}")`;
29085
+ let out = `${withCasing(name, casing)}: json("${name}")`;
29052
29086
  out += defaultValue ? `.default(${mapColumnDefaultForJson(defaultValue)})` : "";
29053
29087
  return out;
29054
29088
  }
29055
29089
  if (lowered.startsWith("varchar")) {
29056
- let out = `${name.camelCase()}: varchar("${name}", { length: ${lowered.substring(
29090
+ let out = `${withCasing(
29091
+ name,
29092
+ casing
29093
+ )}: varchar("${name}", { length: ${lowered.substring(
29057
29094
  "varchar".length + 1,
29058
29095
  lowered.length - 1
29059
29096
  )} })`;
@@ -29061,7 +29098,10 @@ import { sql } from "drizzle-orm"
29061
29098
  return out;
29062
29099
  }
29063
29100
  if (lowered.startsWith("char")) {
29064
- let out = `${name.camelCase()}: char("${name}", { length: ${lowered.substring(
29101
+ let out = `${withCasing(
29102
+ name,
29103
+ casing
29104
+ )}: char("${name}", { length: ${lowered.substring(
29065
29105
  "char".length + 1,
29066
29106
  lowered.length - 1
29067
29107
  )} })`;
@@ -29072,10 +29112,13 @@ import { sql } from "drizzle-orm"
29072
29112
  let out = `// you can use { mode: 'date' }, if you want to have Date as type for this column
29073
29113
  `;
29074
29114
  const fsp = lowered.startsWith("datetime(") ? lowered.substring("datetime".length + 1, lowered.length - 1) : void 0;
29075
- out = fsp ? `${name.camelCase()}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
29115
+ out = fsp ? `${withCasing(
29116
+ name,
29117
+ casing
29118
+ )}: datetime("${name}", { mode: 'string', fsp: ${lowered.substring(
29076
29119
  "datetime".length + 1,
29077
29120
  lowered.length - 1
29078
- )} })` : `${name.camelCase()}: datetime("${name}", { mode: 'string'})`;
29121
+ )} })` : `${withCasing(name, casing)}: datetime("${name}", { mode: 'string'})`;
29079
29122
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29080
29123
  out += defaultValue;
29081
29124
  return out;
@@ -29086,7 +29129,7 @@ import { sql } from "drizzle-orm"
29086
29129
  const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
29087
29130
  params = { precision, scale };
29088
29131
  }
29089
- let out = params ? `${name.camelCase()}: decimal("${name}", ${timeConfig(params)})` : `${name.camelCase()}: decimal("${name}")`;
29132
+ let out = params ? `${withCasing(name, casing)}: decimal("${name}", ${timeConfig(params)})` : `${withCasing(name, casing)}: decimal("${name}")`;
29090
29133
  defaultValue = typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault(defaultValue)})` : "";
29091
29134
  out += defaultValue;
29092
29135
  return out;
@@ -29096,14 +29139,14 @@ import { sql } from "drizzle-orm"
29096
29139
  let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
29097
29140
  length = length ? length : null;
29098
29141
  const params = binaryConfig({ length });
29099
- let out = params ? `${name.camelCase()}: binary("${name}", ${params})` : `${name.camelCase()}: binary("${name}")`;
29142
+ let out = params ? `${withCasing(name, casing)}: binary("${name}", ${params})` : `${withCasing(name, casing)}: binary("${name}")`;
29100
29143
  defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29101
29144
  out += defaultValue;
29102
29145
  return out;
29103
29146
  }
29104
29147
  if (lowered.startsWith("enum")) {
29105
29148
  const values = lowered.substring("enum".length + 1, lowered.length - 1);
29106
- let out = `${name.camelCase()}: mysqlEnum("${name}", [${values}])`;
29149
+ let out = `${withCasing(name, casing)}: mysqlEnum("${name}", [${values}])`;
29107
29150
  out += defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29108
29151
  return out;
29109
29152
  }
@@ -29112,7 +29155,7 @@ import { sql } from "drizzle-orm"
29112
29155
  let length = lowered.length > keyLength ? Number(lowered.substring(keyLength, lowered.length - 1)) : null;
29113
29156
  length = length ? length : null;
29114
29157
  const params = binaryConfig({ length });
29115
- let out = params ? `${name.camelCase()}: varbinary("${name}", ${params})` : `${name.camelCase()}: varbinary("${name}")`;
29158
+ let out = params ? `${withCasing(name, casing)}: varbinary("${name}", ${params})` : `${withCasing(name, casing)}: varbinary("${name}")`;
29116
29159
  defaultValue = defaultValue ? `.default(${mapColumnDefault(defaultValue)})` : "";
29117
29160
  out += defaultValue;
29118
29161
  return out;
@@ -29121,7 +29164,7 @@ import { sql } from "drizzle-orm"
29121
29164
  return `// Warning: Can't parse ${type} from database
29122
29165
  // ${type}Type: ${type}("${name}")`;
29123
29166
  };
29124
- createTableColumns = (columns, fks) => {
29167
+ createTableColumns = (columns, fks, casing) => {
29125
29168
  let statement = "";
29126
29169
  const oneColumnsFKs = Object.values(fks).filter((it) => {
29127
29170
  return !isSelf(it);
@@ -29139,7 +29182,8 @@ import { sql } from "drizzle-orm"
29139
29182
  it.name,
29140
29183
  it.default,
29141
29184
  it.autoincrement,
29142
- it.onUpdate
29185
+ it.onUpdate,
29186
+ casing
29143
29187
  );
29144
29188
  statement += it.primaryKey ? ".primaryKey()" : "";
29145
29189
  statement += it.notNull ? ".notNull()" : "";
@@ -29152,9 +29196,15 @@ import { sql } from "drizzle-orm"
29152
29196
  const typeSuffix = isCyclic(it2) ? ": AnyMySqlColumn" : "";
29153
29197
  const paramsStr = objToStatement2(params);
29154
29198
  if (paramsStr) {
29155
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()}, ${paramsStr} )`;
29156
- }
29157
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()})`;
29199
+ return `.references(()${typeSuffix} => ${withCasing(
29200
+ it2.tableTo,
29201
+ casing
29202
+ )}.${withCasing(it2.columnsTo[0], casing)}, ${paramsStr} )`;
29203
+ }
29204
+ return `.references(()${typeSuffix} => ${withCasing(
29205
+ it2.tableTo,
29206
+ casing
29207
+ )}.${withCasing(it2.columnsTo[0], casing)})`;
29158
29208
  }).join("");
29159
29209
  statement += fksStatement;
29160
29210
  }
@@ -29162,31 +29212,31 @@ import { sql } from "drizzle-orm"
29162
29212
  });
29163
29213
  return statement;
29164
29214
  };
29165
- createTableIndexes = (tableName, idxs) => {
29215
+ createTableIndexes = (tableName, idxs, casing) => {
29166
29216
  let statement = "";
29167
29217
  idxs.forEach((it) => {
29168
29218
  let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
29169
29219
  idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
29170
- idxKey = idxKey.camelCase();
29220
+ idxKey = withCasing(idxKey, casing);
29171
29221
  const indexGeneratedName = indexName(tableName, it.columns);
29172
29222
  const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
29173
29223
  statement += ` ${idxKey}: `;
29174
29224
  statement += it.isUnique ? "uniqueIndex(" : "index(";
29175
29225
  statement += `${escapedIndexName})`;
29176
- statement += `.on(${it.columns.map((it2) => `table.${it2.camelCase()}`).join(", ")}),`;
29226
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing(it2, casing)}`).join(", ")}),`;
29177
29227
  statement += `
29178
29228
  `;
29179
29229
  });
29180
29230
  return statement;
29181
29231
  };
29182
- createTablePKs = (pks) => {
29232
+ createTablePKs = (pks, casing) => {
29183
29233
  let statement = "";
29184
29234
  pks.forEach((it) => {
29185
- let idxKey = it.name.camelCase();
29235
+ let idxKey = withCasing(it.name, casing);
29186
29236
  statement += ` ${idxKey}: `;
29187
29237
  statement += "primaryKey(";
29188
29238
  statement += `${it.columns.map((c) => {
29189
- return `table.${c.camelCase()}`;
29239
+ return `table.${withCasing(c, casing)}`;
29190
29240
  }).join(", ")}`;
29191
29241
  statement += ")";
29192
29242
  statement += `
@@ -29194,16 +29244,16 @@ import { sql } from "drizzle-orm"
29194
29244
  });
29195
29245
  return statement;
29196
29246
  };
29197
- createTableFKs = (fks) => {
29247
+ createTableFKs = (fks, casing) => {
29198
29248
  let statement = "";
29199
29249
  fks.forEach((it) => {
29200
29250
  const isSelf4 = it.tableTo === it.tableFrom;
29201
- const tableTo = isSelf4 ? "table" : `${it.tableTo.camelCase()}`;
29202
- statement += ` ${it.name.camelCase()}: foreignKey({
29251
+ const tableTo = isSelf4 ? "table" : `${withCasing(it.tableTo, casing)}`;
29252
+ statement += ` ${withCasing(it.name, casing)}: foreignKey({
29203
29253
  `;
29204
- statement += ` columns: [${it.columnsFrom.map((i) => `table.${i.camelCase()}`).join(", ")}],
29254
+ statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing(i, casing)}`).join(", ")}],
29205
29255
  `;
29206
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i.camelCase()}`).join(", ")}]
29256
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing(i, casing)}`).join(", ")}]
29207
29257
  `;
29208
29258
  statement += ` })`;
29209
29259
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -30516,15 +30566,21 @@ var init_mysqlIntrospect = __esm({
30516
30566
  connectToMySQL = async (config) => {
30517
30567
  let client;
30518
30568
  let databaseName;
30519
- if ("connectionString" in config) {
30520
- const connection = config.connectionString;
30569
+ if (config.dbCredentials.type === "url") {
30570
+ const connection = config.dbCredentials.connectionString;
30521
30571
  client = await (0, import_promise.createConnection)(connection);
30522
30572
  const connectionUrl = new URL(connection);
30523
30573
  const pathname = connectionUrl.pathname;
30524
30574
  databaseName = pathname.split("/")[pathname.split("/").length - 1];
30525
- } else if ("host" in config) {
30526
- client = await (0, import_promise.createConnection)(config);
30527
- databaseName = config.database;
30575
+ if (!databaseName || databaseName === "") {
30576
+ throw Error(
30577
+ "You should specify a database name in connection string (mysql://USER:PASSWORD@HOST:PORT/DATABASE)"
30578
+ );
30579
+ }
30580
+ } else if (config.dbCredentials.type === "params") {
30581
+ const { type, ...creds } = config.dbCredentials;
30582
+ client = await (0, import_promise.createConnection)(creds);
30583
+ databaseName = creds.database;
30528
30584
  } else {
30529
30585
  throw Error(
30530
30586
  "Either `connectionString` or `host, port, etc.` params be provided in config file"
@@ -30533,22 +30589,35 @@ var init_mysqlIntrospect = __esm({
30533
30589
  await client.connect();
30534
30590
  return { client, databaseName };
30535
30591
  };
30536
- mysqlIntrospect = async (config) => {
30592
+ mysqlIntrospect = async (config, filters) => {
30537
30593
  const { client, databaseName } = await connectToMySQL(config);
30594
+ const matchers = filters.map((it) => {
30595
+ return new Minimatch(it);
30596
+ });
30597
+ const filter2 = (tableName) => {
30598
+ if (matchers.length === 0)
30599
+ return true;
30600
+ for (let i = 0; i < matchers.length; i++) {
30601
+ const matcher = matchers[i];
30602
+ if (matcher.match(tableName))
30603
+ return true;
30604
+ }
30605
+ return false;
30606
+ };
30538
30607
  const progress = new IntrospectProgress();
30539
30608
  const res = await (0, import_hanji5.renderWithTask)(
30540
30609
  progress,
30541
30610
  fromDatabase(
30542
30611
  client,
30543
30612
  databaseName,
30544
- (tableName) => true,
30613
+ filter2,
30545
30614
  (stage, count, status) => {
30546
30615
  progress.update(stage, count, status);
30547
30616
  }
30548
30617
  )
30549
30618
  );
30550
30619
  const schema4 = { id: originUUID, prevId: "", ...res };
30551
- const ts = schemaToTypeScript(schema4);
30620
+ const ts = schemaToTypeScript(schema4, config.introspect.casing);
30552
30621
  return { schema: schema4, ts };
30553
30622
  };
30554
30623
  mysqlPushIntrospect = async (connection, filters) => {
@@ -30574,7 +30643,7 @@ var init_mysqlIntrospect = __esm({
30574
30643
  });
30575
30644
 
30576
30645
  // src/sqlite-introspect.ts
30577
- var sqliteImportsList, indexName3, objToStatement22, relations2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
30646
+ var sqliteImportsList, indexName3, objToStatement22, relations2, withCasing2, schemaToTypeScript2, isCyclic2, isSelf2, mapColumnDefault2, column5, createTableColumns2, createTableIndexes2, createTablePKs2, createTableFKs2;
30578
30647
  var init_sqlite_introspect = __esm({
30579
30648
  "src/sqlite-introspect.ts"() {
30580
30649
  init_utils2();
@@ -30600,7 +30669,16 @@ var init_sqlite_introspect = __esm({
30600
30669
  return statement;
30601
30670
  };
30602
30671
  relations2 = /* @__PURE__ */ new Set();
30603
- schemaToTypeScript2 = (schema4) => {
30672
+ withCasing2 = (value, casing) => {
30673
+ if (typeof casing === "undefined") {
30674
+ return value;
30675
+ }
30676
+ if (casing === "camel") {
30677
+ return value.camelCase();
30678
+ }
30679
+ return value;
30680
+ };
30681
+ schemaToTypeScript2 = (schema4, casing) => {
30604
30682
  Object.values(schema4.tables).forEach((table4) => {
30605
30683
  Object.values(table4.foreignKeys).forEach((fk4) => {
30606
30684
  const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -30632,16 +30710,20 @@ var init_sqlite_introspect = __esm({
30632
30710
  const tableStatements = Object.values(schema4.tables).map((table4) => {
30633
30711
  const func = "sqliteTable";
30634
30712
  let statement = "";
30635
- if (imports.sqlite.includes(table4.name.camelCase())) {
30636
- statement = `// Table name is in conflict with ${table4.name.camelCase()} import.
30713
+ if (imports.sqlite.includes(withCasing2(table4.name, casing))) {
30714
+ statement = `// Table name is in conflict with ${withCasing2(
30715
+ table4.name,
30716
+ casing
30717
+ )} import.
30637
30718
  // Please change to any other name, that is not in imports list
30638
30719
  `;
30639
30720
  }
30640
- statement += `export const ${table4.name.camelCase()} = ${func}("${table4.name}", {
30721
+ statement += `export const ${withCasing2(table4.name, casing)} = ${func}("${table4.name}", {
30641
30722
  `;
30642
30723
  statement += createTableColumns2(
30643
30724
  Object.values(table4.columns),
30644
- Object.values(table4.foreignKeys)
30725
+ Object.values(table4.foreignKeys),
30726
+ casing
30645
30727
  );
30646
30728
  statement += "}";
30647
30729
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
@@ -30651,9 +30733,16 @@ var init_sqlite_introspect = __esm({
30651
30733
  statement += ",\n";
30652
30734
  statement += "(table) => {\n";
30653
30735
  statement += " return {\n";
30654
- statement += createTableIndexes2(table4.name, Object.values(table4.indexes));
30655
- statement += createTableFKs2(Object.values(filteredFKs));
30656
- statement += createTablePKs2(Object.values(table4.compositePrimaryKeys));
30736
+ statement += createTableIndexes2(
30737
+ table4.name,
30738
+ Object.values(table4.indexes),
30739
+ casing
30740
+ );
30741
+ statement += createTableFKs2(Object.values(filteredFKs), casing);
30742
+ statement += createTablePKs2(
30743
+ Object.values(table4.compositePrimaryKeys),
30744
+ casing
30745
+ );
30657
30746
  statement += " }\n";
30658
30747
  statement += "}";
30659
30748
  }
@@ -30689,37 +30778,37 @@ import { sql } from "drizzle-orm"
30689
30778
  }
30690
30779
  return defaultValue;
30691
30780
  };
30692
- column5 = (type, name, defaultValue, autoincrement, onUpdate) => {
30781
+ column5 = (type, name, defaultValue, autoincrement, casing) => {
30693
30782
  let lowered = type;
30694
30783
  if (lowered.startsWith("integer")) {
30695
- let out = `${name.camelCase()}: integer("${name}")`;
30784
+ let out = `${withCasing2(name, casing)}: integer("${name}")`;
30696
30785
  out += typeof defaultValue !== "undefined" ? `.default(${mapColumnDefault2(defaultValue)})` : "";
30697
30786
  return out;
30698
30787
  }
30699
30788
  if (lowered === "real") {
30700
- let out = `${name.camelCase()}: real("${name}")`;
30789
+ let out = `${withCasing2(name, casing)}: real("${name}")`;
30701
30790
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
30702
30791
  return out;
30703
30792
  }
30704
30793
  if (lowered === "text") {
30705
- let out = `${name.camelCase()}: text("${name}")`;
30794
+ let out = `${withCasing2(name, casing)}: text("${name}")`;
30706
30795
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
30707
30796
  return out;
30708
30797
  }
30709
30798
  if (lowered === "blob") {
30710
- let out = `${name.camelCase()}: blob("${name}")`;
30799
+ let out = `${withCasing2(name, casing)}: blob("${name}")`;
30711
30800
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
30712
30801
  return out;
30713
30802
  }
30714
30803
  if (lowered === "numeric") {
30715
- let out = `${name.camelCase()}: numeric("${name}")`;
30804
+ let out = `${withCasing2(name, casing)}: numeric("${name}")`;
30716
30805
  out += defaultValue ? `.default(${mapColumnDefault2(defaultValue)})` : "";
30717
30806
  return out;
30718
30807
  }
30719
30808
  return `// Warning: Can't parse ${type} from database
30720
30809
  // ${type}Type: ${type}("${name}")`;
30721
30810
  };
30722
- createTableColumns2 = (columns, fks) => {
30811
+ createTableColumns2 = (columns, fks, casing) => {
30723
30812
  let statement = "";
30724
30813
  const oneColumnsFKs = Object.values(fks).filter((it) => {
30725
30814
  return !isSelf2(it);
@@ -30732,7 +30821,7 @@ import { sql } from "drizzle-orm"
30732
30821
  }, {});
30733
30822
  columns.forEach((it) => {
30734
30823
  statement += " ";
30735
- statement += column5(it.type, it.name, it.default, it.autoincrement);
30824
+ statement += column5(it.type, it.name, it.default, it.autoincrement, casing);
30736
30825
  statement += it.primaryKey ? `.primaryKey(${it.autoincrement ? "{ autoIncrement: true }" : ""})` : "";
30737
30826
  statement += it.notNull ? ".notNull()" : "";
30738
30827
  const fks2 = fkByColumnName[it.name];
@@ -30744,9 +30833,15 @@ import { sql } from "drizzle-orm"
30744
30833
  const typeSuffix = isCyclic2(it2) ? ": AnySQLiteColumn" : "";
30745
30834
  const paramsStr = objToStatement22(params);
30746
30835
  if (paramsStr) {
30747
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()}, ${paramsStr} )`;
30748
- }
30749
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()})`;
30836
+ return `.references(()${typeSuffix} => ${withCasing2(
30837
+ it2.tableTo,
30838
+ casing
30839
+ )}.${withCasing2(it2.columnsTo[0], casing)}, ${paramsStr} )`;
30840
+ }
30841
+ return `.references(()${typeSuffix} => ${withCasing2(
30842
+ it2.tableTo,
30843
+ casing
30844
+ )}.${withCasing2(it2.columnsTo[0], casing)})`;
30750
30845
  }).join("");
30751
30846
  statement += fksStatement;
30752
30847
  }
@@ -30754,30 +30849,30 @@ import { sql } from "drizzle-orm"
30754
30849
  });
30755
30850
  return statement;
30756
30851
  };
30757
- createTableIndexes2 = (tableName, idxs) => {
30852
+ createTableIndexes2 = (tableName, idxs, casing) => {
30758
30853
  let statement = "";
30759
30854
  idxs.forEach((it) => {
30760
30855
  let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
30761
30856
  idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
30762
- idxKey = idxKey.camelCase();
30857
+ idxKey = withCasing2(idxKey, casing);
30763
30858
  const indexGeneratedName = indexName3(tableName, it.columns);
30764
30859
  const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
30765
30860
  statement += ` ${idxKey}: `;
30766
30861
  statement += it.isUnique ? "uniqueIndex(" : "index(";
30767
30862
  statement += `${escapedIndexName})`;
30768
- statement += `.on(${it.columns.map((it2) => `table.${it2.camelCase()}`).join(", ")}),`;
30863
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing)}`).join(", ")}),`;
30769
30864
  statement += `
30770
30865
  `;
30771
30866
  });
30772
30867
  return statement;
30773
30868
  };
30774
- createTablePKs2 = (pks) => {
30869
+ createTablePKs2 = (pks, casing) => {
30775
30870
  let statement = "";
30776
30871
  pks.forEach((it, i) => {
30777
30872
  statement += ` pk${i}: `;
30778
30873
  statement += "primaryKey(";
30779
30874
  statement += `${it.columns.map((c) => {
30780
- return `table.${c.camelCase()}`;
30875
+ return `table.${withCasing2(c, casing)}`;
30781
30876
  }).join(", ")}`;
30782
30877
  statement += ")";
30783
30878
  statement += `
@@ -30785,16 +30880,16 @@ import { sql } from "drizzle-orm"
30785
30880
  });
30786
30881
  return statement;
30787
30882
  };
30788
- createTableFKs2 = (fks) => {
30883
+ createTableFKs2 = (fks, casing) => {
30789
30884
  let statement = "";
30790
30885
  fks.forEach((it) => {
30791
30886
  const isSelf4 = it.tableTo === it.tableFrom;
30792
- const tableTo = isSelf4 ? "table" : `${it.tableTo.camelCase()}`;
30793
- statement += ` ${it.name.camelCase()}: foreignKey(() => ({
30887
+ const tableTo = isSelf4 ? "table" : `${withCasing2(it.tableTo, casing)}`;
30888
+ statement += ` ${withCasing2(it.name, casing)}: foreignKey(() => ({
30794
30889
  `;
30795
- statement += ` columns: [${it.columnsFrom.map((i) => `table.${i.camelCase()}`).join(", ")}],
30890
+ statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing2(i, casing)}`).join(", ")}],
30796
30891
  `;
30797
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i.camelCase()}`).join(", ")}]
30892
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing2(i, casing)}`).join(", ")}]
30798
30893
  `;
30799
30894
  statement += ` }))`;
30800
30895
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -39411,21 +39506,34 @@ var init_sqliteIntrospect = __esm({
39411
39506
  }
39412
39507
  return {};
39413
39508
  };
39414
- sqliteIntrospect = async (config) => {
39509
+ sqliteIntrospect = async (config, filters) => {
39415
39510
  const { client } = await connectToSQLite(config);
39511
+ const matchers = filters.map((it) => {
39512
+ return new Minimatch(it);
39513
+ });
39514
+ const filter2 = (tableName) => {
39515
+ if (matchers.length === 0)
39516
+ return true;
39517
+ for (let i = 0; i < matchers.length; i++) {
39518
+ const matcher = matchers[i];
39519
+ if (matcher.match(tableName))
39520
+ return true;
39521
+ }
39522
+ return false;
39523
+ };
39416
39524
  const progress = new IntrospectProgress();
39417
39525
  const res = await (0, import_hanji6.renderWithTask)(
39418
39526
  progress,
39419
39527
  fromDatabase3(
39420
39528
  client,
39421
- () => true,
39529
+ filter2,
39422
39530
  (stage, count, status) => {
39423
39531
  progress.update(stage, count, status);
39424
39532
  }
39425
39533
  )
39426
39534
  );
39427
39535
  const schema4 = { id: originUUID, prevId: "", ...res };
39428
- const ts = schemaToTypeScript2(schema4);
39536
+ const ts = schemaToTypeScript2(schema4, config.introspect.casing);
39429
39537
  return { schema: schema4, ts };
39430
39538
  };
39431
39539
  sqlitePushIntrospect = async (client, filters) => {
@@ -41088,50 +41196,47 @@ var require_type_overrides = __commonJS({
41088
41196
  }
41089
41197
  });
41090
41198
 
41091
- // node_modules/.pnpm/pg-connection-string@2.5.0/node_modules/pg-connection-string/index.js
41199
+ // node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js
41092
41200
  var require_pg_connection_string = __commonJS({
41093
- "node_modules/.pnpm/pg-connection-string@2.5.0/node_modules/pg-connection-string/index.js"(exports, module2) {
41201
+ "node_modules/.pnpm/pg-connection-string@2.6.0/node_modules/pg-connection-string/index.js"(exports, module2) {
41094
41202
  "use strict";
41095
- var url = require("url");
41096
- var fs6 = require("fs");
41097
41203
  function parse(str) {
41098
41204
  if (str.charAt(0) === "/") {
41099
- var config = str.split(" ");
41100
- return { host: config[0], database: config[1] };
41205
+ const config2 = str.split(" ");
41206
+ return { host: config2[0], database: config2[1] };
41101
41207
  }
41102
- var result = url.parse(
41103
- / |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str) ? encodeURI(str).replace(/\%25(\d\d)/g, "%$1") : str,
41104
- true
41105
- );
41106
- var config = result.query;
41107
- for (var k in config) {
41108
- if (Array.isArray(config[k])) {
41109
- config[k] = config[k][config[k].length - 1];
41110
- }
41208
+ const config = {};
41209
+ let result;
41210
+ let dummyHost = false;
41211
+ if (/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str)) {
41212
+ str = encodeURI(str).replace(/\%25(\d\d)/g, "%$1");
41213
+ }
41214
+ try {
41215
+ result = new URL(str, "postgres://base");
41216
+ } catch (e) {
41217
+ result = new URL(str.replace("@/", "@___DUMMY___/"), "postgres://base");
41218
+ dummyHost = true;
41111
41219
  }
41112
- var auth = (result.auth || ":").split(":");
41113
- config.user = auth[0];
41114
- config.password = auth.splice(1).join(":");
41220
+ for (const entry of result.searchParams.entries()) {
41221
+ config[entry[0]] = entry[1];
41222
+ }
41223
+ config.user = config.user || decodeURIComponent(result.username);
41224
+ config.password = config.password || decodeURIComponent(result.password);
41115
41225
  config.port = result.port;
41116
41226
  if (result.protocol == "socket:") {
41117
41227
  config.host = decodeURI(result.pathname);
41118
- config.database = result.query.db;
41119
- config.client_encoding = result.query.encoding;
41228
+ config.database = result.searchParams.get("db");
41229
+ config.client_encoding = result.searchParams.get("encoding");
41120
41230
  return config;
41121
41231
  }
41232
+ const hostname = dummyHost ? "" : result.hostname;
41122
41233
  if (!config.host) {
41123
- config.host = result.hostname;
41124
- }
41125
- var pathname = result.pathname;
41126
- if (!config.host && pathname && /^%2f/i.test(pathname)) {
41127
- var pathnameSplit = pathname.split("/");
41128
- config.host = decodeURIComponent(pathnameSplit[0]);
41129
- pathname = pathnameSplit.splice(1).join("/");
41130
- }
41131
- if (pathname && pathname.charAt(0) === "/") {
41132
- pathname = pathname.slice(1) || null;
41234
+ config.host = decodeURIComponent(hostname);
41235
+ } else if (hostname) {
41236
+ result.pathname = hostname + result.pathname;
41133
41237
  }
41134
- config.database = pathname && decodeURI(pathname);
41238
+ const pathname = result.pathname.slice(1) || null;
41239
+ config.database = pathname ? decodeURI(pathname) : null;
41135
41240
  if (config.ssl === "true" || config.ssl === "1") {
41136
41241
  config.ssl = true;
41137
41242
  }
@@ -41141,6 +41246,7 @@ var require_pg_connection_string = __commonJS({
41141
41246
  if (config.sslcert || config.sslkey || config.sslrootcert || config.sslmode) {
41142
41247
  config.ssl = {};
41143
41248
  }
41249
+ const fs6 = config.sslcert || config.sslkey || config.sslrootcert ? require("fs") : null;
41144
41250
  if (config.sslcert) {
41145
41251
  config.ssl.cert = fs6.readFileSync(config.sslcert).toString();
41146
41252
  }
@@ -43990,7 +44096,7 @@ var require_lib5 = __commonJS({
43990
44096
  });
43991
44097
 
43992
44098
  // src/introspect.ts
43993
- var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
44099
+ var pgImportsList, objToStatement23, timeConfig2, possibleIntervals, intervalStrToObj, intervalConfig, importsPatch2, relations3, withCasing3, schemaToTypeScript3, isCyclic3, isSelf3, column6, dimensionsInArray, createTableColumns3, createTableIndexes3, createTablePKs3, createTableFKs3;
43994
44100
  var init_introspect = __esm({
43995
44101
  "src/introspect.ts"() {
43996
44102
  init_utils2();
@@ -44102,7 +44208,16 @@ var init_introspect = __esm({
44102
44208
  "time with time zone": "time"
44103
44209
  };
44104
44210
  relations3 = /* @__PURE__ */ new Set();
44105
- schemaToTypeScript3 = (schema4) => {
44211
+ withCasing3 = (value, casing) => {
44212
+ if (typeof casing === "undefined") {
44213
+ return value;
44214
+ }
44215
+ if (casing.casing === "camel") {
44216
+ return value.camelCase();
44217
+ }
44218
+ return value;
44219
+ };
44220
+ schemaToTypeScript3 = (schema4, casing) => {
44106
44221
  Object.values(schema4.tables).forEach((table4) => {
44107
44222
  Object.values(table4.foreignKeys).forEach((fk4) => {
44108
44223
  const relation = `${fk4.tableFrom}-${fk4.tableTo}`;
@@ -44111,7 +44226,7 @@ var init_introspect = __esm({
44111
44226
  });
44112
44227
  const schemas = Object.fromEntries(
44113
44228
  Object.entries(schema4.schemas).map((it) => {
44114
- return [it[0], it[1].camelCase()];
44229
+ return [it[0], withCasing3(it[1], casing)];
44115
44230
  })
44116
44231
  );
44117
44232
  const enumTypes = new Set(Object.values(schema4.enums).map((it) => it.name));
@@ -44145,7 +44260,7 @@ var init_introspect = __esm({
44145
44260
  );
44146
44261
  const enumStatements = Object.values(schema4.enums).map((it) => {
44147
44262
  const values = Object.values(it.values).map((it2) => `'${it2}'`).join(", ");
44148
- return `export const ${it.name.camelCase()} = pgEnum("${it.name}", [${values}])
44263
+ return `export const ${withCasing3(it.name, casing)} = pgEnum("${it.name}", [${values}])
44149
44264
  `;
44150
44265
  }).join("").concat("\n");
44151
44266
  const schemaStatements = Object.entries(schemas).map((it) => {
@@ -44155,12 +44270,16 @@ var init_introspect = __esm({
44155
44270
  const tableStatements = Object.values(schema4.tables).map((table4) => {
44156
44271
  const schema5 = schemas[table4.schema];
44157
44272
  const func = schema5 ? schema5 : "pgTable";
44158
- let statement = `export const ${table4.name.camelCase()} = ${func}("${table4.name}", {
44273
+ let statement = `export const ${withCasing3(
44274
+ table4.name,
44275
+ casing
44276
+ )} = ${func}("${table4.name}", {
44159
44277
  `;
44160
44278
  statement += createTableColumns3(
44161
44279
  Object.values(table4.columns),
44162
44280
  Object.values(table4.foreignKeys),
44163
- enumTypes
44281
+ enumTypes,
44282
+ casing
44164
44283
  );
44165
44284
  statement += "}";
44166
44285
  const filteredFKs = Object.values(table4.foreignKeys).filter((it) => {
@@ -44170,9 +44289,16 @@ var init_introspect = __esm({
44170
44289
  statement += ",\n";
44171
44290
  statement += "(table) => {\n";
44172
44291
  statement += " return {\n";
44173
- statement += createTableIndexes3(table4.name, Object.values(table4.indexes));
44174
- statement += createTableFKs3(Object.values(filteredFKs));
44175
- statement += createTablePKs3(Object.values(table4.compositePrimaryKeys));
44292
+ statement += createTableIndexes3(
44293
+ table4.name,
44294
+ Object.values(table4.indexes),
44295
+ casing
44296
+ );
44297
+ statement += createTableFKs3(Object.values(filteredFKs), casing);
44298
+ statement += createTablePKs3(
44299
+ Object.values(table4.compositePrimaryKeys),
44300
+ casing
44301
+ );
44176
44302
  statement += " }\n";
44177
44303
  statement += "}";
44178
44304
  }
@@ -44207,51 +44333,54 @@ var init_introspect = __esm({
44207
44333
  isSelf3 = (fk4) => {
44208
44334
  return fk4.tableFrom === fk4.tableTo;
44209
44335
  };
44210
- column6 = (type, name, enumTypes, defaultValue) => {
44336
+ column6 = (type, name, enumTypes, defaultValue, casing) => {
44211
44337
  const lowered = type.toLowerCase();
44212
44338
  if (lowered.startsWith("serial")) {
44213
- return `${name.camelCase()}: serial("${name}")`;
44339
+ return `${withCasing3(name, casing)}: serial("${name}")`;
44214
44340
  }
44215
44341
  if (lowered.startsWith("smallserial")) {
44216
- return `${name.camelCase()}: smallserial("${name}")`;
44342
+ return `${withCasing3(name, casing)}: smallserial("${name}")`;
44217
44343
  }
44218
44344
  if (lowered.startsWith("bigserial")) {
44219
- return `${name.camelCase()}: bigserial("${name}", { mode: "bigint" })`;
44345
+ return `${withCasing3(
44346
+ name,
44347
+ casing
44348
+ )}: bigserial("${name}", { mode: "bigint" })`;
44220
44349
  }
44221
44350
  if (lowered.startsWith("integer")) {
44222
- let out = `${name.camelCase()}: integer("${name}")`;
44351
+ let out = `${withCasing3(name, casing)}: integer("${name}")`;
44223
44352
  out += defaultValue ? `.default(${defaultValue})` : "";
44224
44353
  return out;
44225
44354
  }
44226
44355
  if (lowered.startsWith("smallint")) {
44227
- let out = `${name.camelCase()}: smallint("${name}")`;
44356
+ let out = `${withCasing3(name, casing)}: smallint("${name}")`;
44228
44357
  out += defaultValue ? `.default(${defaultValue})` : "";
44229
44358
  return out;
44230
44359
  }
44231
44360
  if (lowered.startsWith("bigint")) {
44232
44361
  let out = `// You can use { mode: "bigint" } if numbers are exceeding js number limitations
44233
44362
  `;
44234
- out += `${name.camelCase()}: bigint("${name}", { mode: "number" })`;
44363
+ out += `${withCasing3(name, casing)}: bigint("${name}", { mode: "number" })`;
44235
44364
  out += defaultValue ? `.default(${defaultValue})` : "";
44236
44365
  return out;
44237
44366
  }
44238
44367
  if (lowered.startsWith("boolean")) {
44239
- let out = `${name.camelCase()}: boolean("${name}")`;
44368
+ let out = `${withCasing3(name, casing)}: boolean("${name}")`;
44240
44369
  out += defaultValue ? `.default(${defaultValue})` : "";
44241
44370
  return out;
44242
44371
  }
44243
44372
  if (lowered.startsWith("double precision")) {
44244
- let out = `${name.camelCase()}: doublePrecision("${name}")`;
44373
+ let out = `${withCasing3(name, casing)}: doublePrecision("${name}")`;
44245
44374
  out += defaultValue ? `.default(${defaultValue})` : "";
44246
44375
  return out;
44247
44376
  }
44248
44377
  if (lowered.startsWith("real")) {
44249
- let out = `${name.camelCase()}: real("${name}")`;
44378
+ let out = `${withCasing3(name, casing)}: real("${name}")`;
44250
44379
  out += defaultValue ? `.default(${defaultValue})` : "";
44251
44380
  return out;
44252
44381
  }
44253
44382
  if (lowered.startsWith("uuid")) {
44254
- let out = `${name.camelCase()}: uuid("${name}")`;
44383
+ let out = `${withCasing3(name, casing)}: uuid("${name}")`;
44255
44384
  out += defaultValue === "gen_random_uuid()" ? ".defaultRandom()" : defaultValue ? `.default(sql\`${defaultValue}\`)` : "";
44256
44385
  return out;
44257
44386
  }
@@ -44261,7 +44390,7 @@ var init_introspect = __esm({
44261
44390
  const [precision, scale] = lowered.slice(8, lowered.length - 1).split(",");
44262
44391
  params = { precision, scale };
44263
44392
  }
44264
- let out = params ? `${name.camelCase()}: numeric("${name}", ${timeConfig2(params)})` : `${name.camelCase()}: numeric("${name}")`;
44393
+ let out = params ? `${withCasing3(name, casing)}: numeric("${name}", ${timeConfig2(params)})` : `${withCasing3(name, casing)}: numeric("${name}")`;
44265
44394
  defaultValue = defaultValue ? defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`) ? defaultValue.substring(1, defaultValue.length - 1) : defaultValue : void 0;
44266
44395
  out += defaultValue ? `.default('${defaultValue}')` : "";
44267
44396
  return out;
@@ -44277,7 +44406,7 @@ var init_introspect = __esm({
44277
44406
  withTimezone,
44278
44407
  mode: "'string'"
44279
44408
  });
44280
- let out = params ? `${name.camelCase()}: timestamp("${name}", ${params})` : `${name.camelCase()}: timestamp("${name}")`;
44409
+ let out = params ? `${withCasing3(name, casing)}: timestamp("${name}", ${params})` : `${withCasing3(name, casing)}: timestamp("${name}")`;
44281
44410
  defaultValue = defaultValue === "now()" || defaultValue === "CURRENT_TIMESTAMP" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
44282
44411
  out += defaultValue;
44283
44412
  return out;
@@ -44289,59 +44418,59 @@ var init_introspect = __esm({
44289
44418
  ) : null;
44290
44419
  precision = precision ? precision : null;
44291
44420
  const params = timeConfig2({ precision, withTimezone });
44292
- let out = params ? `${name.camelCase()}: time("${name}", ${params})` : `${name.camelCase()}: time("${name}")`;
44421
+ let out = params ? `${withCasing3(name, casing)}: time("${name}", ${params})` : `${withCasing3(name, casing)}: time("${name}")`;
44293
44422
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
44294
44423
  out += defaultValue;
44295
44424
  return out;
44296
44425
  }
44297
44426
  if (lowered.startsWith("interval")) {
44298
44427
  const params = intervalConfig(lowered);
44299
- let out = params ? `${name.camelCase()}: interval("${name}", ${params})` : `${name.camelCase()}: interval("${name}")`;
44428
+ let out = params ? `${withCasing3(name, casing)}: interval("${name}", ${params})` : `${withCasing3(name, casing)}: interval("${name}")`;
44300
44429
  out += defaultValue ? `.default(${defaultValue})` : "";
44301
44430
  return out;
44302
44431
  }
44303
44432
  if (lowered === "date") {
44304
- let out = `${name.camelCase()}: date("${name}")`;
44433
+ let out = `${withCasing3(name, casing)}: date("${name}")`;
44305
44434
  defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
44306
44435
  out += defaultValue;
44307
44436
  return out;
44308
44437
  }
44309
44438
  if (lowered.startsWith("text")) {
44310
- let out = `${name.camelCase()}: text("${name}")`;
44439
+ let out = `${withCasing3(name, casing)}: text("${name}")`;
44311
44440
  out += defaultValue ? `.default(${defaultValue})` : "";
44312
44441
  return out;
44313
44442
  }
44314
44443
  if (lowered === "json") {
44315
- let out = `${name.camelCase()}: json("${name}")`;
44444
+ let out = `${withCasing3(name, casing)}: json("${name}")`;
44316
44445
  defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::json")) ? defaultValue.substring(1, defaultValue.length - 7) : defaultValue;
44317
44446
  const def = defaultValue ? defaultValue : null;
44318
44447
  out += defaultValue ? `.default(${def})` : "";
44319
44448
  return out;
44320
44449
  }
44321
44450
  if (lowered === "jsonb") {
44322
- let out = `${name.camelCase()}: jsonb("${name}")`;
44451
+ let out = `${withCasing3(name, casing)}: jsonb("${name}")`;
44323
44452
  defaultValue = (defaultValue == null ? void 0 : defaultValue.endsWith("::jsonb")) ? defaultValue.substring(1, defaultValue.length - 8) : defaultValue;
44324
44453
  const def = defaultValue ? defaultValue : null;
44325
44454
  out += defaultValue ? `.default(${def})` : "";
44326
44455
  return out;
44327
44456
  }
44328
44457
  if (lowered.startsWith("inet")) {
44329
- let out = `${name.camelCase()}: inet("${name}")`;
44458
+ let out = `${withCasing3(name, casing)}: inet("${name}")`;
44330
44459
  out += defaultValue ? `.default(${defaultValue})` : "";
44331
44460
  return out;
44332
44461
  }
44333
44462
  if (lowered.startsWith("cidr")) {
44334
- let out = `${name.camelCase()}: cidr("${name}")`;
44463
+ let out = `${withCasing3(name, casing)}: cidr("${name}")`;
44335
44464
  out += defaultValue ? `.default(${defaultValue})` : "";
44336
44465
  return out;
44337
44466
  }
44338
44467
  if (lowered.startsWith("macaddr")) {
44339
- let out = `${name.camelCase()}: macaddr("${name}")`;
44468
+ let out = `${withCasing3(name, casing)}: macaddr("${name}")`;
44340
44469
  out += defaultValue ? `.default(${defaultValue})` : "";
44341
44470
  return out;
44342
44471
  }
44343
44472
  if (lowered.startsWith("macaddr8")) {
44344
- let out = `${name.camelCase()}: macaddr8("${name}")`;
44473
+ let out = `${withCasing3(name, casing)}: macaddr8("${name}")`;
44345
44474
  out += defaultValue ? `.default(${defaultValue})` : "";
44346
44475
  return out;
44347
44476
  }
@@ -44349,12 +44478,15 @@ var init_introspect = __esm({
44349
44478
  const split = lowered.split(" ");
44350
44479
  let out;
44351
44480
  if (lowered.length !== 7) {
44352
- out = `${name.camelCase()}: varchar("${name}", { length: ${lowered.substring(
44481
+ out = `${withCasing3(
44482
+ name,
44483
+ casing
44484
+ )}: varchar("${name}", { length: ${lowered.substring(
44353
44485
  8,
44354
44486
  lowered.length - 1
44355
44487
  )} })`;
44356
44488
  } else {
44357
- out = `${name.camelCase()}: varchar("${name}")`;
44489
+ out = `${withCasing3(name, casing)}: varchar("${name}")`;
44358
44490
  }
44359
44491
  out += defaultValue ? `.default(${defaultValue})` : "";
44360
44492
  return out;
@@ -44362,24 +44494,30 @@ var init_introspect = __esm({
44362
44494
  if (lowered.startsWith("char")) {
44363
44495
  let out;
44364
44496
  if (lowered.length !== 4) {
44365
- out = `${name.camelCase()}: char("${name}", { length: ${lowered.substring(
44497
+ out = `${withCasing3(
44498
+ name,
44499
+ casing
44500
+ )}: char("${name}", { length: ${lowered.substring(
44366
44501
  5,
44367
44502
  lowered.length - 1
44368
44503
  )} })`;
44369
44504
  } else {
44370
- out = `${name.camelCase()}: char("${name}")`;
44505
+ out = `${withCasing3(name, casing)}: char("${name}")`;
44371
44506
  }
44372
44507
  out += defaultValue ? `.default(${defaultValue})` : "";
44373
44508
  return out;
44374
44509
  }
44375
44510
  if (enumTypes.has(type)) {
44376
- let out = `${name.camelCase()}: ${type.camelCase()}("${name}")`;
44511
+ let out = `${withCasing3(name, casing)}: ${withCasing3(
44512
+ type,
44513
+ casing
44514
+ )}("${name}")`;
44377
44515
  out += defaultValue ? `.default(${defaultValue})` : "";
44378
44516
  return out;
44379
44517
  }
44380
44518
  let unknown = `// TODO: failed to parse database type '${type}'
44381
44519
  `;
44382
- unknown += ` ${name.camelCase()}: unknown("${name}")`;
44520
+ unknown += ` ${withCasing3(name, casing)}: unknown("${name}")`;
44383
44521
  return unknown;
44384
44522
  };
44385
44523
  dimensionsInArray = (str) => {
@@ -44391,7 +44529,7 @@ var init_introspect = __esm({
44391
44529
  }
44392
44530
  return res;
44393
44531
  };
44394
- createTableColumns3 = (columns, fks, enumTypes) => {
44532
+ createTableColumns3 = (columns, fks, enumTypes, casing) => {
44395
44533
  let statement = "";
44396
44534
  const oneColumnsFKs = Object.values(fks).filter((it) => {
44397
44535
  return !isSelf3(it);
@@ -44403,7 +44541,7 @@ var init_introspect = __esm({
44403
44541
  return res;
44404
44542
  }, {});
44405
44543
  columns.forEach((it) => {
44406
- const columnStatement = column6(it.type, it.name, enumTypes, it.default);
44544
+ const columnStatement = column6(it.type, it.name, enumTypes, it.default, casing);
44407
44545
  statement += " ";
44408
44546
  statement += columnStatement;
44409
44547
  statement += dimensionsInArray(it.type);
@@ -44418,9 +44556,15 @@ var init_introspect = __esm({
44418
44556
  const typeSuffix = isCyclic3(it2) ? ": AnyPgColumn" : "";
44419
44557
  const paramsStr = objToStatement23(params);
44420
44558
  if (paramsStr) {
44421
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()}, ${paramsStr} )`;
44422
- }
44423
- return `.references(()${typeSuffix} => ${it2.tableTo.camelCase()}.${it2.columnsTo[0].camelCase()})`;
44559
+ return `.references(()${typeSuffix} => ${withCasing3(
44560
+ it2.tableTo,
44561
+ casing
44562
+ )}.${withCasing3(it2.columnsTo[0], casing)}, ${paramsStr} )`;
44563
+ }
44564
+ return `.references(()${typeSuffix} => ${withCasing3(
44565
+ it2.tableTo,
44566
+ casing
44567
+ )}.${withCasing3(it2.columnsTo[0], casing)})`;
44424
44568
  }).join("");
44425
44569
  statement += fksStatement;
44426
44570
  }
@@ -44428,31 +44572,31 @@ var init_introspect = __esm({
44428
44572
  });
44429
44573
  return statement;
44430
44574
  };
44431
- createTableIndexes3 = (tableName, idxs) => {
44575
+ createTableIndexes3 = (tableName, idxs, casing) => {
44432
44576
  let statement = "";
44433
44577
  idxs.forEach((it) => {
44434
44578
  let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
44435
44579
  idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
44436
- idxKey = idxKey.camelCase();
44580
+ idxKey = withCasing3(idxKey, casing);
44437
44581
  const indexGeneratedName = indexName2(tableName, it.columns);
44438
44582
  const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
44439
44583
  statement += ` ${idxKey}: `;
44440
44584
  statement += it.isUnique ? "uniqueIndex(" : "index(";
44441
44585
  statement += `${escapedIndexName})`;
44442
- statement += `.on(${it.columns.map((it2) => `table.${it2.camelCase()}`).join(", ")}),`;
44586
+ statement += `.on(${it.columns.map((it2) => `table.${withCasing3(it2, casing)}`).join(", ")}),`;
44443
44587
  statement += `
44444
44588
  `;
44445
44589
  });
44446
44590
  return statement;
44447
44591
  };
44448
- createTablePKs3 = (pks) => {
44592
+ createTablePKs3 = (pks, casing) => {
44449
44593
  let statement = "";
44450
44594
  pks.forEach((it) => {
44451
- let idxKey = it.name.camelCase();
44595
+ let idxKey = withCasing3(it.name, casing);
44452
44596
  statement += ` ${idxKey}: `;
44453
44597
  statement += "primaryKey(";
44454
44598
  statement += `${it.columns.map((c) => {
44455
- return `table.${c.camelCase()}`;
44599
+ return `table.${withCasing3(c, casing)}`;
44456
44600
  }).join(", ")}`;
44457
44601
  statement += ")";
44458
44602
  statement += `
@@ -44460,16 +44604,16 @@ var init_introspect = __esm({
44460
44604
  });
44461
44605
  return statement;
44462
44606
  };
44463
- createTableFKs3 = (fks) => {
44607
+ createTableFKs3 = (fks, casing) => {
44464
44608
  let statement = "";
44465
44609
  fks.forEach((it) => {
44466
44610
  const isSelf4 = it.tableTo === it.tableFrom;
44467
- const tableTo = isSelf4 ? "table" : `${it.tableTo.camelCase()}`;
44468
- statement += ` ${it.name.camelCase()}: foreignKey({
44611
+ const tableTo = isSelf4 ? "table" : `${withCasing3(it.tableTo, casing)}`;
44612
+ statement += ` ${withCasing3(it.name, casing)}: foreignKey({
44469
44613
  `;
44470
- statement += ` columns: [${it.columnsFrom.map((i) => `table.${i.camelCase()}`).join(", ")}],
44614
+ statement += ` columns: [${it.columnsFrom.map((i) => `table.${withCasing3(i, casing)}`).join(", ")}],
44471
44615
  `;
44472
- statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${i.camelCase()}`).join(", ")}]
44616
+ statement += ` foreignColumns: [${it.columnsTo.map((i) => `${tableTo}.${withCasing3(i, casing)}`).join(", ")}]
44473
44617
  `;
44474
44618
  statement += ` })`;
44475
44619
  statement += it.onUpdate && it.onUpdate !== "no action" ? `.onUpdate("${it.onUpdate}")` : "";
@@ -44485,45 +44629,42 @@ var init_introspect = __esm({
44485
44629
  // src/cli/commands/pgIntrospect.ts
44486
44630
  var pgIntrospect_exports = {};
44487
44631
  __export(pgIntrospect_exports, {
44488
- PgConfig1: () => PgConfig1,
44489
- PgConfig2: () => PgConfig2,
44490
44632
  pgIntrospect: () => pgIntrospect
44491
44633
  });
44492
- var import_hanji7, import_pg, PgConfig1, PgConfig2, Conf, pgIntrospect;
44634
+ var import_hanji7, import_pg, pgIntrospect;
44493
44635
  var init_pgIntrospect = __esm({
44494
44636
  "src/cli/commands/pgIntrospect.ts"() {
44495
44637
  import_hanji7 = __toESM(require_hanji());
44496
- init_lib();
44497
44638
  init_views();
44498
44639
  import_pg = __toESM(require_lib5());
44499
44640
  init_pgSerializer();
44500
44641
  init_introspect();
44501
44642
  init_global();
44502
- PgConfig1 = objectType({
44503
- host: stringType(),
44504
- port: coerce.number().optional(),
44505
- user: stringType().default("postgres"),
44506
- password: stringType().optional(),
44507
- database: stringType(),
44508
- ssl: coerce.boolean().optional(),
44509
- out: stringType().optional().default("./drizzle")
44510
- }).strict();
44511
- PgConfig2 = objectType({
44512
- connectionString: stringType(),
44513
- out: stringType().optional().default("./drizzle")
44514
- }).strict();
44515
- Conf = unionType([PgConfig1, PgConfig2]);
44516
- pgIntrospect = async (config) => {
44517
- const pool = new import_pg.Pool(config);
44643
+ init_mjs();
44644
+ pgIntrospect = async (config, filters) => {
44645
+ const pool = new import_pg.Pool(config.dbCredentials);
44646
+ const matchers = filters.map((it) => {
44647
+ return new Minimatch(it);
44648
+ });
44649
+ const filter2 = (tableName) => {
44650
+ if (matchers.length === 0)
44651
+ return true;
44652
+ for (let i = 0; i < matchers.length; i++) {
44653
+ const matcher = matchers[i];
44654
+ if (matcher.match(tableName))
44655
+ return true;
44656
+ }
44657
+ return false;
44658
+ };
44518
44659
  const progress = new IntrospectProgress();
44519
44660
  const res = await (0, import_hanji7.renderWithTask)(
44520
44661
  progress,
44521
- fromDatabase2(pool, (stage, count, status) => {
44662
+ fromDatabase2(pool, filter2, (stage, count, status) => {
44522
44663
  progress.update(stage, count, status);
44523
44664
  })
44524
44665
  );
44525
44666
  const schema4 = { id: originUUID, prevId: "", ...res };
44526
- const ts = schemaToTypeScript3(schema4);
44667
+ const ts = schemaToTypeScript3(schema4, { casing: config.introspect.casing });
44527
44668
  return { schema: schema4, ts };
44528
44669
  };
44529
44670
  }
@@ -44596,7 +44737,7 @@ var assertPackages = async (...pkgs) => {
44596
44737
  process.exit(1);
44597
44738
  }
44598
44739
  };
44599
- var requiredApiVersion = 4;
44740
+ var requiredApiVersion = 5;
44600
44741
  var assertOrmCoreVersion = async () => {
44601
44742
  try {
44602
44743
  const { compatibilityVersion } = await import("drizzle-orm/version");
@@ -44667,6 +44808,7 @@ var package_default = {
44667
44808
  "sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
44668
44809
  test: "ava test --timeout=60s",
44669
44810
  build: "rm -rf ./dist && tsx build.ts && tsc -p tsconfig.cli-types.json",
44811
+ "build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
44670
44812
  pack: "build && package",
44671
44813
  tsc: "tsc -p tsconfig.build.json",
44672
44814
  pub: "cp package.json readme.md dist/ && cd dist && npm publish"
@@ -44707,7 +44849,7 @@ var package_default = {
44707
44849
  "better-sqlite3": "^8.4.0",
44708
44850
  dockerode: "^3.3.4",
44709
44851
  dotenv: "^16.0.3",
44710
- "drizzle-orm": "0.26.5-8235b73",
44852
+ "drizzle-orm": "0.27.0-56b9edc",
44711
44853
  esbuild: "^0.17.19",
44712
44854
  "esbuild-register": "^3.4.2",
44713
44855
  eslint: "^8.29.0",
@@ -44791,6 +44933,10 @@ var dropMigration = async (out) => {
44791
44933
  const journal = JSON.parse(
44792
44934
  (0, import_fs9.readFileSync)(metaFilePath, "utf-8")
44793
44935
  );
44936
+ if (journal.entries.length === 0) {
44937
+ console.log(`[${source_default.blue("i")}] no migration entries found in ${metaFilePath}`);
44938
+ return;
44939
+ }
44794
44940
  const result = await (0, import_hanji3.render)(new DropMigrationView(journal.entries));
44795
44941
  if (result.status === "aborted")
44796
44942
  return;
@@ -44862,12 +45008,38 @@ var assertOutFolder = async (it) => {
44862
45008
  var configCommonSchema = objectType({
44863
45009
  schema: unionType([stringType(), stringType().array()]),
44864
45010
  out: stringType().optional(),
44865
- breakpoints: booleanType().optional(),
45011
+ breakpoints: booleanType().default(true),
44866
45012
  tablesFilter: unionType([stringType(), stringType().array()]).optional()
44867
45013
  });
45014
+ var introspectCasing = objectType({
45015
+ casing: unionType([literalType("camel"), literalType("preserve")]).default("camel")
45016
+ }).default({ casing: "camel" });
44868
45017
  var configIntrospectSchema = objectType({
45018
+ schema: unionType([stringType(), stringType().array()]).optional(),
44869
45019
  out: stringType().optional().default("./drizzle"),
44870
- breakpoints: booleanType().optional()
45020
+ breakpoints: booleanType().default(true),
45021
+ tablesFilter: unionType([stringType(), stringType().array()]).optional(),
45022
+ introspect: introspectCasing
45023
+ });
45024
+ var configIntrospectCliSchema = objectType({
45025
+ schema: unionType([stringType(), stringType().array()]).optional(),
45026
+ out: stringType().optional().default("./drizzle"),
45027
+ breakpoints: booleanType().default(true),
45028
+ tablesFilter: unionType([stringType(), stringType().array()]).optional(),
45029
+ introspectCasing: unionType([literalType("camel"), literalType("preserve")]).default(
45030
+ "camel"
45031
+ )
45032
+ });
45033
+ var configGenerateSchema = objectType({
45034
+ schema: unionType([stringType(), stringType().array()]),
45035
+ out: stringType().optional().default("./drizzle"),
45036
+ breakpoints: booleanType().default(true)
45037
+ });
45038
+ var configPushSchema = objectType({
45039
+ schema: unionType([stringType(), stringType().array()]),
45040
+ tablesFilter: unionType([stringType(), stringType().array()]).optional(),
45041
+ verbose: booleanType().default(false),
45042
+ strict: booleanType().default(false)
44871
45043
  });
44872
45044
  var mysqlConnectionSchema = unionType([
44873
45045
  objectType({
@@ -44897,7 +45069,6 @@ var drizzleConfigFromFile = async (configPath) => {
44897
45069
  const defaultJsonConfigExists = (0, import_fs10.existsSync)(
44898
45070
  (0, import_path6.join)((0, import_path6.resolve)("drizzle.config.json"))
44899
45071
  );
44900
- console.log(configPath);
44901
45072
  const defaultConfigPath = defaultTsConfigExists ? "drizzle.config.ts" : defaultJsConfigExists ? "drizzle.config.js" : "drizzle.config.json";
44902
45073
  if (!configPath) {
44903
45074
  console.log(
@@ -44972,6 +45143,7 @@ var logSuggestionsAndReturn = async ({
44972
45143
  }) => {
44973
45144
  let shouldAskForApprove = false;
44974
45145
  const statementsToExecute = [];
45146
+ const infoToPrint = [];
44975
45147
  const tablesToRemove = [];
44976
45148
  const columnsToRemove = [];
44977
45149
  const schemasToRemove = [];
@@ -44983,7 +45155,7 @@ var logSuggestionsAndReturn = async ({
44983
45155
  );
44984
45156
  const count = Number(res[0][0].count);
44985
45157
  if (count > 0) {
44986
- console.log(
45158
+ infoToPrint.push(
44987
45159
  `\xB7 You're about to delete ${source_default.underline(
44988
45160
  statement.tableName
44989
45161
  )} table with ${count} items`
@@ -44997,7 +45169,7 @@ var logSuggestionsAndReturn = async ({
44997
45169
  );
44998
45170
  const count = Number(res[0][0].count);
44999
45171
  if (count > 0) {
45000
- console.log(
45172
+ infoToPrint.push(
45001
45173
  `\xB7 You're about to delete ${source_default.underline(
45002
45174
  statement.columnName
45003
45175
  )} column in ${statement.tableName} table with ${count} items`
@@ -45011,7 +45183,7 @@ var logSuggestionsAndReturn = async ({
45011
45183
  );
45012
45184
  const count = Number(res[0][0].count);
45013
45185
  if (count > 0) {
45014
- console.log(
45186
+ infoToPrint.push(
45015
45187
  `\xB7 You're about to delete ${source_default.underline(
45016
45188
  statement.name
45017
45189
  )} schema with ${count} tables`
@@ -45025,7 +45197,7 @@ var logSuggestionsAndReturn = async ({
45025
45197
  );
45026
45198
  const count = Number(res[0][0].count);
45027
45199
  if (count > 0) {
45028
- console.log(
45200
+ infoToPrint.push(
45029
45201
  `\xB7 You're about to change ${source_default.underline(
45030
45202
  statement.columnName
45031
45203
  )} column type from ${source_default.underline(
@@ -45043,7 +45215,7 @@ var logSuggestionsAndReturn = async ({
45043
45215
  );
45044
45216
  const count = Number(res[0][0].count);
45045
45217
  if (count > 0) {
45046
- console.log(
45218
+ infoToPrint.push(
45047
45219
  `\xB7 You're about to remove default value from ${source_default.underline(
45048
45220
  statement.columnName
45049
45221
  )} not-null column with ${count} items`
@@ -45061,7 +45233,7 @@ var logSuggestionsAndReturn = async ({
45061
45233
  );
45062
45234
  const count = Number(res[0][0].count);
45063
45235
  if (count > 0) {
45064
- console.log(
45236
+ infoToPrint.push(
45065
45237
  `\xB7 You're about to set not-null constraint to ${source_default.underline(
45066
45238
  statement.columnName
45067
45239
  )} column without default, which contains ${count} items`
@@ -45077,7 +45249,7 @@ var logSuggestionsAndReturn = async ({
45077
45249
  );
45078
45250
  const count = Number(res[0][0].count);
45079
45251
  if (count > 0) {
45080
- console.log(
45252
+ infoToPrint.push(
45081
45253
  `\xB7 You're about to change ${source_default.underline(
45082
45254
  statement.tableName
45083
45255
  )} primary key. This statements may fail and you table may left without primary key`
@@ -45092,7 +45264,7 @@ var logSuggestionsAndReturn = async ({
45092
45264
  );
45093
45265
  const count = Number(res[0][0].count);
45094
45266
  if (count > 0) {
45095
- console.log(
45267
+ infoToPrint.push(
45096
45268
  `\xB7 You're about to add not-null ${source_default.underline(
45097
45269
  statement.column.name
45098
45270
  )} column without default value, which contains ${count} items`
@@ -45107,6 +45279,7 @@ var logSuggestionsAndReturn = async ({
45107
45279
  return {
45108
45280
  statementsToExecute,
45109
45281
  shouldAskForApprove,
45282
+ infoToPrint,
45110
45283
  columnsToRemove: [...new Set(columnsToRemove)],
45111
45284
  schemasToRemove: [...new Set(schemasToRemove)],
45112
45285
  tablesToTruncate: [...new Set(tablesToTruncate)],
@@ -45292,11 +45465,32 @@ var logSuggestionsAndReturn2 = async ({
45292
45465
  }
45293
45466
  }
45294
45467
  } else if (statement.type === "alter_table_alter_column_set_type" || statement.type === "alter_table_alter_column_set_default" || statement.type === "alter_table_alter_column_drop_default" || statement.type === "alter_table_alter_column_set_notnull" || statement.type === "alter_table_alter_column_drop_notnull" || statement.type === "alter_table_alter_column_drop_autoincrement" || statement.type === "alter_table_alter_column_set_autoincrement" || statement.type === "alter_table_alter_column_drop_pk" || statement.type === "alter_table_alter_column_set_pk") {
45295
- if (typeof tablesContext[statement.tableName] === "undefined") {
45296
- tablesContext[statement.tableName] = _moveDataStatements(
45297
- statement.tableName,
45298
- json2
45468
+ if (statement.type === "alter_table_alter_column_set_notnull" && typeof statement.columnDefault === "undefined") {
45469
+ const res = await connection.query(
45470
+ `select count(*) as count from \`${statement.tableName}\``
45299
45471
  );
45472
+ const count = Number(res[0].count);
45473
+ if (count > 0) {
45474
+ infoToPrint.push(
45475
+ `\xB7 You're about to add not-null constraint to ${source_default.underline(
45476
+ statement.columnName
45477
+ )} column without default value, which contains ${count} items`
45478
+ );
45479
+ tablesContext[statement.tableName] = _moveDataStatements(
45480
+ statement.tableName,
45481
+ json2,
45482
+ true
45483
+ );
45484
+ tablesToTruncate.push(statement.tableName);
45485
+ shouldAskForApprove = true;
45486
+ }
45487
+ } else {
45488
+ if (typeof tablesContext[statement.tableName] === "undefined") {
45489
+ tablesContext[statement.tableName] = _moveDataStatements(
45490
+ statement.tableName,
45491
+ json2
45492
+ );
45493
+ }
45300
45494
  }
45301
45495
  const tablesReferncingCurrent = [];
45302
45496
  for (const table4 of Object.values(json1.tables)) {
@@ -45374,14 +45568,8 @@ var sqliteConnectionSchema = unionType([
45374
45568
  })
45375
45569
  })
45376
45570
  ]);
45377
- var configIntrospectSchema2 = objectType({
45378
- schema: unionType([stringType(), stringType().array()]).optional(),
45379
- out: stringType().optional().default("./drizzle"),
45380
- breakpoints: booleanType().optional(),
45381
- tablesFilter: unionType([stringType(), stringType().array()]).optional()
45382
- });
45383
45571
  var sqliteCliConfigSchema = intersectionType(
45384
- configIntrospectSchema2,
45572
+ configIntrospectSchema,
45385
45573
  sqliteConnectionSchema
45386
45574
  );
45387
45575
 
@@ -45392,27 +45580,42 @@ var withStyle = {
45392
45580
  warning: (str) => `${source_default.white.bgGray(" Warning ")} ${str}`
45393
45581
  };
45394
45582
  var outputs = {
45395
- sqlite: {
45396
- common: {
45397
- ambiguousParams: (command) => withStyle.error(
45398
- `You can't use both --config and other cli options for ${command} command`
45583
+ common: {
45584
+ ambiguousParams: (command) => withStyle.error(
45585
+ `You can't use both --config and other cli options for ${command} command`
45586
+ ),
45587
+ schema: (command) => withStyle.error(`"--schema" is a required field for ${command} command`)
45588
+ },
45589
+ postgres: {
45590
+ connection: {
45591
+ driver: () => withStyle.error(
45592
+ `Only "pg" is available options for "--driver"`
45593
+ ),
45594
+ required: () => withStyle.error(
45595
+ `Either "connectionString" or "host", "database" are required for database connection`
45399
45596
  )
45400
- },
45597
+ }
45598
+ },
45599
+ mysql: {
45401
45600
  connection: {
45402
45601
  driver: () => withStyle.error(
45403
- `Either "turso", "libsql", "better-sqlite" are available options for "--driver"`
45602
+ `Only "mysql2" is available options for "--driver"`
45404
45603
  ),
45604
+ required: () => withStyle.error(
45605
+ `Either "connectionString" or "host", "database" are required for database connection`
45606
+ )
45607
+ }
45608
+ },
45609
+ sqlite: {
45610
+ connection: {
45611
+ driver: () => withStyle.error(`Either "turso", "libsql", "better-sqlite" are available options for "--driver"`),
45405
45612
  url: (driver) => withStyle.error(`"--url" is a required option for driver "${driver}"`),
45406
45613
  authToken: (driver) => withStyle.error(
45407
45614
  `"--auth-token" is a required option for driver "${driver}"`
45408
45615
  )
45409
45616
  },
45410
45617
  introspect: {},
45411
- push: {
45412
- schema: () => withStyle.error(
45413
- `"--schema" is a required field for sqlite:push command`
45414
- )
45415
- }
45618
+ push: {}
45416
45619
  }
45417
45620
  };
45418
45621
 
@@ -45445,7 +45648,7 @@ var checkCollisions = (options, command, inputWhitelist = []) => {
45445
45648
  }
45446
45649
  return {
45447
45650
  success: false,
45448
- message: outputs.sqlite.common.ambiguousParams(command),
45651
+ message: outputs.common.ambiguousParams(command),
45449
45652
  action: "error"
45450
45653
  };
45451
45654
  };
@@ -45467,15 +45670,9 @@ var sqliteConnectionCli = unionType([
45467
45670
  })
45468
45671
  ]);
45469
45672
  var sqliteCliIntrospectParams = intersectionType(
45470
- configIntrospectSchema2,
45673
+ configIntrospectCliSchema,
45471
45674
  sqliteConnectionCli
45472
45675
  );
45473
- var configPushSchema = objectType({
45474
- schema: unionType([stringType(), stringType().array()]),
45475
- tablesFilter: unionType([stringType(), stringType().array()]).optional(),
45476
- verbose: booleanType().default(false),
45477
- strict: booleanType().default(false)
45478
- });
45479
45676
  var sqliteCliPushParams = intersectionType(
45480
45677
  configPushSchema,
45481
45678
  sqliteConnectionCli
@@ -45525,14 +45722,14 @@ var printConfigConnectionIssues = (options) => {
45525
45722
  console.log(outputs.sqlite.connection.driver());
45526
45723
  }
45527
45724
  };
45528
- var validateIntrospect = (options) => {
45725
+ var validateIntrospect = async (options) => {
45529
45726
  const collisionRes = checkCollisions(options, "introspect:sqlite");
45530
45727
  if (!collisionRes.success) {
45531
45728
  console.log(collisionRes.message);
45532
45729
  process.exit(1);
45533
45730
  }
45534
45731
  if (collisionRes.action === "config") {
45535
- const drizzleConfig = readDrizzleConfig(options.config);
45732
+ const drizzleConfig = await readDrizzleConfig(options.config);
45536
45733
  const configRes = sqliteCliConfigSchema.safeParse(drizzleConfig);
45537
45734
  if (!configRes.success) {
45538
45735
  printConfigConnectionIssues(drizzleConfig);
@@ -45546,15 +45743,27 @@ var validateIntrospect = (options) => {
45546
45743
  process.exit(1);
45547
45744
  }
45548
45745
  if (cliRes.data.driver === "turso") {
45549
- const { authToken, url: url2, ...rest2 } = cliRes.data;
45550
- return { ...rest2, dbCredentials: { url: url2, authToken } };
45746
+ const { authToken, url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
45747
+ return {
45748
+ ...rest2,
45749
+ dbCredentials: { url: url2, authToken },
45750
+ introspect: { casing: introspectCasing3 }
45751
+ };
45551
45752
  }
45552
45753
  if (cliRes.data.driver === "libsql") {
45553
- const { url: url2, ...rest2 } = cliRes.data;
45554
- return { ...rest2, dbCredentials: { url: url2 } };
45754
+ const { url: url2, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
45755
+ return {
45756
+ ...rest2,
45757
+ dbCredentials: { url: url2 },
45758
+ introspect: { casing: introspectCasing3 }
45759
+ };
45555
45760
  }
45556
- const { url, ...rest } = cliRes.data;
45557
- return { ...rest, dbCredentials: { url } };
45761
+ const { url, introspectCasing: introspectCasing2, ...rest } = cliRes.data;
45762
+ return {
45763
+ ...rest,
45764
+ dbCredentials: { url },
45765
+ introspect: { casing: introspectCasing2 }
45766
+ };
45558
45767
  };
45559
45768
  var validatePush = async (options) => {
45560
45769
  const collisionRes = checkCollisions(options, "push:sqlite");
@@ -45575,7 +45784,7 @@ var validatePush = async (options) => {
45575
45784
  const cliRes = sqliteCliPushParams.safeParse(options);
45576
45785
  if (!cliRes.success) {
45577
45786
  if (typeof options.schema === "undefined") {
45578
- console.log(outputs.sqlite.push.schema());
45787
+ console.log(outputs.common.schema("push:sqlite"));
45579
45788
  }
45580
45789
  printCliConnectionIssues(options);
45581
45790
  process.exit(1);
@@ -45588,6 +45797,269 @@ var validatePush = async (options) => {
45588
45797
  return { ...rest, dbCredentials: { url } };
45589
45798
  };
45590
45799
 
45800
+ // src/cli/validations/pg.ts
45801
+ init_lib();
45802
+ var pgConnectionCli = unionType([
45803
+ objectType({
45804
+ driver: literalType("pg"),
45805
+ host: stringType(),
45806
+ port: coerce.number().optional(),
45807
+ user: stringType().default("postgres"),
45808
+ password: stringType().optional(),
45809
+ database: stringType(),
45810
+ ssl: coerce.boolean().optional(),
45811
+ type: literalType("params").default("params")
45812
+ }),
45813
+ objectType({
45814
+ driver: literalType("pg"),
45815
+ connectionString: stringType(),
45816
+ type: literalType("url").default("url")
45817
+ })
45818
+ ]);
45819
+ var pgConnectionConfig = unionType([
45820
+ objectType({
45821
+ driver: literalType("pg"),
45822
+ dbCredentials: objectType({
45823
+ host: stringType(),
45824
+ port: coerce.number().optional(),
45825
+ user: stringType().default("postgres"),
45826
+ password: stringType().optional(),
45827
+ database: stringType(),
45828
+ ssl: coerce.boolean().optional()
45829
+ })
45830
+ }),
45831
+ objectType({
45832
+ driver: literalType("pg"),
45833
+ dbCredentials: objectType({
45834
+ connectionString: stringType()
45835
+ })
45836
+ })
45837
+ ]);
45838
+ var pgConfigIntrospectSchema = intersectionType(
45839
+ configIntrospectSchema,
45840
+ pgConnectionConfig
45841
+ );
45842
+ var pgCliIntrospectParams = intersectionType(
45843
+ configIntrospectCliSchema,
45844
+ pgConnectionCli
45845
+ );
45846
+ var printCliConnectionIssues2 = (options) => {
45847
+ if (options.driver === "pg") {
45848
+ if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
45849
+ console.log(outputs.postgres.connection.required());
45850
+ }
45851
+ } else {
45852
+ console.log(outputs.postgres.connection.driver());
45853
+ }
45854
+ };
45855
+ var printConfigConnectionIssues2 = (options) => {
45856
+ if (options.driver === "pg") {
45857
+ if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
45858
+ console.log(outputs.postgres.connection.required());
45859
+ }
45860
+ } else {
45861
+ console.log(outputs.postgres.connection.driver());
45862
+ }
45863
+ };
45864
+ var validatePgIntrospect = async (options) => {
45865
+ const collisionRes = checkCollisions(options, "introspect:pg");
45866
+ if (!collisionRes.success) {
45867
+ console.log(collisionRes.message);
45868
+ process.exit(1);
45869
+ }
45870
+ if (collisionRes.action === "config") {
45871
+ const drizzleConfig = await readDrizzleConfig(options.config);
45872
+ const configRes = pgConfigIntrospectSchema.safeParse(drizzleConfig);
45873
+ if (!configRes.success) {
45874
+ printConfigConnectionIssues2(drizzleConfig);
45875
+ process.exit(1);
45876
+ }
45877
+ return configRes.data;
45878
+ }
45879
+ const cliRes = pgCliIntrospectParams.safeParse(options);
45880
+ if (!cliRes.success) {
45881
+ printCliConnectionIssues2(options);
45882
+ process.exit(1);
45883
+ }
45884
+ if (cliRes.data.type === "url") {
45885
+ const { connectionString, introspectCasing: introspectCasing3, ...rest2 } = cliRes.data;
45886
+ return {
45887
+ ...rest2,
45888
+ dbCredentials: { connectionString },
45889
+ introspect: { casing: introspectCasing3 }
45890
+ };
45891
+ }
45892
+ const {
45893
+ host,
45894
+ password,
45895
+ port,
45896
+ database,
45897
+ ssl,
45898
+ user,
45899
+ introspectCasing: introspectCasing2,
45900
+ ...rest
45901
+ } = cliRes.data;
45902
+ return {
45903
+ ...rest,
45904
+ dbCredentials: { host, password, port, database, ssl, user },
45905
+ introspect: { casing: introspectCasing2 }
45906
+ };
45907
+ };
45908
+
45909
+ // src/cli/validations/mysql.ts
45910
+ init_lib();
45911
+ var mysqlConnectionCli = unionType([
45912
+ objectType({
45913
+ driver: literalType("mysql2"),
45914
+ host: stringType(),
45915
+ port: coerce.number().optional(),
45916
+ user: stringType().default("mysql"),
45917
+ password: stringType().optional(),
45918
+ database: stringType(),
45919
+ type: literalType("params").default("params")
45920
+ }),
45921
+ objectType({
45922
+ driver: literalType("mysql2"),
45923
+ connectionString: stringType(),
45924
+ type: literalType("url").default("url")
45925
+ })
45926
+ ]);
45927
+ var mysqlConnectionConfig = unionType([
45928
+ objectType({
45929
+ driver: literalType("mysql2"),
45930
+ dbCredentials: objectType({
45931
+ host: stringType(),
45932
+ port: coerce.number().optional(),
45933
+ user: stringType().default("mysql"),
45934
+ password: stringType().optional(),
45935
+ database: stringType(),
45936
+ type: literalType("params").default("params")
45937
+ })
45938
+ }),
45939
+ objectType({
45940
+ driver: literalType("mysql2"),
45941
+ dbCredentials: objectType({
45942
+ connectionString: stringType(),
45943
+ type: literalType("url").default("url")
45944
+ })
45945
+ })
45946
+ ]);
45947
+ var mysqlConfigIntrospectSchema = intersectionType(
45948
+ configIntrospectSchema,
45949
+ mysqlConnectionConfig
45950
+ );
45951
+ var mysqlCliIntrospectParams = intersectionType(
45952
+ configIntrospectCliSchema,
45953
+ mysqlConnectionCli
45954
+ );
45955
+ var mysqlCliPushParams = intersectionType(
45956
+ configPushSchema,
45957
+ mysqlConnectionCli
45958
+ );
45959
+ var mysqlConfigPushParams = intersectionType(
45960
+ configPushSchema,
45961
+ mysqlConnectionConfig
45962
+ );
45963
+ var printCliConnectionIssues3 = (options) => {
45964
+ if (options.driver === "mysql2") {
45965
+ if (typeof options.connectionString === "undefined" && (typeof options.host === "undefined" || typeof options.database === "undefined")) {
45966
+ console.log(outputs.mysql.connection.required());
45967
+ }
45968
+ } else {
45969
+ console.log(outputs.mysql.connection.driver());
45970
+ }
45971
+ };
45972
+ var printConfigConnectionIssues3 = (options) => {
45973
+ if (options.driver === "mysql2") {
45974
+ if (typeof options.dbCredentials.connectionString === "undefined" && (typeof options.dbCredentials.host === "undefined" || typeof options.dbCredentials.database === "undefined")) {
45975
+ console.log(outputs.mysql.connection.required());
45976
+ }
45977
+ } else {
45978
+ console.log(outputs.mysql.connection.driver());
45979
+ }
45980
+ };
45981
+ var validateMySqlIntrospect = async (options) => {
45982
+ const collisionRes = checkCollisions(options, "introspect:mysql");
45983
+ if (!collisionRes.success) {
45984
+ console.log(collisionRes.message);
45985
+ process.exit(1);
45986
+ }
45987
+ if (collisionRes.action === "config") {
45988
+ const drizzleConfig = await readDrizzleConfig(options.config);
45989
+ const configRes = mysqlConfigIntrospectSchema.safeParse(drizzleConfig);
45990
+ if (!configRes.success) {
45991
+ printConfigConnectionIssues3(drizzleConfig);
45992
+ process.exit(1);
45993
+ }
45994
+ return configRes.data;
45995
+ }
45996
+ const cliRes = mysqlCliIntrospectParams.safeParse(options);
45997
+ if (!cliRes.success) {
45998
+ printCliConnectionIssues3(options);
45999
+ process.exit(1);
46000
+ }
46001
+ if (cliRes.data.type === "url") {
46002
+ const { connectionString, introspectCasing: introspectCasing3, type: type2, ...rest2 } = cliRes.data;
46003
+ return {
46004
+ ...rest2,
46005
+ dbCredentials: { connectionString, type: type2 },
46006
+ introspect: { casing: introspectCasing3 }
46007
+ };
46008
+ }
46009
+ const {
46010
+ host,
46011
+ password,
46012
+ port,
46013
+ database,
46014
+ user,
46015
+ type,
46016
+ introspectCasing: introspectCasing2,
46017
+ ...rest
46018
+ } = cliRes.data;
46019
+ return {
46020
+ ...rest,
46021
+ dbCredentials: { host, password, port, database, user, type },
46022
+ introspect: { casing: introspectCasing2 }
46023
+ };
46024
+ };
46025
+ var validateMySqlPush = async (options) => {
46026
+ const collisionRes = checkCollisions(options, "push:mysql");
46027
+ if (!collisionRes.success) {
46028
+ console.log(collisionRes.message);
46029
+ console.log();
46030
+ process.exit(1);
46031
+ }
46032
+ if (collisionRes.action === "config") {
46033
+ const drizzleConfig = await readDrizzleConfig(options.config);
46034
+ const configRes = mysqlConfigPushParams.safeParse(drizzleConfig);
46035
+ if (!configRes.success) {
46036
+ printConfigConnectionIssues3(drizzleConfig);
46037
+ process.exit(1);
46038
+ }
46039
+ return configRes.data;
46040
+ }
46041
+ const cliRes = mysqlCliPushParams.safeParse(options);
46042
+ if (!cliRes.success) {
46043
+ if (typeof options.schema === "undefined") {
46044
+ console.log(outputs.common.schema("push:mysql"));
46045
+ }
46046
+ printCliConnectionIssues3(options);
46047
+ process.exit(1);
46048
+ }
46049
+ if (cliRes.data.type === "url") {
46050
+ const { connectionString, type: type2, ...rest2 } = cliRes.data;
46051
+ return {
46052
+ ...rest2,
46053
+ dbCredentials: { connectionString, type: type2 }
46054
+ };
46055
+ }
46056
+ const { host, password, port, database, user, type, ...rest } = cliRes.data;
46057
+ return {
46058
+ ...rest,
46059
+ dbCredentials: { host, password, port, database, user, type }
46060
+ };
46061
+ };
46062
+
45591
46063
  // src/cli/index.ts
45592
46064
  var printVersions = async () => {
45593
46065
  const v = await versions();
@@ -45605,7 +46077,7 @@ var optionsSchema = objectType({
45605
46077
  schema: unionType([stringType(), stringType().array()]).optional(),
45606
46078
  out: stringType().optional().default("./drizzle"),
45607
46079
  config: stringType().optional(),
45608
- breakpoints: booleanType().optional().default(false),
46080
+ breakpoints: booleanType().optional().default(true),
45609
46081
  custom: booleanType().optional().default(false)
45610
46082
  }).strict();
45611
46083
  var generatePgCommand = new import_commander.Command("generate:pg").option("--schema <schema...>", "Path to a schema file or folder").option("--out <out>", `Output folder, 'drizzle' by default`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--custom", "Prepare empty migration file for custom SQL").option(
@@ -45614,6 +46086,15 @@ var generatePgCommand = new import_commander.Command("generate:pg").option("--sc
45614
46086
  ).action(async (options) => {
45615
46087
  await printVersions();
45616
46088
  await assertOrmCoreVersion();
46089
+ const collisionRes = checkCollisions(
46090
+ options,
46091
+ "generate:pg",
46092
+ ["custom"]
46093
+ );
46094
+ if (!collisionRes.success) {
46095
+ console.log(collisionRes.message);
46096
+ process.exit(1);
46097
+ }
45617
46098
  const oprtionsParsed = optionsSchema.parse(options);
45618
46099
  const result = await prepareGenerateConfig(oprtionsParsed);
45619
46100
  await assertPackages("drizzle-orm");
@@ -45626,6 +46107,15 @@ var generateMysqlCommand = new import_commander.Command("generate:mysql").option
45626
46107
  ).action(async (options) => {
45627
46108
  await printVersions();
45628
46109
  await assertOrmCoreVersion();
46110
+ const collisionRes = checkCollisions(
46111
+ options,
46112
+ "generate:mysql",
46113
+ ["custom"]
46114
+ );
46115
+ if (!collisionRes.success) {
46116
+ console.log(collisionRes.message);
46117
+ process.exit(1);
46118
+ }
45629
46119
  const oprtionsParsed = optionsSchema.parse(options);
45630
46120
  const result = await prepareGenerateConfig(oprtionsParsed);
45631
46121
  await assertPackages("drizzle-orm");
@@ -45664,12 +46154,14 @@ var Select = class extends import_hanji8.Prompt {
45664
46154
  var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
45665
46155
  "--config <config>",
45666
46156
  "Path to a config.json file, drizzle.config.json by default"
45667
- ).action(async (options) => {
46157
+ ).option("--schema <schema...>", "Path to a schema file or folder").option("--tableFilters", `Table name filters`).option("--connectionString <connectionString>", "MySQL connection string").option("--driver <driver>", "MySQL database path").option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").option("--verbose", "Print all statements for each push").option("--strict", "Always ask for confirmation").action(async (options) => {
45668
46158
  await printVersions();
45669
46159
  await assertPackages("drizzle-orm");
45670
46160
  await assertOrmCoreVersion();
45671
46161
  const { mysqlPushIntrospect: mysqlPushIntrospect2, connectToMySQL: connectToMySQL2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
45672
- const drizzleConfig = await drizzleConfigFromFile(options.config);
46162
+ const drizzleConfig = await validateMySqlPush(
46163
+ options
46164
+ );
45673
46165
  const fileNames = prepareFilenames(drizzleConfig.schema);
45674
46166
  if (fileNames.length === 0) {
45675
46167
  (0, import_hanji8.render)(
@@ -45698,13 +46190,38 @@ var dbPushMysqlCommand = new import_commander.Command("push:mysql").option(
45698
46190
  columnsToRemove,
45699
46191
  tablesToRemove,
45700
46192
  tablesToTruncate,
46193
+ infoToPrint,
45701
46194
  schemasToRemove
45702
46195
  } = await logSuggestionsAndReturn({
45703
46196
  connection: connection.client,
45704
46197
  statements: filteredStatements
45705
46198
  });
46199
+ if (drizzleConfig.verbose) {
46200
+ console.log();
46201
+ console.log(
46202
+ withStyle.warning("You are about to execute current statements:")
46203
+ );
46204
+ console.log();
46205
+ console.log(
46206
+ [...statementsToExecute, ...statements.sqlStatements].map((s) => source_default.blue(s)).join("\n")
46207
+ );
46208
+ console.log();
46209
+ }
46210
+ if (drizzleConfig.strict) {
46211
+ if (!shouldAskForApprove) {
46212
+ const { status, data } = await (0, import_hanji8.render)(
46213
+ new Select(["No, abort", `Yes, I want to execute all statements`])
46214
+ );
46215
+ if ((data == null ? void 0 : data.index) === 0) {
46216
+ (0, import_hanji8.render)(`[${source_default.red("x")}] All changes were aborted`);
46217
+ process.exit(0);
46218
+ }
46219
+ }
46220
+ }
45706
46221
  if (shouldAskForApprove) {
45707
- console.log("\n");
46222
+ console.log(withStyle.warning("Found data-loss statements:"));
46223
+ console.log(infoToPrint.join("\n"));
46224
+ console.log();
45708
46225
  console.log(
45709
46226
  source_default.red.bold(
45710
46227
  "THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED\n"
@@ -45840,6 +46357,15 @@ var generateSqliteCommand = new import_commander.Command("generate:sqlite").opti
45840
46357
  ).action(async (options) => {
45841
46358
  await printVersions();
45842
46359
  await assertOrmCoreVersion();
46360
+ const collisionRes = checkCollisions(
46361
+ options,
46362
+ "generate:sqlite",
46363
+ ["custom"]
46364
+ );
46365
+ if (!collisionRes.success) {
46366
+ console.log(collisionRes.message);
46367
+ process.exit(1);
46368
+ }
45843
46369
  const oprtionsParsed = optionsSchema.parse(options);
45844
46370
  const result = await prepareGenerateConfig(oprtionsParsed);
45845
46371
  await assertPackages("drizzle-orm");
@@ -45853,6 +46379,14 @@ var checkSchema = objectType({
45853
46379
  var checkPgCommand = new import_commander.Command("check:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
45854
46380
  await printVersions();
45855
46381
  await assertOrmCoreVersion();
46382
+ const collisionRes = checkCollisions(
46383
+ options,
46384
+ "check:pg"
46385
+ );
46386
+ if (!collisionRes.success) {
46387
+ console.log(collisionRes.message);
46388
+ process.exit(1);
46389
+ }
45856
46390
  const params = checkSchema.parse(options);
45857
46391
  const out = await assertOutFolder(params);
45858
46392
  checkHandler(out, "pg");
@@ -45861,14 +46395,46 @@ var checkPgCommand = new import_commander.Command("check:pg").option("--out <out
45861
46395
  var checkSqliteCommand = new import_commander.Command("check:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
45862
46396
  await printVersions();
45863
46397
  await assertOrmCoreVersion();
46398
+ const collisionRes = checkCollisions(
46399
+ options,
46400
+ "check:sqlite"
46401
+ );
46402
+ if (!collisionRes.success) {
46403
+ console.log(collisionRes.message);
46404
+ process.exit(1);
46405
+ }
45864
46406
  const params = checkSchema.parse(options);
45865
46407
  const out = await assertOutFolder(params);
45866
46408
  checkHandler(out, "sqlite");
45867
46409
  console.log("Everything's fine \u{1F436}\u{1F525}");
45868
46410
  });
46411
+ var checkMySqlCommand = new import_commander.Command("check:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
46412
+ await printVersions();
46413
+ await assertOrmCoreVersion();
46414
+ const collisionRes = checkCollisions(
46415
+ options,
46416
+ "check:mysql"
46417
+ );
46418
+ if (!collisionRes.success) {
46419
+ console.log(collisionRes.message);
46420
+ process.exit(1);
46421
+ }
46422
+ const params = checkSchema.parse(options);
46423
+ const out = await assertOutFolder(params);
46424
+ checkHandler(out, "mysql");
46425
+ console.log("Everything's fine \u{1F436}\u{1F525}");
46426
+ });
45869
46427
  var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
45870
46428
  await printVersions();
45871
46429
  await assertOrmCoreVersion();
46430
+ const collisionRes = checkCollisions(
46431
+ options,
46432
+ "up:pg"
46433
+ );
46434
+ if (!collisionRes.success) {
46435
+ console.log(collisionRes.message);
46436
+ process.exit(1);
46437
+ }
45872
46438
  const params = checkSchema.parse(options);
45873
46439
  const out = await assertOutFolder(params);
45874
46440
  await assertPackages("drizzle-orm");
@@ -45879,6 +46445,14 @@ var upPgCommand = new import_commander.Command("up:pg").option("--out <out>", `O
45879
46445
  var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
45880
46446
  await printVersions();
45881
46447
  await assertOrmCoreVersion();
46448
+ const collisionRes = checkCollisions(
46449
+ options,
46450
+ "up:mysql"
46451
+ );
46452
+ if (!collisionRes.success) {
46453
+ console.log(collisionRes.message);
46454
+ process.exit(1);
46455
+ }
45882
46456
  const params = checkSchema.parse(options);
45883
46457
  const out = await assertOutFolder(params);
45884
46458
  await assertPackages("drizzle-orm");
@@ -45889,36 +46463,36 @@ var upMysqlCommand = new import_commander.Command("up:mysql").option("--out <out
45889
46463
  var upSqliteCommand = new import_commander.Command("up:sqlite").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
45890
46464
  await printVersions();
45891
46465
  await assertOrmCoreVersion();
46466
+ const collisionRes = checkCollisions(
46467
+ options,
46468
+ "up:sqlite"
46469
+ );
46470
+ if (!collisionRes.success) {
46471
+ console.log(collisionRes.message);
46472
+ process.exit(1);
46473
+ }
45892
46474
  const params = checkSchema.parse(options);
45893
46475
  const out = await assertOutFolder(params);
45894
46476
  upSqliteHandlerV4(out);
45895
46477
  upgradeFolders("sqlite", out);
45896
46478
  upSqliteHandler(out);
45897
46479
  });
45898
- var pt1 = objectType({
45899
- out: stringType(),
45900
- breakpoints: booleanType().optional().default(false)
45901
- });
45902
- var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--introspect-casing <introspectCasing>", "Column object keys naming strategy").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
46480
+ var introspectPgCommand = new import_commander.Command("introspect:pg").option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option(
46481
+ "--introspect-casing <introspectCasing>",
46482
+ "Column object keys naming strategy"
46483
+ ).option("--driver <driver>", "Postgres connection string").option("--connectionString <connectionString>", "Postgres connection string").option("--host <host>", "Postgres host").option("--port <port>", "Postgres port").option("--user <user>", "Postgres user").option("--password <password>", "Postgres password").option("--database <database>", "Postgres database name").option("--ssl <ssl>", "Postgres ssl").option("--config <config>", `Config path [default=drizzle.config.ts]`).action(async (options) => {
45903
46484
  await printVersions();
45904
46485
  await assertPackages("drizzle-orm");
45905
46486
  await assertOrmCoreVersion();
45906
- const { pgIntrospect: pgIntrospect2, PgConfig2: PgConfig22, PgConfig1: PgConfig12 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
45907
- const drizzleConfig = await readDrizzleConfig(options.config);
45908
- const pgIntrospectConfig = unionType([
45909
- pt1.extend(PgConfig22.shape),
45910
- pt1.extend(PgConfig12.shape)
45911
- ]);
45912
- const res = pgIntrospectConfig.safeParse(drizzleConfig);
45913
- if (!res.success) {
45914
- for (const issue of res.error.issues) {
45915
- console.log(issue.message);
45916
- }
45917
- return;
45918
- }
45919
- const { snapshots, journal } = prepareOutFolder2(res.data.out, "pg");
45920
- const { schema: schema4, ts } = await pgIntrospect2(res.data);
45921
- const schemaFile = import_path7.default.join(res.data.out, "schema.ts");
46487
+ const { pgIntrospect: pgIntrospect2 } = await Promise.resolve().then(() => (init_pgIntrospect(), pgIntrospect_exports));
46488
+ const validatedConfig = await validatePgIntrospect(
46489
+ options
46490
+ );
46491
+ const { snapshots, journal } = prepareOutFolder2(validatedConfig.out, "pg");
46492
+ const filterConfig = validatedConfig.tablesFilter;
46493
+ const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
46494
+ const { schema: schema4, ts } = await pgIntrospect2(validatedConfig, tablesFilter);
46495
+ const schemaFile = import_path7.default.join(validatedConfig.out, "schema.ts");
45922
46496
  (0, import_fs11.writeFileSync)(schemaFile, ts);
45923
46497
  console.log();
45924
46498
  if (snapshots.length === 0) {
@@ -45934,8 +46508,8 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
45934
46508
  sqlStatements,
45935
46509
  journal,
45936
46510
  _meta,
45937
- res.data.out,
45938
- res.data.breakpoints,
46511
+ validatedConfig.out,
46512
+ validatedConfig.breakpoints,
45939
46513
  "introspect"
45940
46514
  );
45941
46515
  } else {
@@ -45957,22 +46531,20 @@ var introspectPgCommand = new import_commander.Command("introspect:pg").option("
45957
46531
  var introspectMySqlCommand = new import_commander.Command("introspect:mysql").option(
45958
46532
  "--config <config>",
45959
46533
  "Path to a config.json file, drizzle.config.json by default"
46534
+ ).option(
46535
+ "--introspect-casing <introspectCasing>",
46536
+ "Column object keys naming strategy"
45960
46537
  ).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--connectionString <connectionString>", "MySQL connection string").option("--host <host>", "MySQL host").option("--port <port>", "MySQL port").option("--user <user>", "MySQL user").option("--password <password>", "MySQL password").option("--database <database>", "MySQL database name").action(async (options) => {
45961
46538
  await printVersions();
45962
46539
  await assertPackages("drizzle-orm");
45963
46540
  await assertOrmCoreVersion();
45964
46541
  const { mysqlIntrospect: mysqlIntrospect2 } = await Promise.resolve().then(() => (init_mysqlIntrospect(), mysqlIntrospect_exports));
45965
- const drizzleConfig = await readDrizzleConfig(options.config);
45966
- const res = mySqlIntrospectConfigSchema.safeParse(drizzleConfig);
45967
- if (!res.success) {
45968
- for (const issue of res.error.issues) {
45969
- console.log(issue.message);
45970
- }
45971
- process.exit(1);
45972
- }
45973
- const out = res.data.out;
46542
+ const res = await validateMySqlIntrospect(options);
46543
+ const out = res.out;
45974
46544
  const { snapshots, journal } = prepareOutFolder2(out, "mysql");
45975
- const { schema: schema4, ts } = await mysqlIntrospect2(res.data);
46545
+ const filterConfig = res.tablesFilter;
46546
+ const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
46547
+ const { schema: schema4, ts } = await mysqlIntrospect2(res, tablesFilter);
45976
46548
  const schemaFile = import_path7.default.join(out, "schema.ts");
45977
46549
  (0, import_fs11.writeFileSync)(schemaFile, ts);
45978
46550
  console.log();
@@ -45990,7 +46562,7 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
45990
46562
  journal,
45991
46563
  _meta,
45992
46564
  out,
45993
- res.data.breakpoints ?? false,
46565
+ res.breakpoints ?? false,
45994
46566
  "introspect"
45995
46567
  );
45996
46568
  } else {
@@ -46012,15 +46584,20 @@ var introspectMySqlCommand = new import_commander.Command("introspect:mysql").op
46012
46584
  var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").option(
46013
46585
  "--config <config>",
46014
46586
  "Path to a config.json file, drizzle.config.json by default"
46587
+ ).option(
46588
+ "--introspect-casing <introspectCasing>",
46589
+ "Column object keys naming strategy"
46015
46590
  ).option("--schema <schema>", `Migrations folder`).option("--out <out>", `Migrations folder`).option("--breakpoints", `Prepare SQL statements with breakpoints`).option("--driver <driver>", "SQLite database path").option("--url <url>", "SQLite database url").option("--auth-token <authToken>", "SQLite database path").action(async (options) => {
46016
46591
  printVersions();
46017
46592
  assertPackages("drizzle-orm");
46018
46593
  assertOrmCoreVersion();
46019
46594
  const { sqliteIntrospect: sqliteIntrospect2 } = await Promise.resolve().then(() => (init_sqliteIntrospect(), sqliteIntrospect_exports));
46020
- const res = validateIntrospect(options);
46595
+ const res = await validateIntrospect(options);
46021
46596
  const out = res.out;
46022
46597
  const { snapshots, journal } = prepareOutFolder2(out, "sqlite");
46023
- const { schema: schema4, ts } = await sqliteIntrospect2(res);
46598
+ const filterConfig = res.tablesFilter;
46599
+ const tablesFilter = filterConfig ? typeof filterConfig === "string" ? [filterConfig] : filterConfig : [];
46600
+ const { schema: schema4, ts } = await sqliteIntrospect2(res, tablesFilter);
46024
46601
  const schemaFile = import_path7.default.join(out, "schema.ts");
46025
46602
  (0, import_fs11.writeFileSync)(schemaFile, ts);
46026
46603
  console.log();
@@ -46060,10 +46637,18 @@ var introspectSQLiteCommand = new import_commander.Command("introspect:sqlite").
46060
46637
  var dropCommand = new import_commander.Command("drop").option("--out <out>", `Output folder`).option("--config <config>", `Config path [default=drizzle.config.json]`).action(async (options) => {
46061
46638
  await printVersions();
46062
46639
  await assertOrmCoreVersion();
46640
+ const collisionRes = checkCollisions(
46641
+ options,
46642
+ "drop"
46643
+ );
46644
+ if (!collisionRes.success) {
46645
+ console.log(collisionRes.message);
46646
+ process.exit(1);
46647
+ }
46063
46648
  const params = checkSchema.parse(options);
46064
46649
  const out = await assertOutFolder(params);
46065
46650
  assertV1OutFolder(out, "{dialect}");
46066
- dropMigration(out);
46651
+ await dropMigration(out);
46067
46652
  });
46068
46653
  var main = async () => {
46069
46654
  const version2 = await versions();
@@ -46082,6 +46667,7 @@ var main = async () => {
46082
46667
  import_commander.program.addCommand(dbPushMysqlCommand);
46083
46668
  import_commander.program.addCommand(introspectSQLiteCommand);
46084
46669
  import_commander.program.addCommand(dbPushSqliteCommand);
46670
+ import_commander.program.addCommand(checkMySqlCommand);
46085
46671
  import_commander.program.parse();
46086
46672
  };
46087
46673
  main();