drizzle-kit 0.23.2 → 0.24.0-6205f01

Sign up to get free protection for your applications and to get access to all the features.
package/api.d.mts CHANGED
@@ -1411,7 +1411,7 @@ declare const pushMySQLSchema: (imports: Record<string, unknown>, drizzleInstanc
1411
1411
  apply: () => Promise<void>;
1412
1412
  }>;
1413
1413
  declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1414
- version: "6";
1414
+ version: "7";
1415
1415
  dialect: "postgresql";
1416
1416
  tables: Record<string, {
1417
1417
  name: string;
@@ -1444,11 +1444,17 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1444
1444
  }>;
1445
1445
  indexes: Record<string, {
1446
1446
  name: string;
1447
- columns: string[];
1447
+ columns: {
1448
+ expression: string;
1449
+ isExpression: boolean;
1450
+ asc: boolean;
1451
+ nulls?: string | undefined;
1452
+ opclass?: string | undefined;
1453
+ }[];
1448
1454
  isUnique: boolean;
1449
1455
  method: string;
1450
1456
  concurrently: boolean;
1451
- with?: Record<string, string> | undefined;
1457
+ with?: Record<string, any> | undefined;
1452
1458
  where?: string | undefined;
1453
1459
  }>;
1454
1460
  foreignKeys: Record<string, {
@@ -1477,6 +1483,16 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1477
1483
  schema: string;
1478
1484
  }>;
1479
1485
  schemas: Record<string, string>;
1486
+ sequences: Record<string, {
1487
+ name: string;
1488
+ schema: string;
1489
+ increment?: string | undefined;
1490
+ minValue?: string | undefined;
1491
+ maxValue?: string | undefined;
1492
+ startWith?: string | undefined;
1493
+ cache?: string | undefined;
1494
+ cycle?: boolean | undefined;
1495
+ }>;
1480
1496
  _meta: {
1481
1497
  tables: Record<string, string>;
1482
1498
  columns: Record<string, string>;
@@ -1493,6 +1509,6 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1493
1509
  } | undefined>;
1494
1510
  } | undefined>;
1495
1511
  } | undefined;
1496
- };
1512
+ } | Record<string, unknown>;
1497
1513
 
1498
1514
  export { type DrizzleMySQLSnapshotJSON, type DrizzleSQLiteSnapshotJSON, type DrizzleSnapshotJSON, generateDrizzleJson, generateMigration, generateMySQLDrizzleJson, generateMySQLMigration, generateSQLiteDrizzleJson, generateSQLiteMigration, pushMySQLSchema, pushSQLiteSchema, pushSchema, upPgSnapshot };
package/api.d.ts CHANGED
@@ -1411,7 +1411,7 @@ declare const pushMySQLSchema: (imports: Record<string, unknown>, drizzleInstanc
1411
1411
  apply: () => Promise<void>;
1412
1412
  }>;
1413
1413
  declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1414
- version: "6";
1414
+ version: "7";
1415
1415
  dialect: "postgresql";
1416
1416
  tables: Record<string, {
1417
1417
  name: string;
@@ -1444,11 +1444,17 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1444
1444
  }>;
1445
1445
  indexes: Record<string, {
1446
1446
  name: string;
1447
- columns: string[];
1447
+ columns: {
1448
+ expression: string;
1449
+ isExpression: boolean;
1450
+ asc: boolean;
1451
+ nulls?: string | undefined;
1452
+ opclass?: string | undefined;
1453
+ }[];
1448
1454
  isUnique: boolean;
1449
1455
  method: string;
1450
1456
  concurrently: boolean;
1451
- with?: Record<string, string> | undefined;
1457
+ with?: Record<string, any> | undefined;
1452
1458
  where?: string | undefined;
1453
1459
  }>;
1454
1460
  foreignKeys: Record<string, {
@@ -1477,6 +1483,16 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1477
1483
  schema: string;
1478
1484
  }>;
1479
1485
  schemas: Record<string, string>;
1486
+ sequences: Record<string, {
1487
+ name: string;
1488
+ schema: string;
1489
+ increment?: string | undefined;
1490
+ minValue?: string | undefined;
1491
+ maxValue?: string | undefined;
1492
+ startWith?: string | undefined;
1493
+ cache?: string | undefined;
1494
+ cycle?: boolean | undefined;
1495
+ }>;
1480
1496
  _meta: {
1481
1497
  tables: Record<string, string>;
1482
1498
  columns: Record<string, string>;
@@ -1493,6 +1509,6 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1493
1509
  } | undefined>;
1494
1510
  } | undefined>;
