drizzle-kit 1.0.0-beta.3-36e9b9e → 1.0.0-beta.3-bd5bd2b

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/api-mysql.js CHANGED
@@ -10676,6 +10676,7 @@ var init_stringify = __esm({
10676
10676
  case `number`:
10677
10677
  return Number.isFinite(value) ? value.toString() : `null`;
10678
10678
  case `boolean`:
10679
+ return value.toString();
10679
10680
  case `bigint`:
10680
10681
  return n6 ? `${value.toString()}n` : value.toString();
10681
10682
  case `object`: {
package/api-mysql.mjs CHANGED
@@ -10688,6 +10688,7 @@ var init_stringify = __esm({
10688
10688
  case `number`:
10689
10689
  return Number.isFinite(value) ? value.toString() : `null`;
10690
10690
  case `boolean`:
10691
+ return value.toString();
10691
10692
  case `bigint`:
10692
10693
  return n6 ? `${value.toString()}n` : value.toString();
10693
10694
  case `object`: {
package/api-postgres.js CHANGED
@@ -5993,6 +5993,7 @@ var init_stringify = __esm({
5993
5993
  case `number`:
5994
5994
  return Number.isFinite(value) ? value.toString() : `null`;
5995
5995
  case `boolean`:
5996
+ return value.toString();
5996
5997
  case `bigint`:
5997
5998
  return n6 ? `${value.toString()}n` : value.toString();
5998
5999
  case `object`: {
@@ -6229,7 +6230,7 @@ function formatTime(date2) {
6229
6230
  const iso = instant.toString({ timeZone: "UTC" });
6230
6231
  return iso;
6231
6232
  }
6232
- var import_polyfill, SmallInt, Int, BigInt2, Numeric, Real, Double, Boolean2, Char, Varchar, Text, toDefaultArray, Json, Jsonb, Time, TimeTz, DateType, Timestamp, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum, Serial, BigSerial, SmallSerial, Custom, typeFor, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, defaultsCommutative, defaults;
6233
+ var import_polyfill, SmallInt, Int, BigInt2, Numeric, Real, Double, Boolean2, Char, Varchar, Text, toDefaultArray, Json, Jsonb, Time, TimeTz, DateType, Timestamp, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum, Serial, BigSerial, SmallSerial, Custom, typeFor, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, mapSerialToInt, defaultsCommutative, defaults;
6233
6234
  var init_grammar = __esm({
6234
6235
  "src/dialects/postgres/grammar.ts"() {
6235
6236
  "use strict";
@@ -7819,6 +7820,18 @@ var init_grammar = __esm({
7819
7820
  isSerialType = (type) => {
7820
7821
  return /^(?:serial|bigserial|smallserial)$/i.test(type);
7821
7822
  };
7823
+ mapSerialToInt = (type) => {
7824
+ switch (type) {
7825
+ case "smallserial":
7826
+ return "smallint";
7827
+ case "serial":
7828
+ return "int";
7829
+ case "bigserial":
7830
+ return "bigint";
7831
+ default:
7832
+ throw new Error(`Unsupported type: ${type}`);
7833
+ }
7834
+ };
7822
7835
  defaultsCommutative = (diffDef, type, dimensions) => {
7823
7836
  if (!diffDef) return false;
7824
7837
  let from = diffDef.from;
@@ -22998,7 +23011,7 @@ var init_convertor = __esm({
22998
23011
  return [drop, add];
22999
23012
  });
23000
23013
  alterColumnConvertor = convertor("alter_column", (st) => {
23001
- const { diff: diff2, to: column7, isEnum, wasEnum, wasSerial } = st;
23014
+ const { diff: diff2, to: column7, isEnum, wasEnum, wasSerial, toSerial } = st;
23002
23015
  const statements = [];
23003
23016
  const key = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}"` : `"${column7.table}"`;
23004
23017
  const recreateDefault = diff2.type && (isEnum || wasEnum) && diff2.$left.default;
@@ -23008,17 +23021,21 @@ var init_convertor = __esm({
23008
23021
  if (diff2.type) {
23009
23022
  const typeSchema = column7.typeSchema && column7.typeSchema !== "public" ? `"${column7.typeSchema}".` : "";
23010
23023
  const textProxy = wasEnum && isEnum ? "text::" : "";
23011
- const suffix = isEnum ? ` USING "${column7.name}"::${textProxy}${typeSchema}"${column7.type}"${"[]".repeat(column7.dimensions)}` : ` USING "${column7.name}"::${column7.type}${"[]".repeat(column7.dimensions)}`;
23012
- let type;
23013
- if (diff2.type) {
23014
- type = diff2.typeSchema?.to && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : diff2.type.to;
23015
- } else {
23016
- type = `${typeSchema}${column7.typeSchema ? `"${column7.type}"` : column7.type}`;
23017
- }
23024
+ const suffix = isEnum ? ` USING "${column7.name}"::${textProxy}${typeSchema}"${column7.type}"${"[]".repeat(column7.dimensions)}` : ` USING "${column7.name}"::${toSerial ? mapSerialToInt(column7.type) : column7.type}${"[]".repeat(column7.dimensions)}`;
23025
+ const type = diff2.typeSchema?.to && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : toSerial ? mapSerialToInt(diff2.type.to) : diff2.type.to;
23018
23026
  if (wasSerial) {
23019
- statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column7.name}" DROP DEFAULT`);
23027
+ statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column7.name}" DROP DEFAULT;`);
23028
+ const sequenceKey = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}_${column7.name}_seq"` : `"${column7.table}_${column7.name}_seq"`;
23029
+ statements.push(`DROP SEQUENCE ${sequenceKey};`);
23030
+ }
23031
+ if (toSerial) {
23020
23032
  const sequenceKey = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}_${column7.name}_seq"` : `"${column7.table}_${column7.name}_seq"`;
23021
- statements.push(`DROP SEQUENCE ${sequenceKey}`);
23033
+ const sequenceName = column7.schema !== "public" ? `${column7.schema}.${column7.table}_${column7.name}_seq` : `${column7.table}_${column7.name}_seq`;
23034
+ statements.push(`CREATE SEQUENCE ${sequenceKey};`);
23035
+ statements.push(
23036
+ `ALTER TABLE ${key} ALTER COLUMN "${column7.name}" SET DEFAULT nextval('${sequenceName}')`
23037
+ );
23038
+ statements.push(`ALTER SEQUENCE ${sequenceKey} OWNED BY "${column7.schema}"."${column7.table}"."${column7.name}";`);
23022
23039
  }
23023
23040
  statements.push(
23024
23041
  `ALTER TABLE ${key} ALTER COLUMN "${column7.name}" SET DATA TYPE ${type}${"[]".repeat(column7.dimensions)}${suffix};`
@@ -24320,6 +24337,7 @@ var init_diff = __esm({
24320
24337
  }).map((it) => {
24321
24338
  const column7 = it.$right;
24322
24339
  const wasSerial = isSerialType(it.$left.type);
24340
+ const toSerial = !isSerialType(it.$left.type) && isSerialType(it.$right.type);
24323
24341
  const isEnum = ddl22.enums.one({ schema: column7.typeSchema ?? "public", name: column7.type }) !== null;
24324
24342
  const wasEnum = (it.type && ddl1.enums.one({ schema: column7.typeSchema ?? "public", name: it.type.from }) !== null) ?? false;
24325
24343
  return prepareStatement("alter_column", {
@@ -24327,7 +24345,8 @@ var init_diff = __esm({
24327
24345
  to: column7,
24328
24346
  isEnum,
24329
24347
  wasEnum,
24330
- wasSerial
24348
+ wasSerial,
24349
+ toSerial
24331
24350
  });
24332
24351
  });
24333
24352
  const createSequences = createdSequences.map((it) => prepareStatement("create_sequence", { sequence: it }));
package/api-postgres.mjs CHANGED
@@ -5999,6 +5999,7 @@ var init_stringify = __esm({
5999
5999
  case `number`:
6000
6000
  return Number.isFinite(value) ? value.toString() : `null`;
6001
6001
  case `boolean`:
6002
+ return value.toString();
6002
6003
  case `bigint`:
6003
6004
  return n6 ? `${value.toString()}n` : value.toString();
6004
6005
  case `object`: {
@@ -6236,7 +6237,7 @@ function formatTime(date2) {
6236
6237
  const iso = instant.toString({ timeZone: "UTC" });
6237
6238
  return iso;
6238
6239
  }
6239
- var SmallInt, Int, BigInt2, Numeric, Real, Double, Boolean2, Char, Varchar, Text, toDefaultArray, Json, Jsonb, Time, TimeTz, DateType, Timestamp, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum, Serial, BigSerial, SmallSerial, Custom, typeFor, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, defaultsCommutative, defaults;
6240
+ var SmallInt, Int, BigInt2, Numeric, Real, Double, Boolean2, Char, Varchar, Text, toDefaultArray, Json, Jsonb, Time, TimeTz, DateType, Timestamp, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum, Serial, BigSerial, SmallSerial, Custom, typeFor, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, mapSerialToInt, defaultsCommutative, defaults;
6240
6241
  var init_grammar = __esm({
6241
6242
  "src/dialects/postgres/grammar.ts"() {
6242
6243
  "use strict";
@@ -7825,6 +7826,18 @@ var init_grammar = __esm({
7825
7826
  isSerialType = (type) => {
7826
7827
  return /^(?:serial|bigserial|smallserial)$/i.test(type);
7827
7828
  };
7829
+ mapSerialToInt = (type) => {
7830
+ switch (type) {
7831
+ case "smallserial":
7832
+ return "smallint";
7833
+ case "serial":
7834
+ return "int";
7835
+ case "bigserial":
7836
+ return "bigint";
7837
+ default:
7838
+ throw new Error(`Unsupported type: ${type}`);
7839
+ }
7840
+ };
7828
7841
  defaultsCommutative = (diffDef, type, dimensions) => {
7829
7842
  if (!diffDef) return false;
7830
7843
  let from = diffDef.from;
@@ -23035,7 +23048,7 @@ var init_convertor = __esm({
23035
23048
  return [drop, add];
23036
23049
  });
23037
23050
  alterColumnConvertor = convertor("alter_column", (st) => {
23038
- const { diff: diff2, to: column7, isEnum, wasEnum, wasSerial } = st;
23051
+ const { diff: diff2, to: column7, isEnum, wasEnum, wasSerial, toSerial } = st;
23039
23052
  const statements = [];
23040
23053
  const key = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}"` : `"${column7.table}"`;
23041
23054
  const recreateDefault = diff2.type && (isEnum || wasEnum) && diff2.$left.default;
@@ -23045,17 +23058,21 @@ var init_convertor = __esm({
23045
23058
  if (diff2.type) {
23046
23059
  const typeSchema = column7.typeSchema && column7.typeSchema !== "public" ? `"${column7.typeSchema}".` : "";
23047
23060
  const textProxy = wasEnum && isEnum ? "text::" : "";
23048
- const suffix = isEnum ? ` USING "${column7.name}"::${textProxy}${typeSchema}"${column7.type}"${"[]".repeat(column7.dimensions)}` : ` USING "${column7.name}"::${column7.type}${"[]".repeat(column7.dimensions)}`;
23049
- let type;
23050
- if (diff2.type) {
23051
- type = diff2.typeSchema?.to && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : diff2.type.to;
23052
- } else {
23053
- type = `${typeSchema}${column7.typeSchema ? `"${column7.type}"` : column7.type}`;
23054
- }
23061
+ const suffix = isEnum ? ` USING "${column7.name}"::${textProxy}${typeSchema}"${column7.type}"${"[]".repeat(column7.dimensions)}` : ` USING "${column7.name}"::${toSerial ? mapSerialToInt(column7.type) : column7.type}${"[]".repeat(column7.dimensions)}`;
23062
+ const type = diff2.typeSchema?.to && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : toSerial ? mapSerialToInt(diff2.type.to) : diff2.type.to;
23055
23063
  if (wasSerial) {
23056
- statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column7.name}" DROP DEFAULT`);
23064
+ statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column7.name}" DROP DEFAULT;`);
23065
+ const sequenceKey = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}_${column7.name}_seq"` : `"${column7.table}_${column7.name}_seq"`;
23066
+ statements.push(`DROP SEQUENCE ${sequenceKey};`);
23067
+ }
23068
+ if (toSerial) {
23057
23069
  const sequenceKey = column7.schema !== "public" ? `"${column7.schema}"."${column7.table}_${column7.name}_seq"` : `"${column7.table}_${column7.name}_seq"`;
23058
- statements.push(`DROP SEQUENCE ${sequenceKey}`);
23070
+ const sequenceName = column7.schema !== "public" ? `${column7.schema}.${column7.table}_${column7.name}_seq` : `${column7.table}_${column7.name}_seq`;
23071
+ statements.push(`CREATE SEQUENCE ${sequenceKey};`);
23072
+ statements.push(
23073
+ `ALTER TABLE ${key} ALTER COLUMN "${column7.name}" SET DEFAULT nextval('${sequenceName}')`
23074
+ );
23075
+ statements.push(`ALTER SEQUENCE ${sequenceKey} OWNED BY "${column7.schema}"."${column7.table}"."${column7.name}";`);
23059
23076
  }
23060
23077
  statements.push(
23061
23078
  `ALTER TABLE ${key} ALTER COLUMN "${column7.name}" SET DATA TYPE ${type}${"[]".repeat(column7.dimensions)}${suffix};`
@@ -24357,6 +24374,7 @@ var init_diff = __esm({
24357
24374
  }).map((it) => {
24358
24375
  const column7 = it.$right;
24359
24376
  const wasSerial = isSerialType(it.$left.type);
24377
+ const toSerial = !isSerialType(it.$left.type) && isSerialType(it.$right.type);
24360
24378
  const isEnum = ddl22.enums.one({ schema: column7.typeSchema ?? "public", name: column7.type }) !== null;
24361
24379
  const wasEnum = (it.type && ddl1.enums.one({ schema: column7.typeSchema ?? "public", name: it.type.from }) !== null) ?? false;
24362
24380
  return prepareStatement("alter_column", {
@@ -24364,7 +24382,8 @@ var init_diff = __esm({
24364
24382
  to: column7,
24365
24383
  isEnum,
24366
24384
  wasEnum,
24367
- wasSerial
24385
+ wasSerial,
24386
+ toSerial
24368
24387
  });
24369
24388
  });
24370
24389
  const createSequences = createdSequences.map((it) => prepareStatement("create_sequence", { sequence: it }));
package/api-sqlite.js CHANGED
@@ -10676,6 +10676,7 @@ var init_stringify = __esm({
10676
10676
  case `number`:
10677
10677
  return Number.isFinite(value) ? value.toString() : `null`;
10678
10678
  case `boolean`:
10679
+ return value.toString();
10679
10680
  case `bigint`:
10680
10681
  return n6 ? `${value.toString()}n` : value.toString();
10681
10682
  case `object`: {
package/api-sqlite.mjs CHANGED
@@ -10688,6 +10688,7 @@ var init_stringify = __esm({
10688
10688
  case `number`:
10689
10689
  return Number.isFinite(value) ? value.toString() : `null`;
10690
10690
  case `boolean`:
10691
+ return value.toString();
10691
10692
  case `bigint`:
10692
10693
  return n6 ? `${value.toString()}n` : value.toString();
10693
10694
  case `object`: {
package/bin.cjs CHANGED
@@ -9498,6 +9498,7 @@ var init_stringify = __esm({
9498
9498
  case `number`:
9499
9499
  return Number.isFinite(value) ? value.toString() : `null`;
9500
9500
  case `boolean`:
9501
+ return value.toString();
9501
9502
  case `bigint`:
9502
9503
  return n5 ? `${value.toString()}n` : value.toString();
9503
9504
  case `object`: {
@@ -21140,7 +21141,7 @@ function formatTime(date2) {
21140
21141
  const iso = instant.toString({ timeZone: "UTC" });
21141
21142
  return iso;
21142
21143
  }
21143
- var SmallInt2, Int2, BigInt3, Numeric, Real2, Double2, Boolean3, Char2, Varchar2, Text2, toDefaultArray, Json2, Jsonb, Time2, TimeTz, DateType, Timestamp2, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum2, Serial2, BigSerial, SmallSerial, Custom2, typeFor2, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK2, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, defaultsCommutative, defaults;
21144
+ var SmallInt2, Int2, BigInt3, Numeric, Real2, Double2, Boolean3, Char2, Varchar2, Text2, toDefaultArray, Json2, Jsonb, Time2, TimeTz, DateType, Timestamp2, TimestampTz, Uuid, Interval2, Inet, Cidr, MacAddr, MacAddr8, Vector, HalfVec, SparseVec, Bit, Point, Line, GeometryPoint, Enum2, Serial2, BigSerial, SmallSerial, Custom2, typeFor2, splitSqlType, vectorOps, indexName, isSerialExpression, parseOnType, systemNamespaceNames, isSystemNamespace, wrapRecord, parseViewDefinition, defaultNameForIdentitySequence, defaultNameForPK, defaultNameForFK2, defaultNameForUnique, defaultNameForIndex, trimDefaultValueSuffix, defaultForColumn, defaultToSQL, isDefaultAction, isSerialType, mapSerialToInt, defaultsCommutative, defaults;
21144
21145
  var init_grammar2 = __esm({
21145
21146
  "src/dialects/postgres/grammar.ts"() {
21146
21147
  "use strict";
@@ -22732,6 +22733,18 @@ var init_grammar2 = __esm({
22732
22733
  isSerialType = (type) => {
22733
22734
  return /^(?:serial|bigserial|smallserial)$/i.test(type);
22734
22735
  };
22736
+ mapSerialToInt = (type) => {
22737
+ switch (type) {
22738
+ case "smallserial":
22739
+ return "smallint";
22740
+ case "serial":
22741
+ return "int";
22742
+ case "bigserial":
22743
+ return "bigint";
22744
+ default:
22745
+ throw new Error(`Unsupported type: ${type}`);
22746
+ }
22747
+ };
22735
22748
  defaultsCommutative = (diffDef, type, dimensions) => {
22736
22749
  if (!diffDef) return false;
22737
22750
  let from = diffDef.from;
@@ -38982,7 +38995,7 @@ var init_convertor = __esm({
38982
38995
  });
38983
38996
  alterColumnConvertor = convertor("alter_column", (st2) => {
38984
38997
  var _a5;
38985
- const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial } = st2;
38998
+ const { diff: diff2, to: column11, isEnum, wasEnum, wasSerial, toSerial } = st2;
38986
38999
  const statements = [];
38987
39000
  const key = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}"` : `"${column11.table}"`;
38988
39001
  const recreateDefault = diff2.type && (isEnum || wasEnum) && diff2.$left.default;
@@ -38992,17 +39005,21 @@ var init_convertor = __esm({
38992
39005
  if (diff2.type) {
38993
39006
  const typeSchema = column11.typeSchema && column11.typeSchema !== "public" ? `"${column11.typeSchema}".` : "";
38994
39007
  const textProxy = wasEnum && isEnum ? "text::" : "";
38995
- const suffix = isEnum ? ` USING "${column11.name}"::${textProxy}${typeSchema}"${column11.type}"${"[]".repeat(column11.dimensions)}` : ` USING "${column11.name}"::${column11.type}${"[]".repeat(column11.dimensions)}`;
38996
- let type;
38997
- if (diff2.type) {
38998
- type = ((_a5 = diff2.typeSchema) == null ? void 0 : _a5.to) && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : diff2.type.to;
38999
- } else {
39000
- type = `${typeSchema}${column11.typeSchema ? `"${column11.type}"` : column11.type}`;
39001
- }
39008
+ const suffix = isEnum ? ` USING "${column11.name}"::${textProxy}${typeSchema}"${column11.type}"${"[]".repeat(column11.dimensions)}` : ` USING "${column11.name}"::${toSerial ? mapSerialToInt(column11.type) : column11.type}${"[]".repeat(column11.dimensions)}`;
39009
+ const type = ((_a5 = diff2.typeSchema) == null ? void 0 : _a5.to) && diff2.typeSchema.to !== "public" ? `"${diff2.typeSchema.to}"."${diff2.type.to}"` : isEnum ? `"${diff2.type.to}"` : toSerial ? mapSerialToInt(diff2.type.to) : diff2.type.to;
39002
39010
  if (wasSerial) {
39003
- statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT`);
39011
+ statements.push(`ALTER TABLE ${key} ALTER COLUMN "${column11.name}" DROP DEFAULT;`);
39004
39012
  const sequenceKey = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}_${column11.name}_seq"` : `"${column11.table}_${column11.name}_seq"`;
39005
- statements.push(`DROP SEQUENCE ${sequenceKey}`);
39013
+ statements.push(`DROP SEQUENCE ${sequenceKey};`);
39014
+ }
39015
+ if (toSerial) {
39016
+ const sequenceKey = column11.schema !== "public" ? `"${column11.schema}"."${column11.table}_${column11.name}_seq"` : `"${column11.table}_${column11.name}_seq"`;
39017
+ const sequenceName = column11.schema !== "public" ? `${column11.schema}.${column11.table}_${column11.name}_seq` : `${column11.table}_${column11.name}_seq`;
39018
+ statements.push(`CREATE SEQUENCE ${sequenceKey};`);
39019
+ statements.push(
39020
+ `ALTER TABLE ${key} ALTER COLUMN "${column11.name}" SET DEFAULT nextval('${sequenceName}')`
39021
+ );
39022
+ statements.push(`ALTER SEQUENCE ${sequenceKey} OWNED BY "${column11.schema}"."${column11.table}"."${column11.name}";`);
39006
39023
  }
39007
39024
  statements.push(
39008
39025
  `ALTER TABLE ${key} ALTER COLUMN "${column11.name}" SET DATA TYPE ${type}${"[]".repeat(column11.dimensions)}${suffix};`
@@ -40308,6 +40325,7 @@ var init_diff = __esm({
40308
40325
  }).map((it2) => {
40309
40326
  const column11 = it2.$right;
40310
40327
  const wasSerial = isSerialType(it2.$left.type);
40328
+ const toSerial = !isSerialType(it2.$left.type) && isSerialType(it2.$right.type);
40311
40329
  const isEnum = ddl22.enums.one({ schema: column11.typeSchema ?? "public", name: column11.type }) !== null;
40312
40330
  const wasEnum = (it2.type && ddl1.enums.one({ schema: column11.typeSchema ?? "public", name: it2.type.from }) !== null) ?? false;
40313
40331
  return prepareStatement("alter_column", {
@@ -40315,7 +40333,8 @@ var init_diff = __esm({
40315
40333
  to: column11,
40316
40334
  isEnum,
40317
40335
  wasEnum,
40318
- wasSerial
40336
+ wasSerial,
40337
+ toSerial
40319
40338
  });
40320
40339
  });
40321
40340
  const createSequences = createdSequences.map((it2) => prepareStatement("create_sequence", { sequence: it2 }));
@@ -41572,6 +41591,15 @@ var init_diff2 = __esm({
41572
41591
  });
41573
41592
  for (const pk of alters.filter((x6) => x6.entityType === "pks")) {
41574
41593
  if (pk.columns) {
41594
+ const fks = ddl22.fks.list({ tableTo: pk.table });
41595
+ const fksFound = fks.filter((fk5) => {
41596
+ if (fk5.columnsTo.length !== pk.$left.columns.length) return false;
41597
+ return fk5.columnsTo.every((fkCol) => pk.$left.columns.includes(fkCol));
41598
+ });
41599
+ for (const fk5 of fksFound) {
41600
+ dropFKStatements.push({ type: "drop_constraint", table: fk5.table, constraint: fk5.name, dropAutoIndex: false });
41601
+ createFKsStatements.push({ type: "create_fk", fk: fk5, cause: "alter_pk" });
41602
+ }
41575
41603
  dropPKStatements.push({ type: "drop_pk", pk: pk.$left });
41576
41604
  createPKStatements.push({ type: "create_pk", pk: pk.$right });
41577
41605
  }
@@ -41584,26 +41612,28 @@ var init_diff2 = __esm({
41584
41612
  }
41585
41613
  }
41586
41614
  const statements = [
41587
- ...createTableStatements,
41588
- ...dropFKStatements,
41589
- ...dropTableStatements,
41590
- ...renameTableStatements,
41591
- ...renameColumnsStatement,
41592
- ...dropViewStatements,
41593
- ...renameViewStatements,
41594
- ...alterViewStatements,
41595
- ...dropCheckStatements,
41596
- ...dropIndexeStatements,
41597
- ...dropPKStatements,
41598
- ...columnAlterStatements,
41599
- ...columnRecreateStatatements,
41600
- ...addColumnsStatemets,
41601
- ...createPKStatements,
41602
- ...createIndexesStatements,
41603
- ...createFKsStatements,
41604
- ...createCheckStatements,
41605
- ...dropColumnStatements,
41606
- ...createViewStatements
41615
+ .../* @__PURE__ */ new Set([
41616
+ ...createTableStatements,
41617
+ ...dropFKStatements,
41618
+ ...dropTableStatements,
41619
+ ...renameTableStatements,
41620
+ ...renameColumnsStatement,
41621
+ ...dropViewStatements,
41622
+ ...renameViewStatements,
41623
+ ...alterViewStatements,
41624
+ ...dropCheckStatements,
41625
+ ...dropIndexeStatements,
41626
+ ...dropPKStatements,
41627
+ ...columnAlterStatements,
41628
+ ...columnRecreateStatatements,
41629
+ ...addColumnsStatemets,
41630
+ ...createPKStatements,
41631
+ ...createIndexesStatements,
41632
+ ...createFKsStatements,
41633
+ ...createCheckStatements,
41634
+ ...dropColumnStatements,
41635
+ ...createViewStatements
41636
+ ])
41607
41637
  ];
41608
41638
  const res = fromJson2(statements);
41609
41639
  return {
@@ -41620,9 +41650,10 @@ var init_diff2 = __esm({
41620
41650
  var generate_mysql_exports = {};
41621
41651
  __export(generate_mysql_exports, {
41622
41652
  handle: () => handle2,
41623
- handleExport: () => handleExport2
41653
+ handleExport: () => handleExport2,
41654
+ suggestions: () => suggestions
41624
41655
  });
41625
- var handle2, handleExport2;
41656
+ var suggestions, handle2, handleExport2;
41626
41657
  var init_generate_mysql = __esm({
41627
41658
  "src/cli/commands/generate-mysql.ts"() {
41628
41659
  "use strict";
@@ -41632,8 +41663,57 @@ var init_generate_mysql = __esm({
41632
41663
  init_ddl();
41633
41664
  init_diff2();
41634
41665
  init_prompts();
41666
+ init_outputs();
41635
41667
  init_views();
41636
41668
  init_generate_common();
41669
+ suggestions = (jsonStatements, ddl22) => {
41670
+ const grouped = { errors: [], hints: [] };
41671
+ for (const statement of jsonStatements) {
41672
+ if (statement.type === "create_fk" && statement.cause !== "alter_pk") {
41673
+ const { columnsTo, table: table6, tableTo, columns } = statement.fk;
41674
+ const indexes = ddl22.indexes.list({ isUnique: true, table: tableTo });
41675
+ const pk = ddl22.pks.one({ table: tableTo });
41676
+ const columnsToSet = new Set(columnsTo);
41677
+ const isUniqueFound = indexes.some((index6) => {
41678
+ if (index6.columns.length !== columnsToSet.size) {
41679
+ return false;
41680
+ }
41681
+ return index6.columns.every((col) => columnsToSet.has(col.value));
41682
+ });
41683
+ const isPkFound = pk && pk.columns.length === columnsToSet.size && pk.columns.every((col) => columnsToSet.has(col));
41684
+ if (isPkFound || isUniqueFound) continue;
41685
+ let composite = columnsTo.length > 1 ? "composite " : "";
41686
+ grouped.errors.push(
41687
+ `\xB7 You are trying to add reference from "${table6}" ("${columns.join('", ')}") to "${tableTo}" ("${columnsTo.join(
41688
+ '", '
41689
+ )}"). The referenced columns are not guaranteed to be unique together. A foreign key must point to a PRIMARY KEY or a set of columns with a UNIQUE constraint. You should add a ${composite}unique constraint to the referenced columns`
41690
+ );
41691
+ continue;
41692
+ }
41693
+ if (statement.type === "drop_pk") {
41694
+ const { table: table6, columns } = statement.pk;
41695
+ const fks = ddl22.fks.list({ tableTo: table6 });
41696
+ const indexes = ddl22.indexes.list({ table: table6 });
41697
+ const fkFound = fks.filter((fk5) => {
41698
+ if (fk5.columnsTo.length !== columns.length) return false;
41699
+ return fk5.columnsTo.every((fkCol) => columns.includes(fkCol));
41700
+ });
41701
+ if (fkFound.length === 0) continue;
41702
+ const indexesFound = indexes.some((index6) => {
41703
+ if (index6.columns.length !== columns.length) {
41704
+ return false;
41705
+ }
41706
+ return index6.columns.every((col) => columns.includes(col.value));
41707
+ });
41708
+ if (indexesFound) continue;
41709
+ grouped.errors.push(
41710
+ `\xB7 You are trying to drop primary key from "${table6}" ("${columns.join('", ')}"), but there is an existing reference on this column. You must either add a UNIQUE constraint to ("${columns.join('", ')}") or drop the foreign key constraint that references this column.`
41711
+ );
41712
+ continue;
41713
+ }
41714
+ }
41715
+ return grouped;
41716
+ };
41637
41717
  handle2 = async (config) => {
41638
41718
  const outFolder = config.out;
41639
41719
  const schemaPath = config.schema;
@@ -41654,7 +41734,7 @@ var init_generate_mysql = __esm({
41654
41734
  });
41655
41735
  return;
41656
41736
  }
41657
- const { sqlStatements, renames, groupedStatements } = await ddlDiff2(
41737
+ const { sqlStatements, renames, groupedStatements, statements } = await ddlDiff2(
41658
41738
  ddlPrev,
41659
41739
  ddlCur,
41660
41740
  resolver("table"),
@@ -41662,6 +41742,11 @@ var init_generate_mysql = __esm({
41662
41742
  resolver("view"),
41663
41743
  "default"
41664
41744
  );
41745
+ const { errors } = suggestions(statements, ddlCur);
41746
+ if (errors.length) {
41747
+ console.log(errors.map((err2) => withStyle.errorWarning(err2)).join("\n\n"));
41748
+ process.exit(1);
41749
+ }
41665
41750
  const explainMessage = explain("mysql", groupedStatements, false, []);
41666
41751
  if (explainMessage) console.log(explainMessage);
41667
41752
  writeResult({
@@ -169041,9 +169126,9 @@ var init_pull_mysql = __esm({
169041
169126
  var push_mysql_exports = {};
169042
169127
  __export(push_mysql_exports, {
169043
169128
  handle: () => handle8,
169044
- suggestions: () => suggestions
169129
+ suggestions: () => suggestions2
169045
169130
  });
169046
- var import_hanji8, handle8, identifier, suggestions;
169131
+ var import_hanji8, handle8, identifier, suggestions2;
169047
169132
  var init_push_mysql = __esm({
169048
169133
  "src/cli/commands/push-mysql.ts"() {
169049
169134
  "use strict";
@@ -169090,7 +169175,7 @@ ${filenames.join("\n")}
169090
169175
  if (filteredStatements.length === 0) {
169091
169176
  (0, import_hanji8.render)(`[${source_default.blue("i")}] No changes detected`);
169092
169177
  }
169093
- const hints = await suggestions(db, filteredStatements);
169178
+ const hints = await suggestions2(db, filteredStatements, ddl22);
169094
169179
  const explainMessage = explain("mysql", groupedStatements, explainFlag, hints);
169095
169180
  if (explainMessage) console.log(explainMessage);
169096
169181
  if (explainFlag) return;
@@ -169115,7 +169200,7 @@ ${filenames.join("\n")}
169115
169200
  identifier = ({ table: table6, column: column11 }) => {
169116
169201
  return [table6, column11].filter(Boolean).map((t6) => `\`${t6}\``).join(".");
169117
169202
  };
169118
- suggestions = async (db, jsonStatements) => {
169203
+ suggestions2 = async (db, jsonStatements, ddl22) => {
169119
169204
  const grouped = [];
169120
169205
  const filtered = jsonStatements.filter((it2) => {
169121
169206
  if (it2.type === "alter_column" && it2.diff.generated) return false;
@@ -169139,14 +169224,32 @@ ${filenames.join("\n")}
169139
169224
  continue;
169140
169225
  }
169141
169226
  if (statement.type === "drop_pk") {
169142
- const table6 = statement.pk.table;
169227
+ const { table: table6, columns } = statement.pk;
169143
169228
  const id = identifier({ table: table6 });
169144
169229
  const res = await db.query(
169145
169230
  `select 1 from ${id} limit 1`
169146
169231
  );
169147
- if (res.length === 0) continue;
169148
- const hint = `\xB7 You're about to drop ${source_default.underline(table6)} primary key, this statements may fail and your table may loose primary key`;
169149
- grouped.push({ hint });
169232
+ if (res.length > 0) {
169233
+ const hint = `\xB7 You're about to drop ${source_default.underline(table6)} primary key, this statements may fail and your table may loose primary key`;
169234
+ grouped.push({ hint });
169235
+ }
169236
+ const fks = ddl22.fks.list({ tableTo: table6 });
169237
+ const indexes = ddl22.indexes.list({ isUnique: true, table: table6 });
169238
+ const fkFound = fks.filter((fk5) => {
169239
+ if (fk5.columnsTo.length !== columns.length) return false;
169240
+ return fk5.columnsTo.every((fkCol) => columns.includes(fkCol));
169241
+ });
169242
+ if (fkFound.length === 0) continue;
169243
+ const indexesFound = indexes.some((index6) => {
169244
+ if (index6.columns.length !== columns.length) {
169245
+ return false;
169246
+ }
169247
+ return index6.columns.every((col) => columns.includes(col.value));
169248
+ });
169249
+ if (indexesFound) continue;
169250
+ grouped.push({
169251
+ hint: `\xB7 You are trying to drop primary key from "${table6}" ("${columns.join('", ')}"), but there is an existing reference on this column. You must either add a UNIQUE constraint to ("${columns.join('", ')}") or drop the foreign key constraint that references this column.`
169252
+ });
169150
169253
  continue;
169151
169254
  }
169152
169255
  if (statement.type === "add_column" && statement.column.notNull && statement.column.default === null && !statement.column.generated) {
@@ -169189,6 +169292,27 @@ ${filenames.join("\n")}
169189
169292
  });
169190
169293
  continue;
169191
169294
  }
169295
+ if (statement.type === "create_fk" && statement.cause !== "alter_pk") {
169296
+ const { columnsTo, table: table6, tableTo, columns } = statement.fk;
169297
+ const indexes = ddl22.indexes.list({ isUnique: true, table: tableTo });
169298
+ const pk = ddl22.pks.one({ table: tableTo });
169299
+ const columnsToSet = new Set(columnsTo);
169300
+ const isUniqueFound = indexes.some((index6) => {
169301
+ if (index6.columns.length !== columnsToSet.size) {
169302
+ return false;
169303
+ }
169304
+ return index6.columns.every((col) => columnsToSet.has(col.value));
169305
+ });
169306
+ const isPkFound = pk && pk.columns.length === columnsToSet.size && pk.columns.every((col) => columnsToSet.has(col));
169307
+ if (isPkFound || isUniqueFound) continue;
169308
+ let composite = columnsTo.length > 1 ? "composite " : "";
169309
+ grouped.push({
169310
+ hint: `\xB7 You are trying to add reference from "${table6}" ("${columns.join('", ')}") to "${tableTo}" ("${columnsTo.join(
169311
+ '", '
169312
+ )}"). The referenced columns are not guaranteed to be unique together. A foreign key must point to a PRIMARY KEY or a set of columns with a UNIQUE constraint. You should add a ${composite}unique constraint to the referenced columns`
169313
+ });
169314
+ continue;
169315
+ }
169192
169316
  }
169193
169317
  return grouped;
169194
169318
  };
@@ -170184,9 +170308,9 @@ var init_pull_postgres = __esm({
170184
170308
  var push_postgres_exports = {};
170185
170309
  __export(push_postgres_exports, {
170186
170310
  handle: () => handle10,
170187
- suggestions: () => suggestions2
170311
+ suggestions: () => suggestions3
170188
170312
  });
170189
- var import_hanji10, handle10, identifier2, suggestions2;
170313
+ var import_hanji10, handle10, identifier2, suggestions3;
170190
170314
  var init_push_postgres = __esm({
170191
170315
  "src/cli/commands/push-postgres.ts"() {
170192
170316
  "use strict";
@@ -170249,7 +170373,7 @@ var init_push_postgres = __esm({
170249
170373
  (0, import_hanji10.render)(`[${source_default.blue("i")}] No changes detected`);
170250
170374
  return;
170251
170375
  }
170252
- const hints = await suggestions2(db, jsonStatements);
170376
+ const hints = await suggestions3(db, jsonStatements);
170253
170377
  const explainMessage = explain("postgres", groupedStatements, explainFlag, hints);
170254
170378
  if (explainMessage) console.log(explainMessage);
170255
170379
  if (explainFlag) return;
@@ -170272,7 +170396,7 @@ var init_push_postgres = __esm({
170272
170396
  const schemakey = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
170273
170397
  return `${schemakey}"${name}"`;
170274
170398
  };
170275
- suggestions2 = async (db, jsonStatements) => {
170399
+ suggestions3 = async (db, jsonStatements) => {
170276
170400
  const grouped = [];
170277
170401
  const filtered = jsonStatements.filter((it2) => {
170278
170402
  if (it2.type === "drop_view" && it2.cause) return false;
@@ -171211,9 +171335,9 @@ var init_pull_sqlite = __esm({
171211
171335
  var push_sqlite_exports = {};
171212
171336
  __export(push_sqlite_exports, {
171213
171337
  handle: () => handle12,
171214
- suggestions: () => suggestions3
171338
+ suggestions: () => suggestions4
171215
171339
  });
171216
- var import_hanji12, handle12, suggestions3;
171340
+ var import_hanji12, handle12, suggestions4;
171217
171341
  var init_push_sqlite = __esm({
171218
171342
  "src/cli/commands/push-sqlite.ts"() {
171219
171343
  "use strict";
@@ -171255,7 +171379,7 @@ var init_push_sqlite = __esm({
171255
171379
  [${source_default.blue("i")}] No changes detected`);
171256
171380
  return;
171257
171381
  }
171258
- const hints = await suggestions3(db, statements);
171382
+ const hints = await suggestions4(db, statements);
171259
171383
  const explainMessage = explain("sqlite", groupedStatements, explainFlag, hints);
171260
171384
  if (explainMessage) console.log(explainMessage);
171261
171385
  if (explainFlag) return;
@@ -171289,7 +171413,7 @@ var init_push_sqlite = __esm({
171289
171413
  (0, import_hanji12.render)(`[${source_default.green("\u2713")}] Changes applied`);
171290
171414
  }
171291
171415
  };
171292
- suggestions3 = async (connection, jsonStatements) => {
171416
+ suggestions4 = async (connection, jsonStatements) => {
171293
171417
  const grouped = [];
171294
171418
  for (const statement of jsonStatements) {
171295
171419
  if (statement.type === "drop_table") {
@@ -171361,9 +171485,9 @@ var init_push_libsql = __esm({
171361
171485
  var push_singlestore_exports = {};
171362
171486
  __export(push_singlestore_exports, {
171363
171487
  handle: () => handle14,
171364
- suggestions: () => suggestions4
171488
+ suggestions: () => suggestions5
171365
171489
  });
171366
- var import_hanji13, handle14, suggestions4;
171490
+ var import_hanji13, handle14, suggestions5;
171367
171491
  var init_push_singlestore = __esm({
171368
171492
  "src/cli/commands/push-singlestore.ts"() {
171369
171493
  "use strict";
@@ -171411,7 +171535,7 @@ ${filenames.join("\n")}
171411
171535
  if (filteredStatements.length === 0) {
171412
171536
  (0, import_hanji13.render)(`[${source_default.blue("i")}] No changes detected`);
171413
171537
  } else {
171414
- const { hints, truncates } = await suggestions4(db, filteredStatements);
171538
+ const { hints, truncates } = await suggestions5(db, filteredStatements);
171415
171539
  const combinedStatements = [...truncates, ...sqlStatements];
171416
171540
  if (verbose) {
171417
171541
  console.log();
@@ -171457,7 +171581,7 @@ ${filenames.join("\n")}
171457
171581
  }
171458
171582
  }
171459
171583
  };
171460
- suggestions4 = async (_db, _statements) => {
171584
+ suggestions5 = async (_db, _statements) => {
171461
171585
  const hints = [];
171462
171586
  const truncates = [];
171463
171587
  return { hints, truncates };
@@ -172786,9 +172910,9 @@ var init_pull_cockroach = __esm({
172786
172910
  var push_cockroach_exports = {};
172787
172911
  __export(push_cockroach_exports, {
172788
172912
  handle: () => handle16,
172789
- suggestions: () => suggestions5
172913
+ suggestions: () => suggestions6
172790
172914
  });
172791
- var import_hanji15, handle16, identifier3, suggestions5;
172915
+ var import_hanji15, handle16, identifier3, suggestions6;
172792
172916
  var init_push_cockroach = __esm({
172793
172917
  "src/cli/commands/push-cockroach.ts"() {
172794
172918
  "use strict";
@@ -172848,7 +172972,7 @@ var init_push_cockroach = __esm({
172848
172972
  (0, import_hanji15.render)(`[${source_default.blue("i")}] No changes detected`);
172849
172973
  return;
172850
172974
  }
172851
- const { losses, hints } = await suggestions5(db, jsonStatements);
172975
+ const { losses, hints } = await suggestions6(db, jsonStatements);
172852
172976
  if (verbose) {
172853
172977
  console.log();
172854
172978
  console.log(withStyle.warning("You are about to execute these statements:"));
@@ -172889,7 +173013,7 @@ var init_push_cockroach = __esm({
172889
173013
  const schemakey = schema5 && schema5 !== "public" ? `"${schema5}".` : "";
172890
173014
  return `${schemakey}"${name}"`;
172891
173015
  };
172892
- suggestions5 = async (db, jsonStatements) => {
173016
+ suggestions6 = async (db, jsonStatements) => {
172893
173017
  const statements = [];
172894
173018
  const hints = [];
172895
173019
  const filtered = jsonStatements.filter((it2) => {
@@ -173989,9 +174113,9 @@ var init_pull_mssql = __esm({
173989
174113
  var push_mssql_exports = {};
173990
174114
  __export(push_mssql_exports, {
173991
174115
  handle: () => handle18,
173992
- suggestions: () => suggestions6
174116
+ suggestions: () => suggestions7
173993
174117
  });
173994
- var import_hanji17, handle18, identifier4, suggestions6;
174118
+ var import_hanji17, handle18, identifier4, suggestions7;
173995
174119
  var init_push_mssql = __esm({
173996
174120
  "src/cli/commands/push-mssql.ts"() {
173997
174121
  "use strict";
@@ -174057,7 +174181,7 @@ var init_push_mssql = __esm({
174057
174181
  (0, import_hanji17.render)(`[${source_default.blue("i")}] No changes detected`);
174058
174182
  return;
174059
174183
  }
174060
- const { losses, hints } = await suggestions6(db, jsonStatements, ddl22);
174184
+ const { losses, hints } = await suggestions7(db, jsonStatements, ddl22);
174061
174185
  const statementsToExecute = [...losses, ...sqlStatements];
174062
174186
  if (verbose) {
174063
174187
  console.log();
@@ -174100,7 +174224,7 @@ var init_push_mssql = __esm({
174100
174224
  const tableKey = `[${table6}]`;
174101
174225
  return `${schemaKey}${tableKey}`;
174102
174226
  };
174103
- suggestions6 = async (db, jsonStatements, ddl22) => {
174227
+ suggestions7 = async (db, jsonStatements, ddl22) => {
174104
174228
  const losses = [];
174105
174229
  const hints = [];
174106
174230
  const filtered = jsonStatements.filter((it2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "1.0.0-beta.3-36e9b9e",
3
+ "version": "1.0.0-beta.3-bd5bd2b",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",