drizzle-kit 0.23.2 → 0.24.0-5df8253

Sign up to get free protection for your applications and to get access to all the features.
package/api.mjs CHANGED
@@ -7469,11 +7469,30 @@ var init_mysqlSchema = __esm({
7469
7469
  }
7470
7470
  });
7471
7471
 
7472
+ // src/extensions/vector.ts
7473
+ var vectorOps;
7474
+ var init_vector = __esm({
7475
+ "src/extensions/vector.ts"() {
7476
+ "use strict";
7477
+ vectorOps = [
7478
+ "vector_l2_ops",
7479
+ "vector_ip_ops",
7480
+ "vector_cosine_ops",
7481
+ "vector_l1_ops",
7482
+ "bit_hamming_ops",
7483
+ "bit_jaccard_ops",
7484
+ "halfvec_l2_ops",
7485
+ "sparsevec_l2_ops"
7486
+ ];
7487
+ }
7488
+ });
7489
+
7472
7490
  // src/serializer/pgSchema.ts
7473
7491
  var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, sequenceSchema, sequenceSquashed, columnV7, column2, columnSquashed, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV5, tableV6, tableV7, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternalV7, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchemaV7, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
7474
7492
  var init_pgSchema = __esm({
7475
7493
  "src/serializer/pgSchema.ts"() {
7476
7494
  "use strict";
7495
+ init_vector();
7477
7496
  init_global();
7478
7497
  init_lib();
7479
7498
  indexV2 = objectType({
@@ -7720,7 +7739,8 @@ var init_pgSchema = __esm({
7720
7739
  objectType({
7721
7740
  isArray: booleanType().optional(),
7722
7741
  dimensions: numberType().optional(),
7723
- rawType: stringType().optional()
7742
+ rawType: stringType().optional(),
7743
+ isDefaultAnExpression: booleanType().optional()
7724
7744
  }).optional()
7725
7745
  )
7726
7746
  }).optional()
@@ -7858,7 +7878,7 @@ var init_pgSchema = __esm({
7858
7878
  squashIdx: (idx) => {
7859
7879
  index2.parse(idx);
7860
7880
  return `${idx.name};${idx.columns.map(
7861
- (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
7881
+ (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
7862
7882
  ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
7863
7883
  },
7864
7884
  unsquashIdx: (input) => {
@@ -8343,6 +8363,9 @@ var init_sqliteSchema = __esm({
8343
8363
  });
8344
8364
 
8345
8365
  // src/utils.ts
8366
+ function isPgArrayType(sqlType) {
8367
+ return sqlType.match(/.*\[\d*\].*|.*\[\].*/g) !== null;
8368
+ }
8346
8369
  var copy, prepareMigrationMeta, schemaRenameKey, tableRenameKey, columnRenameKey;
8347
8370
  var init_utils = __esm({
8348
8371
  "src/utils.ts"() {
@@ -8716,14 +8739,14 @@ var require_heap = __commonJS({
8716
8739
  return item;
8717
8740
  };
8718
8741
  heapify = function(array, cmp) {
8719
- var i, _i2, _j, _len, _ref, _ref1, _results, _results1;
8742
+ var i, _i2, _j2, _len, _ref, _ref1, _results, _results1;
8720
8743
  if (cmp == null) {
8721
8744
  cmp = defaultCmp;
8722
8745
  }
8723
8746
  _ref1 = function() {
8724
8747
  _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);
8748
+ for (var _j3 = 0, _ref2 = floor(array.length / 2); 0 <= _ref2 ? _j3 < _ref2 : _j3 > _ref2; 0 <= _ref2 ? _j3++ : _j3--) {
8749
+ _results1.push(_j3);
8727
8750
  }
8728
8751
  return _results1;
8729
8752
  }.apply(this).reverse();
@@ -8764,7 +8787,7 @@ var require_heap = __commonJS({
8764
8787
  return result.sort(cmp).reverse();
8765
8788
  };
8766
8789
  nsmallest = function(array, n, cmp) {
8767
- var elem, i, los, result, _i2, _j, _len, _ref, _ref1, _results;
8790
+ var elem, i, los, result, _i2, _j2, _len, _ref, _ref1, _results;
8768
8791
  if (cmp == null) {
8769
8792
  cmp = defaultCmp;
8770
8793
  }
@@ -8787,7 +8810,7 @@ var require_heap = __commonJS({
8787
8810
  }
8788
8811
  heapify(array, cmp);
8789
8812
  _results = [];
8790
- for (i = _j = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
8813
+ for (i = _j2 = 0, _ref1 = min2(n, array.length); 0 <= _ref1 ? _j2 < _ref1 : _j2 > _ref1; i = 0 <= _ref1 ? ++_j2 : --_j2) {
8791
8814
  _results.push(heappop(array, cmp));
8792
8815
  }
8793
8816
  return _results;
@@ -11504,7 +11527,7 @@ var init_sqlgenerator = __esm({
11504
11527
  isPgNativeType = (it) => {
11505
11528
  if (pgNativeTypes.has(it)) return true;
11506
11529
  const toCheck = it.replace(/ /g, "");
11507
- return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
11530
+ return toCheck.startsWith("varchar(") || toCheck.startsWith("char(") || toCheck.startsWith("numeric(") || toCheck.startsWith("timestamp(") || toCheck.startsWith("doubleprecision[") || toCheck.startsWith("intervalyear(") || toCheck.startsWith("intervalmonth(") || toCheck.startsWith("intervalday(") || toCheck.startsWith("intervalhour(") || toCheck.startsWith("intervalminute(") || toCheck.startsWith("intervalsecond(") || toCheck.startsWith("intervalyeartomonth(") || toCheck.startsWith("intervaldaytohour(") || toCheck.startsWith("intervaldaytominute(") || toCheck.startsWith("intervaldaytosecond(") || toCheck.startsWith("intervalhourtominute(") || toCheck.startsWith("intervalhourtosecond(") || toCheck.startsWith("intervalminutetosecond(") || toCheck.startsWith("vector(") || toCheck.startsWith("geometry(") || /^(\w+)(\[\d*])+$/.test(it);
11508
11531
  };
11509
11532
  Convertor = class {
11510
11533
  };
@@ -17482,7 +17505,7 @@ function getTableName(table4) {
17482
17505
  function getTableUniqueName(table4) {
17483
17506
  return `${table4[Schema] ?? "public"}.${table4[TableName]}`;
17484
17507
  }
17485
- var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, Table2;
17508
+ var TableName, Schema, Columns, ExtraConfigColumns, OriginalName, BaseName, IsAlias, ExtraConfigBuilder, IsDrizzleTable, _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, Table2;
17486
17509
  var init_table = __esm({
17487
17510
  "../drizzle-orm/dist/table.js"() {
17488
17511
  "use strict";
@@ -17496,32 +17519,34 @@ var init_table = __esm({
17496
17519
  IsAlias = Symbol.for("drizzle:IsAlias");
17497
17520
  ExtraConfigBuilder = Symbol.for("drizzle:ExtraConfigBuilder");
17498
17521
  IsDrizzleTable = Symbol.for("drizzle:IsDrizzleTable");
17499
- _i = entityKind, _h = TableName, _g = OriginalName, _f = Schema, _e = Columns, _d = ExtraConfigColumns, _c = BaseName, _b = IsAlias, _a3 = ExtraConfigBuilder;
17522
+ _j = entityKind, _i = TableName, _h = OriginalName, _g = Schema, _f = Columns, _e = ExtraConfigColumns, _d = BaseName, _c = IsAlias, _b = IsDrizzleTable, _a3 = ExtraConfigBuilder;
17500
17523
  Table2 = class {
17501
17524
  constructor(name2, schema4, baseName) {
17502
17525
  /**
17503
17526
  * @internal
17504
17527
  * Can be changed if the table is aliased.
17505
17528
  */
17506
- __publicField(this, _h);
17529
+ __publicField(this, _i);
17507
17530
  /**
17508
17531
  * @internal
17509
17532
  * Used to store the original name of the table, before any aliasing.
17510
17533
  */
17534
+ __publicField(this, _h);
17535
+ /** @internal */
17511
17536
  __publicField(this, _g);
17512
17537
  /** @internal */
17513
17538
  __publicField(this, _f);
17514
17539
  /** @internal */
17515
17540
  __publicField(this, _e);
17516
- /** @internal */
17517
- __publicField(this, _d);
17518
17541
  /**
17519
17542
  * @internal
17520
17543
  * Used to store the table name before the transformation via the `tableCreator` functions.
17521
17544
  */
17522
- __publicField(this, _c);
17545
+ __publicField(this, _d);
17546
+ /** @internal */
17547
+ __publicField(this, _c, false);
17523
17548
  /** @internal */
17524
- __publicField(this, _b, false);
17549
+ __publicField(this, _b, true);
17525
17550
  /** @internal */
17526
17551
  __publicField(this, _a3);
17527
17552
  this[TableName] = this[OriginalName] = name2;
@@ -17529,7 +17554,7 @@ var init_table = __esm({
17529
17554
  this[BaseName] = baseName;
17530
17555
  }
17531
17556
  };
17532
- __publicField(Table2, _i, "Table");
17557
+ __publicField(Table2, _j, "Table");
17533
17558
  /** @internal */
17534
17559
  __publicField(Table2, "Symbol", {
17535
17560
  Name: TableName,
@@ -18105,7 +18130,7 @@ var version;
18105
18130
  var init_version = __esm({
18106
18131
  "../drizzle-orm/dist/version.js"() {
18107
18132
  "use strict";
18108
- version = "0.32.2";
18133
+ version = "0.33.0";
18109
18134
  }
18110
18135
  });
18111
18136
 
@@ -18207,6 +18232,12 @@ function fillPlaceholders(params, values) {
18207
18232
  }
18208
18233
  return values[p.name];
18209
18234
  }
18235
+ if (is(p, Param) && is(p.value, Placeholder)) {
18236
+ if (!(p.value.name in values)) {
18237
+ throw new Error(`No value for placeholder "${p.value.name}" was provided`);
18238
+ }
18239
+ return p.encoder.mapToDriverValue(values[p.value.name]);
18240
+ }
18210
18241
  return p;
18211
18242
  });
18212
18243
  }
@@ -18320,6 +18351,9 @@ var init_sql = __esm({
18320
18351
  };
18321
18352
  }
18322
18353
  if (is(chunk, Param)) {
18354
+ if (is(chunk.value, Placeholder)) {
18355
+ return { sql: escapeParam(paramStartIndex.value++, chunk), params: [chunk], typings: ["none"] };
18356
+ }
18323
18357
  const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
18324
18358
  if (is(mappedValue, _SQL)) {
18325
18359
  return this.buildQueryFromSourceParams([mappedValue], config);
@@ -19364,7 +19398,7 @@ function jaccardDistance(column4, value) {
19364
19398
  }
19365
19399
  return sql`${column4} <%> ${value}`;
19366
19400
  }
19367
- var init_vector = __esm({
19401
+ var init_vector2 = __esm({
19368
19402
  "../drizzle-orm/dist/sql/functions/vector.js"() {
19369
19403
  "use strict";
19370
19404
  init_sql();
@@ -19376,7 +19410,7 @@ var init_functions = __esm({
19376
19410
  "../drizzle-orm/dist/sql/functions/index.js"() {
19377
19411
  "use strict";
19378
19412
  init_aggregate();
19379
- init_vector();
19413
+ init_vector2();
19380
19414
  }
19381
19415
  });
19382
19416
 
@@ -21040,7 +21074,7 @@ var init_sparsevec = __esm({
21040
21074
 
21041
21075
  // ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
21042
21076
  var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
21043
- var init_vector2 = __esm({
21077
+ var init_vector3 = __esm({
21044
21078
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
21045
21079
  "use strict";
21046
21080
  init_entity();
@@ -21112,7 +21146,7 @@ var init_columns = __esm({
21112
21146
  init_bit();
21113
21147
  init_halfvec();
21114
21148
  init_sparsevec();
21115
- init_vector2();
21149
+ init_vector3();
21116
21150
  }
21117
21151
  });
21118
21152
 
@@ -24610,24 +24644,6 @@ var init_pg_core = __esm({
24610
24644
  }
24611
24645
  });
24612
24646
 
24613
- // src/extensions/vector.ts
24614
- var vectorOps;
24615
- var init_vector3 = __esm({
24616
- "src/extensions/vector.ts"() {
24617
- "use strict";
24618
- vectorOps = [
24619
- "vector_l2_ops",
24620
- "vector_ip_ops",
24621
- "vector_cosine_ops",
24622
- "vector_l1_ops",
24623
- "bit_hamming_ops",
24624
- "bit_jaccard_ops",
24625
- "halfvec_l2_ops",
24626
- "sparsevec_l2_ops"
24627
- ];
24628
- }
24629
- });
24630
-
24631
24647
  // src/serializer/pgSerializer.ts
24632
24648
  function stringFromIdentityProperty(field) {
24633
24649
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
@@ -24641,7 +24657,31 @@ function minRangeForIdentityBasedOn(columnType) {
24641
24657
  function stringFromDatabaseIdentityProperty(field) {
24642
24658
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : typeof field === "bigint" ? field.toString() : String(field);
24643
24659
  }
24644
- var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24660
+ function buildArrayString(array, sqlType) {
24661
+ sqlType = sqlType.split("[")[0];
24662
+ const values = array.map((value) => {
24663
+ if (typeof value === "number" || typeof value === "bigint") {
24664
+ return value.toString();
24665
+ } else if (typeof value === "boolean") {
24666
+ return value ? "true" : "false";
24667
+ } else if (Array.isArray(value)) {
24668
+ return buildArrayString(value, sqlType);
24669
+ } else if (value instanceof Date) {
24670
+ if (sqlType === "date") {
24671
+ return `"${value.toISOString().split("T")[0]}"`;
24672
+ } else if (sqlType === "timestamp") {
24673
+ return `"${value.toISOString().replace("T", " ").slice(0, 23)}"`;
24674
+ } else {
24675
+ return `"${value.toISOString()}"`;
24676
+ }
24677
+ } else if (typeof value === "object") {
24678
+ return `"${JSON.stringify(value).replaceAll('"', '\\"')}"`;
24679
+ }
24680
+ return `"${value}"`;
24681
+ }).join(",");
24682
+ return `{${values}}`;
24683
+ }
24684
+ var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
24645
24685
  var init_pgSerializer = __esm({
24646
24686
  "src/serializer/pgSerializer.ts"() {
24647
24687
  "use strict";
@@ -24649,8 +24689,9 @@ var init_pgSerializer = __esm({
24649
24689
  init_dist();
24650
24690
  init_pg_core();
24651
24691
  init_pg_core();
24652
- init_vector3();
24692
+ init_vector();
24653
24693
  init_outputs();
24694
+ init_utils();
24654
24695
  init_serializer();
24655
24696
  dialect4 = new PgDialect();
24656
24697
  indexName = (tableName, columns) => {
@@ -24757,6 +24798,11 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
24757
24798
  } else {
24758
24799
  columnToSet.default = `'${column4.default.toISOString()}'`;
24759
24800
  }
24801
+ } else if (isPgArrayType(sqlTypeLowered) && Array.isArray(column4.default)) {
24802
+ columnToSet.default = `'${buildArrayString(
24803
+ column4.default,
24804
+ sqlTypeLowered
24805
+ )}'`;
24760
24806
  } else {
24761
24807
  columnToSet.default = column4.default;
24762
24808
  }
@@ -25103,7 +25149,7 @@ ${withStyle.errorWarning(
25103
25149
  WHEN 'int2'::regtype THEN 'smallserial'
25104
25150
  END
25105
25151
  ELSE format_type(a.atttypid, a.atttypmod)
25106
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
25152
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
25107
25153
  pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
25108
25154
  INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
25109
25155
  INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
@@ -25114,6 +25160,7 @@ ${withStyle.errorWarning(
25114
25160
  INFORMATION_SCHEMA.COLUMNS.identity_cycle
25115
25161
  FROM pg_attribute a
25116
25162
  JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
25163
+ JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
25117
25164
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
25118
25165
  AND a.attnum > 0
25119
25166
  AND NOT a.attisdropped
@@ -25133,30 +25180,42 @@ ${withStyle.errorWarning(
25133
25180
  }
25134
25181
  const tableForeignKeys = await db.query(
25135
25182
  `SELECT
25136
- tc.table_schema,
25137
- tc.constraint_name,
25138
- tc.table_name,
25139
- kcu.column_name,
25140
- (
25141
- SELECT ccu.table_schema
25142
- FROM information_schema.constraint_column_usage ccu
25143
- WHERE ccu.constraint_name = tc.constraint_name
25144
- LIMIT 1
25145
- ) AS foreign_table_schema,
25146
- ccu.table_name AS foreign_table_name,
25147
- ccu.column_name AS foreign_column_name,
25148
- rc.delete_rule,
25149
- rc.update_rule
25150
- FROM
25151
- information_schema.table_constraints AS tc
25152
- JOIN information_schema.key_column_usage AS kcu
25153
- ON tc.constraint_name = kcu.constraint_name
25154
- AND tc.table_schema = kcu.table_schema
25155
- JOIN information_schema.constraint_column_usage AS ccu
25156
- ON ccu.constraint_name = tc.constraint_name
25157
- JOIN information_schema.referential_constraints AS rc
25158
- ON ccu.constraint_name = rc.constraint_name
25159
- WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
25183
+ con.contype AS constraint_type,
25184
+ nsp.nspname AS constraint_schema,
25185
+ con.conname AS constraint_name,
25186
+ rel.relname AS table_name,
25187
+ att.attname AS column_name,
25188
+ fnsp.nspname AS foreign_table_schema,
25189
+ frel.relname AS foreign_table_name,
25190
+ fatt.attname AS foreign_column_name,
25191
+ CASE con.confupdtype
25192
+ WHEN 'a' THEN 'NO ACTION'
25193
+ WHEN 'r' THEN 'RESTRICT'
25194
+ WHEN 'n' THEN 'SET NULL'
25195
+ WHEN 'c' THEN 'CASCADE'
25196
+ WHEN 'd' THEN 'SET DEFAULT'
25197
+ END AS update_rule,
25198
+ CASE con.confdeltype
25199
+ WHEN 'a' THEN 'NO ACTION'
25200
+ WHEN 'r' THEN 'RESTRICT'
25201
+ WHEN 'n' THEN 'SET NULL'
25202
+ WHEN 'c' THEN 'CASCADE'
25203
+ WHEN 'd' THEN 'SET DEFAULT'
25204
+ END AS delete_rule
25205
+ FROM
25206
+ pg_catalog.pg_constraint con
25207
+ JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
25208
+ JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
25209
+ LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
25210
+ AND att.attrelid = con.conrelid
25211
+ LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
25212
+ LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
25213
+ LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
25214
+ AND fatt.attrelid = con.confrelid
25215
+ WHERE
25216
+ nsp.nspname = '${tableSchema}'
25217
+ AND rel.relname = '${tableName}'
25218
+ AND con.contype IN ('f');`
25160
25219
  );
25161
25220
  foreignKeysCount += tableForeignKeys.length;
25162
25221
  if (progressCallback) {
@@ -25214,6 +25273,8 @@ ${withStyle.errorWarning(
25214
25273
  const columnDimensions = columnResponse.array_dimensions;
25215
25274
  const enumType2 = columnResponse.enum_name;
25216
25275
  let columnType = columnResponse.data_type;
25276
+ const typeSchema = columnResponse.type_schema;
25277
+ const defaultValueRes = columnResponse.column_default;
25217
25278
  const isGenerated = columnResponse.is_generated === "ALWAYS";
25218
25279
  const generationExpression = columnResponse.generation_expression;
25219
25280
  const isIdentity = columnResponse.is_identity === "YES";
@@ -25244,12 +25305,7 @@ ${withStyle.errorWarning(
25244
25305
  columns: cprimaryKey.map((c) => c.column_name)
25245
25306
  };
25246
25307
  }
25247
- const defaultValue = defaultForColumn(columnResponse);
25248
- const isSerial = columnType === "serial";
25249
25308
  let columnTypeMapped = columnType;
25250
- if (columnTypeMapped.startsWith("numeric(")) {
25251
- columnTypeMapped = columnTypeMapped.replace(",", ", ");
25252
- }
25253
25309
  if (columnAdditionalDT === "ARRAY") {
25254
25310
  if (typeof internals.tables[tableName] === "undefined") {
25255
25311
  internals.tables[tableName] = {
@@ -25277,6 +25333,34 @@ ${withStyle.errorWarning(
25277
25333
  }
25278
25334
  }
25279
25335
  }
25336
+ const defaultValue = defaultForColumn(
25337
+ columnResponse,
25338
+ internals,
25339
+ tableName
25340
+ );
25341
+ if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
25342
+ if (typeof internals.tables[tableName] === "undefined") {
25343
+ internals.tables[tableName] = {
25344
+ columns: {
25345
+ [columnName]: {
25346
+ isDefaultAnExpression: true
25347
+ }
25348
+ }
25349
+ };
25350
+ } else {
25351
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25352
+ internals.tables[tableName].columns[columnName] = {
25353
+ isDefaultAnExpression: true
25354
+ };
25355
+ } else {
25356
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25357
+ }
25358
+ }
25359
+ }
25360
+ const isSerial = columnType === "serial";
25361
+ if (columnTypeMapped.startsWith("numeric(")) {
25362
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
25363
+ }
25280
25364
  if (columnAdditionalDT === "ARRAY") {
25281
25365
  for (let i = 1; i < Number(columnDimensions); i++) {
25282
25366
  columnTypeMapped += "[]";
@@ -25290,7 +25374,7 @@ ${withStyle.errorWarning(
25290
25374
  // filter vectors, but in future we should filter any extension that was installed by user
25291
25375
  columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
25292
25376
  ),
25293
- typeSchema: enumsToReturn[`${tableSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${tableSchema}.${enumType2}`].schema : void 0,
25377
+ typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
25294
25378
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
25295
25379
  // default: isSerial ? undefined : defaultValue,
25296
25380
  notNull: columnResponse.is_nullable === "NO",
@@ -25461,59 +25545,71 @@ ${withStyle.errorWarning(
25461
25545
  internal: internals
25462
25546
  };
25463
25547
  };
25464
- columnToDefault = {
25465
- "numeric(": "::numeric",
25466
- // text: "::text",
25467
- // "character varying": "::character varying",
25468
- // "double precision": "::double precision",
25469
- // "time with time zone": "::time with time zone",
25470
- "time without time zone": "::time without time zone",
25471
- // "timestamp with time zone": "::timestamp with time zone",
25472
- "timestamp without time zone": "::timestamp without time zone",
25473
- "timestamp(": "::timestamp without time zone",
25474
- // date: "::date",
25475
- // interval: "::interval",
25476
- // character: "::bpchar",
25477
- // macaddr8: "::macaddr8",
25478
- // macaddr: "::macaddr",
25479
- // inet: "::inet",
25480
- // cidr: "::cidr",
25481
- // jsonb: "::jsonb",
25482
- // json: "::json",
25483
- "character(": "::bpchar"
25484
- };
25485
- defaultForColumn = (column4) => {
25548
+ defaultForColumn = (column4, internals, tableName) => {
25549
+ const columnName = column4.attname;
25550
+ const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
25486
25551
  if (column4.column_default === null) {
25487
25552
  return void 0;
25488
25553
  }
25489
25554
  if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
25490
25555
  return void 0;
25491
25556
  }
25492
- const hasDifferentDefaultCast = Object.keys(columnToDefault).find((it) => column4.data_type.startsWith(it));
25557
+ if (column4.column_default.endsWith("[]")) {
25558
+ column4.column_default = column4.column_default.slice(0, -2);
25559
+ }
25560
+ column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
25493
25561
  const columnDefaultAsString = column4.column_default.toString();
25494
- if (columnDefaultAsString.endsWith(
25495
- hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
25496
- )) {
25497
- const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
25498
- const rt = column4.column_default.toString().substring(1, nonPrefixPart);
25499
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
25500
- return Number(rt);
25501
- } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25502
- const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
25503
- return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
25504
- } else if (column4.data_type === "boolean") {
25505
- return column4.column_default === "true";
25506
- } else {
25507
- return `'${rt}'`;
25508
- }
25509
- } else {
25510
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column4.data_type.startsWith("numeric")) {
25562
+ if (isArray) {
25563
+ return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
25564
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
25565
+ return value;
25566
+ } else if (column4.data_type.startsWith("timestamp")) {
25567
+ return `${value}`;
25568
+ } else if (column4.data_type.slice(0, -2) === "interval") {
25569
+ return value.replaceAll('"', `"`);
25570
+ } else if (column4.data_type.slice(0, -2) === "boolean") {
25571
+ return value === "t" ? "true" : "false";
25572
+ } else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
25573
+ return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
25574
+ } else {
25575
+ return `"${value}"`;
25576
+ }
25577
+ }).join(",")}}'`;
25578
+ }
25579
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
25580
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
25511
25581
  return Number(columnDefaultAsString);
25512
- } else if (column4.data_type === "boolean") {
25513
- return column4.column_default === "true";
25514
25582
  } else {
25515
- return `${columnDefaultAsString}`;
25583
+ if (typeof internals.tables[tableName] === "undefined") {
25584
+ internals.tables[tableName] = {
25585
+ columns: {
25586
+ [columnName]: {
25587
+ isDefaultAnExpression: true
25588
+ }
25589
+ }
25590
+ };
25591
+ } else {
25592
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25593
+ internals.tables[tableName].columns[columnName] = {
25594
+ isDefaultAnExpression: true
25595
+ };
25596
+ } else {
25597
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25598
+ }
25599
+ }
25600
+ return columnDefaultAsString;
25516
25601
  }
25602
+ } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25603
+ const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
25604
+ return `'${jsonWithoutSpaces}'::${column4.data_type}`;
25605
+ } else if (column4.data_type === "boolean") {
25606
+ return column4.column_default === "true";
25607
+ } else if (columnDefaultAsString === "NULL") {
25608
+ return `NULL`;
25609
+ } else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
25610
+ return columnDefaultAsString;
25611
+ } else {
25612
+ return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
25517
25613
  }
25518
25614
  };
25519
25615
  }
@@ -29036,7 +29132,7 @@ The unique constraint ${source_default.underline.blue(
29036
29132
  primaryKeys.forEach((it) => {
29037
29133
  if (it.columns.length > 1) {
29038
29134
  primaryKeysObject[it.getName()] = {
29039
- columns: it.columns.map((it2) => it2.name).sort(),
29135
+ columns: it.columns.map((it2) => it2.name),
29040
29136
  name: it.getName()
29041
29137
  };
29042
29138
  } else {
@@ -29161,7 +29257,6 @@ The unique constraint ${source_default.underline.blue(
29161
29257
  }
29162
29258
  for (const [key, value] of Object.entries(tableToPk)) {
29163
29259
  if (value.length > 1) {
29164
- value.sort();
29165
29260
  result[key].compositePrimaryKeys = {
29166
29261
  [`${key}_${value.join("_")}_pk`]: {
29167
29262
  columns: value,
@@ -33605,7 +33700,7 @@ We have encountered a collision between the index name on columns ${source_defau
33605
33700
  onUpdate = true;
33606
33701
  }
33607
33702
  const newColumn = {
33608
- default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) && !columnType.startsWith("decimal") ? Number(columnDefault) : isDefaultAnExpression ? clearDefaults(columnDefault, collation) : `'${columnDefault}'`,
33703
+ 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
33704
  autoincrement: isAutoincrement,
33610
33705
  name: columnName,
33611
33706
  type: changedType,
@@ -33844,7 +33939,7 @@ var init_cli = __esm({
33844
33939
  extensionsFilters: literalType("postgis").array().optional(),
33845
33940
  introspectCasing: casing,
33846
33941
  breakpoints: booleanType().optional().default(true),
33847
- database: objectType({
33942
+ migrations: objectType({
33848
33943
  prefix: prefix.optional().default("index")
33849
33944
  }).optional()
33850
33945
  }).passthrough();
@@ -34808,6 +34903,37 @@ var updateUpToV6 = (json) => {
34808
34903
  enums
34809
34904
  };
34810
34905
  };
34906
+ var updateUpToV7 = (json) => {
34907
+ const schema4 = pgSchemaV6.parse(json);
34908
+ const tables = Object.fromEntries(
34909
+ Object.entries(schema4.tables).map((it) => {
34910
+ const table4 = it[1];
34911
+ const mappedIndexes = Object.fromEntries(
34912
+ Object.entries(table4.indexes).map((idx) => {
34913
+ const { columns, ...rest } = idx[1];
34914
+ const mappedColumns = columns.map((it2) => {
34915
+ return {
34916
+ expression: it2,
34917
+ isExpression: false,
34918
+ asc: true,
34919
+ nulls: "last",
34920
+ opClass: void 0
34921
+ };
34922
+ });
34923
+ return [idx[0], { columns: mappedColumns, with: {}, ...rest }];
34924
+ })
34925
+ );
34926
+ return [it[0], { ...table4, indexes: mappedIndexes }];
34927
+ })
34928
+ );
34929
+ return {
34930
+ ...schema4,
34931
+ version: "7",
34932
+ dialect: "postgresql",
34933
+ sequences: {},
34934
+ tables
34935
+ };
34936
+ };
34811
34937
 
34812
34938
  // src/cli/commands/sqliteIntrospect.ts
34813
34939
  var import_hanji6 = __toESM(require_hanji());
@@ -35464,7 +35590,13 @@ var pushMySQLSchema = async (imports, drizzleInstance, databaseName) => {
35464
35590
  };
35465
35591
  };
35466
35592
  var upPgSnapshot = (snapshot) => {
35467
- return updateUpToV6(snapshot);
35593
+ if (snapshot.version === "5") {
35594
+ return updateUpToV7(updateUpToV6(snapshot));
35595
+ }
35596
+ if (snapshot.version === "6") {
35597
+ return updateUpToV7(snapshot);
35598
+ }
35599
+ return snapshot;
35468
35600
  };
35469
35601
  export {
35470
35602
  generateDrizzleJson,