1495
1511
  } | undefined;
1496
- };
1512
+ } | Record<string, unknown>;
1497
1513
 
1498
1514
  export { type DrizzleMySQLSnapshotJSON, type DrizzleSQLiteSnapshotJSON, type DrizzleSnapshotJSON, generateDrizzleJson, generateMigration, generateMySQLDrizzleJson, generateMySQLMigration, generateSQLiteDrizzleJson, generateSQLiteMigration, pushMySQLSchema, pushSQLiteSchema, pushSchema, upPgSnapshot };
package/api.js CHANGED
@@ -8338,6 +8338,9 @@ var init_sqliteSchema = __esm({
8338
8338
  });
8339
8339
 
8340
8340
  // src/utils.ts
8341
+ function isPgArrayType(sqlType) {
8342
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
8343
+ }
8341
8344
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8342
8345
  var init_utils = __esm({
8343
8346
  "src/utils.ts"() {
@@ -8711,14 +8714,14 @@ var require_heap = __commonJS({
8711
8714
  return item;
8712
8715
  };
8713
8716
  heapify = function(array, cmp) {
8714
- var i, _i2, _j, _len, _ref, _ref1, _results, _results1;
8717
+ var i, _i2, _j2, _len, _ref, _ref1, _results, _results1;
8715
8718
  if (cmp == null) {
8716
8719
  cmp = defaultCmp;
8717
8720
  }
8718
8721
  _ref1 = function() {
8719
8722
  _results1 = [];
8720
- for (var _j2 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j2 < _ref2 : _j2 > _ref2; 0 <= _ref2 ? _j2++ : _j2--) {
8721
- _results1.push(_j2);
8723
+ for (var _j3 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j3 < _ref2 : _j3 > _ref2; 0 <= _ref2 ? _j3++ : _j3--) {
8724
+ _results1.push(_j3);
8722
8725
  }
8723
8726
  return _results1;
8724
8727
  }.apply(this).reverse();
@@ -8759,7 +8762,7 @@ var require_heap = __commonJS({
8759
8762
  return result.sort(cmp).reverse();
8760
8763
  };
8761
8764
  nsmallest = function(array, n, cmp) {
8762
- var elem, i, los, result, _i2, _j, _len, _ref, _ref1, _results;
8765
+ var elem, i, los, result, _i2, _j2, _len, _ref, _ref1, _results;
8763
8766
  if (cmp == null) {
8764
8767
  cmp = defaultCmp;
8765
8768
  }
@@ -8782,7 +8785,7 @@ var require_heap = __commonJS({
8782
8785
  }
8783
8786
  heapify(array, cmp);
8784
8787
  _results = [];
8785
- for (i = _j = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
8788
+ for (i = _j2 = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j2 < _ref1 : _j2 > _ref1; i = 0 <= _ref1 ? ++_j2 : --_j2) {
8786
8789
  _results.push(heappop(array, cmp));
8787
8790
  }
8788
8791
  return _results;
@@ -17477,7 +17480,7 @@ function getTableName(table4) {
17477
17480
  function getTableUniqueName(table4) {
17478
17481
  return `${table4[Schema] ?? "public"}.${table4[TableName]}`;
17479
17482
  }
17480
- var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, Table2;
17483
+ var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, Table2;
17481
17484
  var init_table = __esm({
17482
17485
  "../drizzle-orm/dist/table.js"() {
17483
17486
  "use strict";
@@ -17491,32 +17494,34 @@ var init_table = __esm({
17491
17494
  IsAlias = Symbol.for("drizzle:IsAlias");
17492
17495
  ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
17493
17496
  IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
17494
- _i = entityKind, _h = TableName, _g = OriginalName, _f = Schema, _e = Columns, _d = ExtraConfigColumns, _c = BaseName, _b = IsAlias, _a3 = ExtraConfigBuilder;
17497
+ _j = entityKind, _i = TableName, _h = OriginalName, _g = Schema, _f = Columns, _e = ExtraConfigColumns, _d = BaseName, _c = IsAlias, _b = IsDrizzleTable, _a3 = ExtraConfigBuilder;
17495
17498
  Table2 = class {
17496
17499
  constructor(name2, schema4, baseName) {
17497
17500
  /**
17498
17501
  * @internal
17499
17502
  * Can be changed if the table is aliased.
17500
17503
  */
17501
- __publicField(this, _h);
17504
+ __publicField(this, _i);
17502
17505
  /**
17503
17506
  * @internal
17504
17507
  * Used to store the original name of the table, before any aliasing.
17505
17508
  */
17509
+ __publicField(this, _h);
17510
+ /** @internal */
17506
17511
  __publicField(this, _g);
17507
17512
  /** @internal */
17508
17513
  __publicField(this, _f);
17509
17514
  /** @internal */
17510
17515
  __publicField(this, _e);
17511
- /** @internal */
17512
- __publicField(this, _d);
17513
17516
  /**
17514
17517
  * @internal
17515
17518
  * Used to store the table name before the transformation via the `tableCreator` functions.
17516
17519
  */
17517
- __publicField(this, _c);
17520
+ __publicField(this, _d);
17518
17521
  /** @internal */
17519
- __publicField(this, _b, false);
17522
+ __publicField(this, _c, false);
17523
+ /** @internal */
17524
+ __publicField(this, _b, true);
17520
17525
  /** @internal */
17521
17526
  __publicField(this, _a3);
17522
17527
  this[TableName] = this[OriginalName] = name2;
@@ -17524,7 +17529,7 @@ var init_table = __esm({
17524
17529
  this[BaseName] = baseName;
17525
17530
  }
17526
17531
  };
17527
- __publicField(Table2, _i, "Table");
17532
+ __publicField(Table2, _j, "Table");
17528
17533
  /** @internal */
17529
17534
  __publicField(Table2, "Symbol", {
17530
17535
  Name: TableName,
@@ -18100,7 +18105,7 @@ var version;
18100
18105
  var init_version = __esm({
18101
18106
  "../drizzle-orm/dist/version.js"() {
18102
18107
  "use strict";
18103
- version = "0.32.2";
18108
+ version = "0.33.0";
18104
18109
  }
18105
18110
  });
18106
18111
 
@@ -18202,6 +18207,12 @@ function fillPlaceholders(params, values) {
18202
18207
  }
18203
18208
  return values[p.name];
18204
18209
  }
18210
+ if (is(p, Param) && is(p.value, Placeholder)) {
18211
+ if (!(p.value.name in values)) {
18212
+ throw new Error(`No value for placeholder "${p.value.name}" was provided`);
18213
+ }
18214
+ return p.encoder.mapToDriverValue(values[p.value.name]);
18215
+ }
18205
18216
  return p;
18206
18217
  });
18207
18218
  }
@@ -18315,6 +18326,9 @@ var init_sql = __esm({
18315
18326
  };
18316
18327
  }
18317
18328
  if (is(chunk, Param)) {
18329
+ if (is(chunk.value, Placeholder)) {
18330
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
18331
+ }
18318
18332
  const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
18319
18333
  if (is(mappedValue, _SQL)) {
18320
18334
  return this.buildQueryFromSourceParams([mappedValue], config);
@@ -24636,6 +24650,30 @@ function minRangeForIdentityBasedOn(columnType) {
24636
24650
  function stringFromDatabaseIdentityProperty(field) {
24637
24651
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
24638
24652
  }
24653
+ function buildArrayString(array, sqlType) {
24654
+ sqlType = sqlType.split("[")[0];
24655
+ const values = array.map((value) => {
24656
+ if (typeof value === "number" || typeof value === "bigint") {
24657
+ return value.toString();
24658
+ } else if (typeof value === "boolean") {
24659
+ return value ? "true" : "false";
24660
+ } else if (Array.isArray(value)) {
24661
+ return buildArrayString(value, sqlType);
24662
+ } else if (value instanceof Date) {
24663
+ if (sqlType === "date") {
24664
+ return `"${value.toISOString().split("T")[0]}"`;
24665
+ } else if (sqlType === "timestamp") {
24666
+ return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
24667
+ } else {
24668
+ return `"${value.toISOString()}"`;
24669
+ }
24670
+ } else if (typeof value === "object") {
24671
+ return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
24672
+ }
24673
+ return `"${value}"`;
24674
+ }).join(",");
24675
+ return `{${values}}`;
24676
+ }
24639
24677
  var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24640
24678
  var init_pgSerializer = __esm({
24641
24679
  "src/serializer/pgSerializer.ts"() {
@@ -24646,6 +24684,7 @@ var init_pgSerializer = __esm({
24646
24684
  init_pg_core();
24647
24685
  init_vector3();
24648
24686
  init_outputs();
24687
+ init_utils();
24649
24688
  init_serializer();
24650
24689
  dialect4 = new PgDialect();
24651
24690
  indexName = (tableName, columns) => {
@@ -24752,6 +24791,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
24752
24791
  } else {
24753
24792
  columnToSet.default = `'${column4.default.toISOString()}'`;
24754
24793
  }
24794
+ } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
24795
+ columnToSet.default = `'${buildArrayString(
24796
+ column4.default,
24797
+ sqlTypeLowered
24798
+ )}'::${sqlTypeLowered}`;
24755
24799
  } else {
24756
24800
  columnToSet.default = column4.default;
24757
24801
  }
@@ -29031,7 +29075,7 @@ The unique constraint ${source_default.underline.blue(
29031
29075
  primaryKeys.forEach((it) => {
29032
29076
  if (it.columns.length > 1) {
29033
29077
  primaryKeysObject[it.getName()] = {
29034
- columns: it.columns.map((it2) => it2.name).sort(),
29078
+ columns: it.columns.map((it2) => it2.name),
29035
29079
  name: it.getName()
29036
29080
  };
29037
29081
  } else {
@@ -29156,7 +29200,6 @@ The unique constraint ${source_default.underline.blue(
29156
29200
  }
29157
29201
  for (const [key, value] of Object.entries(tableToPk)) {
29158
29202
  if (value.length > 1) {
29159
- value.sort();
29160
29203
  result[key].compositePrimaryKeys = {
29161
29204
  [`${key}_${value.join("_")}_pk`]: {
29162
29205
  columns: value,
@@ -33600,7 +33643,7 @@ We have encountered a collision between the index name on columns ${source_defau
33600
33643
  onUpdate = true;
33601
33644
  }
33602
33645
  const newColumn = {
33603
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
33646
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
33604
33647
  autoincrement: isAutoincrement,
33605
33648
  name: columnName,
33606
33649
  type: changedType,
@@ -34817,6 +34860,37 @@ var updateUpToV6 = (json) => {
34817
34860
  enums
34818
34861
  };
34819
34862
  };
34863
+ var updateUpToV7 = (json) => {
34864
+ const schema4 = pgSchemaV6.parse(json);
34865
+ const tables = Object.fromEntries(
34866
+ Object.entries(schema4.tables).map((it) => {
34867
+ const table4 = it[1];
34868
+ const mappedIndexes = Object.fromEntries(
34869
+ Object.entries(table4.indexes).map((idx) => {
34870
+ const { columns, ...rest } = idx[1];
34871
+ const mappedColumns = columns.map((it2) => {
34872
+ return {
34873
+ expression: it2,
34874
+ isExpression: false,
34875
+ asc: true,
34876
+ nulls: "last",
34877
+ opClass: void 0
34878
+ };
34879
+ });
34880
+ return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
34881
+ })
34882
+ );
34883
+ return [it[0], { ...table4, indexes: mappedIndexes }];
34884
+ })
34885
+ );
34886
+ return {
34887
+ ...schema4,
34888
+ version: "7",
34889
+ dialect: "postgresql",
34890
+ sequences: {},
34891
+ tables
34892
+ };
34893
+ };
34820
34894
 
34821
34895
  // src/cli/commands/sqliteIntrospect.ts
34822
34896
  var import_hanji6 = __toESM(require_hanji());
@@ -35473,7 +35547,13 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
35473
35547
  };
35474
35548
  };
35475
35549
  var upPgSnapshot = (snapshot) => {
35476
- return updateUpToV6(snapshot);
35550
+ if (snapshot.version === "5") {
35551
+ return updateUpToV7(updateUpToV6(snapshot));
35552
+ }
35553
+ if (snapshot.version === "6") {
35554
+ return updateUpToV7(snapshot);
35555
+ }
35556
+ return snapshot;
35477
35557
  };
35478
35558
  // Annotate the CommonJS export names for ESM import in node:
35479
35559
  0 && (module.exports = {
package/api.mjs CHANGED
@@ -8343,6 +8343,9 @@ var init_sqliteSchema = __esm({
8343
8343
  });
8344
8344
 
8345
8345
  // src/utils.ts
8346
+ function isPgArrayType(sqlType) {
8347
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
8348
+ }
8346
8349
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8347
8350
  var init_utils = __esm({
8348
8351
  "src/utils.ts"() {
@@ -8716,14 +8719,14 @@ var require_heap = __commonJS({
8716
8719
  return item;
8717
8720
  };
8718
8721
  heapify = function(array, cmp) {
8719
- var i, _i2, _j, _len, _ref, _ref1, _results, _results1;
8722
+ var i, _i2, _j2, _len, _ref, _ref1, _results, _results1;
8720
8723
  if (cmp == null) {
8721
8724
  cmp = defaultCmp;
8722
8725
  }
8723
8726
  _ref1 = function() {
8724
8727
  _results1 = [];
8725
- for (var _j2 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j2 < _ref2 : _j2 > _ref2; 0 <= _ref2 ? _j2++ : _j2--) {
8726
- _results1.push(_j2);
8728
+ for (var _j3 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j3 < _ref2 : _j3 > _ref2; 0 <= _ref2 ? _j3++ : _j3--) {
8729
+ _results1.push(_j3);
8727
8730
  }
8728
8731
  return _results1;
8729
8732
  }.apply(this).reverse();
@@ -8764,7 +8767,7 @@ var require_heap = __commonJS({
8764
8767
  return result.sort(cmp).reverse();
8765
8768
  };
8766
8769
  nsmallest = function(array, n, cmp) {
8767
- var elem, i, los, result, _i2, _j, _len, _ref, _ref1, _results;
8770
+ var elem, i, los, result, _i2, _j2, _len, _ref, _ref1, _results;
8768
8771
  if (cmp == null) {
8769
8772
  cmp = defaultCmp;
8770
8773
  }
@@ -8787,7 +8790,7 @@ var require_heap = __commonJS({
8787
8790
  }
8788
8791
  heapify(array, cmp);
8789
8792
  _results = [];
8790
- for (i = _j = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
8793
+ for (i = _j2 = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j2 < _ref1 : _j2 > _ref1; i = 0 <= _ref1 ? ++_j2 : --_j2) {
8791
8794
  _results.push(heappop(array, cmp));
8792
8795
  }
8793
8796
  return _results;
@@ -17482,7 +17485,7 @@ function getTableName(table4) {
17482
17485
  function getTableUniqueName(table4) {
17483
17486
  return `${table4[Schema] ?? "public"}.${table4[TableName]}`;
17484
17487
  }
17485
- var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, Table2;
17488
+ var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, Table2;
17486
17489
  var init_table = __esm({
17487
17490
  "../drizzle-orm/dist/table.js"() {
17488
17491
  "use strict";
@@ -17496,32 +17499,34 @@ var init_table = __esm({
17496
17499
  IsAlias = Symbol.for("drizzle:IsAlias");
17497
17500
  ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
17498
17501
  IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
17499
- _i = entityKind, _h = TableName, _g = OriginalName, _f = Schema, _e = Columns, _d = ExtraConfigColumns, _c = BaseName, _b = IsAlias, _a3 = ExtraConfigBuilder;
17502
+ _j = entityKind, _i = TableName, _h = OriginalName, _g = Schema, _f = Columns, _e = ExtraConfigColumns, _d = BaseName, _c = IsAlias, _b = IsDrizzleTable, _a3 = ExtraConfigBuilder;
17500
17503
  Table2 = class {
17501
17504
  constructor(name2, schema4, baseName) {
17502
17505
  /**
17503
17506
  * @internal
17504
17507
  * Can be changed if the table is aliased.
17505
17508
  */
17506
- __publicField(this, _h);
17509
+ __publicField(this, _i);
17507
17510
  /**
17508
17511
  * @internal
17509
17512
  * Used to store the original name of the table, before any aliasing.
17510
17513
  */
17514
+ __publicField(this, _h);
17515
+ /** @internal */
17511
17516
  __publicField(this, _g);
17512
17517
  /** @internal */
17513
17518
  __publicField(this, _f);
17514
17519
  /** @internal */
17515
17520
  __publicField(this, _e);
17516
- /** @internal */
17517
- __publicField(this, _d);
17518
17521
  /**
17519
17522
  * @internal
17520
17523
  * Used to store the table name before the transformation via the `tableCreator` functions.
17521
17524
  */
17522
- __publicField(this, _c);
17525
+ __publicField(this, _d);
17523
17526
  /** @internal */
17524
- __publicField(this, _b, false);
17527
+ __publicField(this, _c, false);
17528
+ /** @internal */
17529
+ __publicField(this, _b, true);
17525
17530
  /** @internal */
17526
17531
  __publicField(this, _a3);
17527
17532
  this[TableName] = this[OriginalName] = name2;
@@ -17529,7 +17534,7 @@ var init_table = __esm({
17529
17534
  this[BaseName] = baseName;
17530
17535
  }
17531
17536
  };
17532
- __publicField(Table2, _i, "Table");
17537
+ __publicField(Table2, _j, "Table");
17533
17538
  /** @internal */
17534
17539
  __publicField(Table2, "Symbol", {
17535
17540
  Name: TableName,
@@ -18105,7 +18110,7 @@ var version;
18105
18110
  var init_version = __esm({
18106
18111
  "../drizzle-orm/dist/version.js"() {
18107
18112
  "use strict";
18108
- version = "0.32.2";
18113
+ version = "0.33.0";
18109
18114
  }
18110
18115
  });
18111
18116
 
@@ -18207,6 +18212,12 @@ function fillPlaceholders(params, values) {
18207
18212
  }
18208
18213
  return values[p.name];
18209
18214
  }
18215
+ if (is(p, Param) && is(p.value, Placeholder)) {
18216
+ if (!(p.value.name in values)) {
18217
+ throw new Error(`No value for placeholder "${p.value.name}" was provided`);
18218
+ }
18219
+ return p.encoder.mapToDriverValue(values[p.value.name]);
18220
+ }
18210
18221
  return p;
18211
18222
  });
18212
18223
  }
@@ -18320,6 +18331,9 @@ var init_sql = __esm({
18320
18331
  };
18321
18332
  }
18322
18333
  if (is(chunk, Param)) {
18334
+ if (is(chunk.value, Placeholder)) {
18335
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
18336
+ }
18323
18337
  const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
18324
18338
  if (is(mappedValue, _SQL)) {
18325
18339
  return this.buildQueryFromSourceParams([mappedValue], config);
@@ -24641,6 +24655,30 @@ function minRangeForIdentityBasedOn(columnType) {
24641
24655
  function stringFromDatabaseIdentityProperty(field) {
24642
24656
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
24643
24657
  }
24658
+ function buildArrayString(array, sqlType) {
24659
+ sqlType = sqlType.split("[")[0];
24660
+ const values = array.map((value) => {
24661
+ if (typeof value === "number" || typeof value === "bigint") {
24662
+ return value.toString();
24663
+ } else if (typeof value === "boolean") {
24664
+ return value ? "true" : "false";
24665
+ } else if (Array.isArray(value)) {
24666
+ return buildArrayString(value, sqlType);
24667
+ } else if (value instanceof Date) {
24668
+ if (sqlType === "date") {
24669
+ return `"${value.toISOString().split("T")[0]}"`;
24670
+ } else if (sqlType === "timestamp") {
24671
+ return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
24672
+ } else {
24673
+ return `"${value.toISOString()}"`;
24674
+ }
24675
+ } else if (typeof value === "object") {
24676
+ return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
24677
+ }
24678
+ return `"${value}"`;
24679
+ }).join(",");
24680
+ return `{${values}}`;
24681
+ }
24644
24682
  var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24645
24683
  var init_pgSerializer = __esm({
24646
24684
  "src/serializer/pgSerializer.ts"() {
@@ -24651,6 +24689,7 @@ var init_pgSerializer = __esm({
24651
24689
  init_pg_core();
24652
24690
  init_vector3();
24653
24691
  init_outputs();
24692
+ init_utils();
24654
24693
  init_serializer();
24655
24694
  dialect4 = new PgDialect();
24656
24695
  indexName = (tableName, columns) => {
@@ -24757,6 +24796,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
24757
24796
  } else {
24758
24797
  columnToSet.default = `'${column4.default.toISOString()}'`;
24759
24798
  }
24799
+ } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
24800
+ columnToSet.default = `'${buildArrayString(
24801
+ column4.default,
24802
+ sqlTypeLowered
24803
+ )}'::${sqlTypeLowered}`;
24760
24804
  } else {
24761
24805
  columnToSet.default = column4.default;
24762
24806
  }
@@ -29036,7 +29080,7 @@ The unique constraint ${source_default.underline.blue(
29036
29080
  primaryKeys.forEach((it) => {
29037
29081
  if (it.columns.length > 1) {
29038
29082
  primaryKeysObject[it.getName()] = {
29039
- columns: it.columns.map((it2) => it2.name).sort(),
29083
+ columns: it.columns.map((it2) => it2.name),
29040
29084
  name: it.getName()
29041
29085
  };
29042
29086
  } else {
@@ -29161,7 +29205,6 @@ The unique constraint ${source_default.underline.blue(
29161
29205
  }
29162
29206
  for (const [key, value] of Object.entries(tableToPk)) {
29163
29207
  if (value.length > 1) {
29164
- value.sort();
29165
29208
  result[key].compositePrimaryKeys = {
29166
29209
  [`${key}_${value.join("_")}_pk`]: {
29167
29210
  columns: value,
@@ -33605,7 +33648,7 @@ We have encountered a collision between the index name on columns ${source_defau
33605
33648
  onUpdate = true;
33606
33649
  }
33607
33650
  const newColumn = {
33608
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
33651
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
33609
33652
  autoincrement: isAutoincrement,
33610
33653
  name: columnName,
33611
33654
  type: changedType,
@@ -34808,6 +34851,37 @@ var updateUpToV6 = (json) => {
34808
34851
  enums
34809
34852
  };
34810
34853
  };
34854
+ var updateUpToV7 = (json) => {
34855
+ const schema4 = pgSchemaV6.parse(json);
34856
+ const tables = Object.fromEntries(
34857
+ Object.entries(schema4.tables).map((it) => {
34858
+ const table4 = it[1];
34859
+ const mappedIndexes = Object.fromEntries(
34860
+ Object.entries(table4.indexes).map((idx) => {
34861
+ const { columns, ...rest } = idx[1];
34862
+ const mappedColumns = columns.map((it2) => {
34863
+ return {
34864
+ expression: it2,
34865
+ isExpression: false,
34866
+ asc: true,
34867
+ nulls: "last",
34868
+ opClass: void 0
34869
+ };
34870
+ });
34871
+ return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
34872
+ })
34873
+ );
34874
+ return [it[0], { ...table4, indexes: mappedIndexes }];
34875
+ })
34876
+ );
34877
+ return {
34878
+ ...schema4,
34879
+ version: "7",
34880
+ dialect: "postgresql",
34881
+ sequences: {},
34882
+ tables
34883
+ };
34884
+ };
34811
34885
 
34812
34886
  // src/cli/commands/sqliteIntrospect.ts
34813
34887
  var import_hanji6 = __toESM(require_hanji());
@@ -35464,7 +35538,13 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
35464
35538
  };
35465
35539
  };
35466
35540
  var upPgSnapshot = (snapshot) => {
35467
- return updateUpToV6(snapshot);
35541
+ if (snapshot.version === "5") {
35542
+ return updateUpToV7(updateUpToV6(snapshot));
35543
+ }
35544
+ if (snapshot.version === "6") {
35545
+ return updateUpToV7(snapshot);
35546
+ }
35547
+ return snapshot;
35468
35548
  };
35469
35549
  export {
35470
35550
  generateDrizzleJson,
package/bin.cjs CHANGED
@@ -6561,6 +6561,9 @@ var init_sqliteSchema = __esm({
6561
6561
  });
6562
6562
 
6563
6563
  // src/utils.ts
6564
+ function isPgArrayType(sqlType) {
6565
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
6566
+ }
6564
6567
  var import_fs, import_path, import_url, copy, objectValues, assertV1OutFolder, dryJournal, prepareOutFolder, validatorForDialect, validateWithReport, prepareMigrationFolder, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey, normaliseSQLiteUrl;
6565
6568
  var init_utils = __esm({
6566
6569
  "src/utils.ts"() {
@@ -18107,7 +18110,7 @@ We have encountered a collision between the index name on columns ${source_defau
18107
18110
  onUpdate = true;
18108
18111
  }
18109
18112
  const newColumn = {
18110
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
18113
+ default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !["decimal", "char", "varchar"].some((type) => columnType.startsWith(type)) ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
18111
18114
  autoincrement: isAutoincrement,
18112
18115
  name: columnName,
18113
18116
  type: changedType,
@@ -18406,6 +18409,30 @@ function minRangeForIdentityBasedOn(columnType) {
18406
18409
  function stringFromDatabaseIdentityProperty(field) {
18407
18410
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
18408
18411
  }
18412
+ function buildArrayString(array, sqlType) {
18413
+ sqlType = sqlType.split("[")[0];
18414
+ const values = array.map((value) => {
18415
+ if (typeof value === "number" || typeof value === "bigint") {
18416
+ return value.toString();
18417
+ } else if (typeof value === "boolean") {
18418
+ return value ? "true" : "false";
18419
+ } else if (Array.isArray(value)) {
18420
+ return buildArrayString(value, sqlType);
18421
+ } else if (value instanceof Date) {
18422
+ if (sqlType === "date") {
18423
+ return `"${value.toISOString().split("T")[0]}"`;
18424
+ } else if (sqlType === "timestamp") {
18425
+ return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
18426
+ } else {
18427
+ return `"${value.toISOString()}"`;
18428
+ }
18429
+ } else if (typeof value === "object") {
18430
+ return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
18431
+ }
18432
+ return `"${value}"`;
18433
+ }).join(",");
18434
+ return `{${values}}`;
18435
+ }
18409
18436
  var import_drizzle_orm5, import_pg_core2, import_pg_core3, dialect5, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
18410
18437
  var init_pgSerializer = __esm({
18411
18438
  "src/serializer/pgSerializer.ts"() {
@@ -18416,6 +18443,7 @@ var init_pgSerializer = __esm({
18416
18443
  import_pg_core3 = require("drizzle-orm/pg-core");
18417
18444
  init_vector();
18418
18445
  init_outputs();
18446
+ init_utils();
18419
18447
  init_serializer();
18420
18448
  dialect5 = new import_pg_core2.PgDialect();
18421
18449
  indexName2 = (tableName, columns) => {
@@ -18524,6 +18552,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
18524
18552
  } else {
18525
18553
  columnToSet.default = `'${column7.default.toISOString()}'`;
18526
18554
  }
18555
+ } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column7.default)) {
18556
+ columnToSet.default = `'${buildArrayString(
18557
+ column7.default,
18558
+ sqlTypeLowered
18559
+ )}'::${sqlTypeLowered}`;
18527
18560
  } else {
18528
18561
  columnToSet.default = column7.default;
18529
18562
  }
@@ -19570,7 +19603,7 @@ The unique constraint ${source_default.underline.blue(
19570
19603
  primaryKeys.forEach((it) => {
19571
19604
  if (it.columns.length > 1) {
19572
19605
  primaryKeysObject[it.getName()] = {
19573
- columns: it.columns.map((it2) => it2.name).sort(),
19606
+ columns: it.columns.map((it2) => it2.name),
19574
19607
  name: it.getName()
19575
19608
  };
19576
19609
  } else {
@@ -19696,7 +19729,6 @@ The unique constraint ${source_default.underline.blue(
19696
19729
  }
19697
19730
  for (const [key, value] of Object.entries(tableToPk)) {
19698
19731
  if (value.length > 1) {
19699
- value.sort();
19700
19732
  result[key].compositePrimaryKeys = {
19701
19733
  [`${key}_${value.join("_")}_pk`]: {
19702
19734
  columns: value,
@@ -75265,6 +75297,7 @@ var init_introspect_mysql = __esm({
75265
75297
  patched = patched.startsWith("datetime(") ? "datetime" : patched;
75266
75298
  patched = patched.startsWith("varbinary(") ? "varbinary" : patched;
75267
75299
  patched = patched.startsWith("int(") ? "int" : patched;
75300
+ patched = patched.startsWith("double(") ? "double" : patched;
75268
75301
  return patched;
75269
75302
  }).filter((type) => {
75270
75303
  return mysqlImportsList.has(type);
@@ -83369,7 +83402,7 @@ init_utils2();
83369
83402
  var version2 = async () => {
83370
83403
  const { npmVersion } = await ormCoreVersions();
83371
83404
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
83372
- const envVersion = "0.23.2";
83405
+ const envVersion = "0.24.0-6205f01";
83373
83406
  const kitVersion = envVersion ? `v${envVersion}` : "--";
83374
83407
  const versions = `drizzle-kit: ${kitVersion}
83375
83408
  ${ormVersion}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "0.23.2",
3
+ "version": "0.24.0-6205f01",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",
package/utils.js CHANGED
@@ -568,6 +568,7 @@ __export(utils_exports, {
568
568
  columnRenameKey: () => columnRenameKey,
569
569
  copy: () => copy,
570
570
  dryJournal: () => dryJournal,
571
+ isPgArrayType: () => isPgArrayType,
571
572
  kloudMeta: () => kloudMeta,
572
573
  normaliseSQLiteUrl: () => normaliseSQLiteUrl,
573
574
  objectValues: () => objectValues,
@@ -5738,12 +5739,16 @@ var normaliseSQLiteUrl = (it, type) => {
5738
5739
  }
5739
5740
  assertUnreachable(type);
5740
5741
  };
5742
+ function isPgArrayType(sqlType) {
5743
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
5744
+ }
5741
5745
  // Annotate the CommonJS export names for ESM import in node:
5742
5746
  0 && (module.exports = {
5743
5747
  assertV1OutFolder,
5744
5748
  columnRenameKey,
5745
5749
  copy,
5746
5750
  dryJournal,
5751
+ isPgArrayType,
5747
5752
  kloudMeta,
5748
5753
  normaliseSQLiteUrl,
5749
5754
  objectValues,
package/utils.mjs CHANGED
@@ -5720,11 +5720,15 @@ var normaliseSQLiteUrl = (it, type) => {
5720
5720
  }
5721
5721
  assertUnreachable(type);
5722
5722
  };
5723
+ function isPgArrayType(sqlType) {
5724
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
5725
+ }
5723
5726
  export {
5724
5727
  assertV1OutFolder,
5725
5728
  columnRenameKey,
5726
5729
  copy,
5727
5730
  dryJournal,
5731
+ isPgArrayType,
5728
5732
  kloudMeta,
5729
5733
  normaliseSQLiteUrl,
5730
5734
  objectValues,