drizzle-kit 0.21.4 → 0.22.0-ed86dfa

Sign up to get free protection for your applications and to get access to all the features.
package/bin.cjs CHANGED
@@ -1456,7 +1456,7 @@ var init_global = __esm({
1456
1456
  "src/global.ts"() {
1457
1457
  "use strict";
1458
1458
  originUUID = "00000000-0000-0000-0000-000000000000";
1459
- snapshotVersion = "6";
1459
+ snapshotVersion = "7";
1460
1460
  mapValues = (obj, map) => {
1461
1461
  const result = Object.keys(obj).reduce(function(result2, key) {
1462
1462
  result2[key] = map(obj[key]);
@@ -5658,7 +5658,7 @@ var init_mysqlSchema = __esm({
5658
5658
  });
5659
5659
 
5660
5660
  // src/serializer/pgSchema.ts
5661
- var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaExternal, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
5661
+ var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, indexColumn, index2, indexV4, indexV5, indexV6, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, tableV6, tableV5, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaInternalV6, pgSchemaExternal, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashedV6, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchemaV6, pgSchema, backwardCompatiblePgSchema, PgSquasher, squashPgScheme, dryPg;
5662
5662
  var init_pgSchema = __esm({
5663
5663
  "src/serializer/pgSchema.ts"() {
5664
5664
  "use strict";
@@ -5726,10 +5726,48 @@ var init_pgSchema = __esm({
5726
5726
  tables: recordType(stringType(), tableV1),
5727
5727
  enums: recordType(stringType(), enumSchemaV1)
5728
5728
  }).strict();
5729
+ indexColumn = objectType({
5730
+ expression: stringType(),
5731
+ isExpression: booleanType(),
5732
+ asc: booleanType(),
5733
+ nulls: stringType().optional(),
5734
+ opclass: stringType().optional()
5735
+ });
5729
5736
  index2 = objectType({
5737
+ name: stringType(),
5738
+ columns: indexColumn.array(),
5739
+ isUnique: booleanType(),
5740
+ with: recordType(stringType(), anyType()).optional(),
5741
+ method: stringType().default("btree"),
5742
+ where: stringType().optional(),
5743
+ concurrently: booleanType().default(false)
5744
+ }).strict();
5745
+ indexV4 = objectType({
5730
5746
  name: stringType(),
5731
5747
  columns: stringType().array(),
5732
- isUnique: booleanType()
5748
+ isUnique: booleanType(),
5749
+ with: recordType(stringType(), stringType()).optional(),
5750
+ method: stringType().default("btree"),
5751
+ where: stringType().optional(),
5752
+ concurrently: booleanType().default(false)
5753
+ }).strict();
5754
+ indexV5 = objectType({
5755
+ name: stringType(),
5756
+ columns: stringType().array(),
5757
+ isUnique: booleanType(),
5758
+ with: recordType(stringType(), stringType()).optional(),
5759
+ method: stringType().default("btree"),
5760
+ where: stringType().optional(),
5761
+ concurrently: booleanType().default(false)
5762
+ }).strict();
5763
+ indexV6 = objectType({
5764
+ name: stringType(),
5765
+ columns: stringType().array(),
5766
+ isUnique: booleanType(),
5767
+ with: recordType(stringType(), stringType()).optional(),
5768
+ method: stringType().default("btree"),
5769
+ where: stringType().optional(),
5770
+ concurrently: booleanType().default(false)
5733
5771
  }).strict();
5734
5772
  fk2 = objectType({
5735
5773
  name: stringType(),
@@ -5771,9 +5809,27 @@ var init_pgSchema = __esm({
5771
5809
  name: stringType(),
5772
5810
  schema: stringType(),
5773
5811
  columns: recordType(stringType(), column2),
5774
- indexes: recordType(stringType(), index2),
5812
+ indexes: recordType(stringType(), indexV4),
5775
5813
  foreignKeys: recordType(stringType(), fk2)
5776
5814
  }).strict();
5815
+ tableV6 = objectType({
5816
+ name: stringType(),
5817
+ schema: stringType(),
5818
+ columns: recordType(stringType(), column2),
5819
+ indexes: recordType(stringType(), indexV6),
5820
+ foreignKeys: recordType(stringType(), fk2),
5821
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
5822
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
5823
+ }).strict();
5824
+ tableV5 = objectType({
5825
+ name: stringType(),
5826
+ schema: stringType(),
5827
+ columns: recordType(stringType(), column2),
5828
+ indexes: recordType(stringType(), indexV5),
5829
+ foreignKeys: recordType(stringType(), fk2),
5830
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
5831
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
5832
+ }).strict();
5777
5833
  table2 = objectType({
5778
5834
  name: stringType(),
5779
5835
  schema: stringType(),
@@ -5818,7 +5874,7 @@ var init_pgSchema = __esm({
5818
5874
  pgSchemaInternalV5 = objectType({
5819
5875
  version: literalType("5"),
5820
5876
  dialect: literalType("pg"),
5821
- tables: recordType(stringType(), table2),
5877
+ tables: recordType(stringType(), tableV5),
5822
5878
  enums: recordType(stringType(), enumSchemaV1),
5823
5879
  schemas: recordType(stringType(), stringType()),
5824
5880
  _meta: objectType({
@@ -5828,6 +5884,19 @@ var init_pgSchema = __esm({
5828
5884
  }),
5829
5885
  internal: kitInternals2
5830
5886
  }).strict();
5887
+ pgSchemaInternalV6 = objectType({
5888
+ version: literalType("6"),
5889
+ dialect: literalType("postgresql"),
5890
+ tables: recordType(stringType(), tableV6),
5891
+ enums: recordType(stringType(), enumSchema),
5892
+ schemas: recordType(stringType(), stringType()),
5893
+ _meta: objectType({
5894
+ schemas: recordType(stringType(), stringType()),
5895
+ tables: recordType(stringType(), stringType()),
5896
+ columns: recordType(stringType(), stringType())
5897
+ }),
5898
+ internal: kitInternals2
5899
+ }).strict();
5831
5900
  pgSchemaExternal = objectType({
5832
5901
  version: literalType("5"),
5833
5902
  dialect: literalType("pg"),
@@ -5841,7 +5910,7 @@ var init_pgSchema = __esm({
5841
5910
  })
5842
5911
  }).strict();
5843
5912
  pgSchemaInternal = objectType({
5844
- version: literalType("6"),
5913
+ version: literalType("7"),
5845
5914
  dialect: literalType("postgresql"),
5846
5915
  tables: recordType(stringType(), table2),
5847
5916
  enums: recordType(stringType(), enumSchema),
@@ -5876,29 +5945,94 @@ var init_pgSchema = __esm({
5876
5945
  enums: recordType(stringType(), enumSchemaV1),
5877
5946
  schemas: recordType(stringType(), stringType())
5878
5947
  }).strict();
5879
- pgSchemaSquashed = objectType({
5948
+ pgSchemaSquashedV6 = objectType({
5880
5949
  version: literalType("6"),
5881
5950
  dialect: literalType("postgresql"),
5882
5951
  tables: recordType(stringType(), tableSquashed2),
5883
5952
  enums: recordType(stringType(), enumSchema),
5884
5953
  schemas: recordType(stringType(), stringType())
5885
5954
  }).strict();
5955
+ pgSchemaSquashed = objectType({
5956
+ version: literalType("7"),
5957
+ dialect: literalType("postgresql"),
5958
+ tables: recordType(stringType(), tableSquashed2),
5959
+ enums: recordType(stringType(), enumSchema),
5960
+ schemas: recordType(stringType(), stringType())
5961
+ }).strict();
5886
5962
  pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
5887
5963
  pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
5888
5964
  pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
5965
+ pgSchemaV6 = pgSchemaInternalV6.merge(schemaHash2);
5889
5966
  pgSchema = pgSchemaInternal.merge(schemaHash2);
5890
- backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema]);
5967
+ backwardCompatiblePgSchema = unionType([
5968
+ pgSchemaV5,
5969
+ pgSchemaV6,
5970
+ pgSchema
5971
+ ]);
5891
5972
  PgSquasher = {
5892
5973
  squashIdx: (idx) => {
5893
5974
  index2.parse(idx);
5894
- return `${idx.name};${idx.columns.join(",")};${idx.isUnique}`;
5975
+ return `${idx.name};${idx.columns.map(
5976
+ (c) => `${c.expression},${c.isExpression},${c.asc},${c.nulls},${c.opclass}`
5977
+ ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
5895
5978
  },
5896
5979
  unsquashIdx: (input) => {
5897
- const [name, columnsString, isUnique] = input.split(";");
5980
+ const [
5981
+ name,
5982
+ columnsString,
5983
+ isUnique,
5984
+ concurrently,
5985
+ method,
5986
+ where,
5987
+ idxWith
5988
+ ] = input.split(";");
5989
+ const columnString = columnsString.split(",,");
5990
+ const columns = [];
5991
+ for (const column7 of columnString) {
5992
+ const [expression, isExpression, asc, nulls, opclass] = column7.split(",");
5993
+ columns.push({
5994
+ nulls,
5995
+ isExpression: isExpression === "true",
5996
+ asc: asc === "true",
5997
+ expression,
5998
+ opclass: opclass === "undefined" ? void 0 : opclass
5999
+ });
6000
+ }
5898
6001
  const result = index2.parse({
5899
6002
  name,
5900
- columns: columnsString.split(","),
5901
- isUnique: isUnique === "true"
6003
+ columns,
6004
+ isUnique: isUnique === "true",
6005
+ concurrently: concurrently === "true",
6006
+ method,
6007
+ where: where === "undefined" ? void 0 : where,
6008
+ with: !idxWith || idxWith === "undefined" ? void 0 : JSON.parse(idxWith)
6009
+ });
6010
+ return result;
6011
+ },
6012
+ squashIdxPush: (idx) => {
6013
+ index2.parse(idx);
6014
+ return `${idx.name};${idx.columns.map((c) => `${c.isExpression ? "" : c.expression},${c.asc},${c.nulls}`).join(",,")};${idx.isUnique};${idx.method};${JSON.stringify(idx.with)}`;
6015
+ },
6016
+ unsquashIdxPush: (input) => {
6017
+ const [name, columnsString, isUnique, method, idxWith] = input.split(";");
6018
+ const columnString = columnsString.split(",,");
6019
+ const columns = [];
6020
+ for (const column7 of columnString) {
6021
+ const [expression, asc, nulls, opclass] = column7.split(",");
6022
+ columns.push({
6023
+ nulls,
6024
+ isExpression: expression === "",
6025
+ asc: asc === "true",
6026
+ expression
6027
+ });
6028
+ }
6029
+ const result = index2.parse({
6030
+ name,
6031
+ columns,
6032
+ isUnique: isUnique === "true",
6033
+ concurrently: false,
6034
+ method,
6035
+ with: idxWith === "undefined" ? void 0 : JSON.parse(idxWith)
5902
6036
  });
5903
6037
  return result;
5904
6038
  },
@@ -5947,11 +6081,11 @@ var init_pgSchema = __esm({
5947
6081
  return result;
5948
6082
  }
5949
6083
  };
5950
- squashPgScheme = (json) => {
6084
+ squashPgScheme = (json, action) => {
5951
6085
  const mappedTables = Object.fromEntries(
5952
6086
  Object.entries(json.tables).map((it) => {
5953
6087
  const squashedIndexes = mapValues(it[1].indexes, (index4) => {
5954
- return PgSquasher.squashIdx(index4);
6088
+ return action === "push" ? PgSquasher.squashIdxPush(index4) : PgSquasher.squashIdx(index4);
5955
6089
  });
5956
6090
  const squashedFKs = mapValues(it[1].foreignKeys, (fk4) => {
5957
6091
  return PgSquasher.squashFK(fk4);
@@ -5980,7 +6114,7 @@ var init_pgSchema = __esm({
5980
6114
  })
5981
6115
  );
5982
6116
  return {
5983
- version: "6",
6117
+ version: "7",
5984
6118
  dialect: json.dialect,
5985
6119
  tables: mappedTables,
5986
6120
  enums: json.enums,
@@ -6278,7 +6412,7 @@ var init_utils = __esm({
6278
6412
  validatorForDialect = (dialect7) => {
6279
6413
  switch (dialect7) {
6280
6414
  case "postgresql":
6281
- return { validator: backwardCompatiblePgSchema, version: 6 };
6415
+ return { validator: backwardCompatiblePgSchema, version: 7 };
6282
6416
  case "sqlite":
6283
6417
  return { validator: backwardCompatibleSqliteSchema, version: 6 };
6284
6418
  case "mysql":
@@ -8265,7 +8399,7 @@ var init_utils2 = __esm({
8265
8399
  process.exit(1);
8266
8400
  }
8267
8401
  };
8268
- requiredApiVersion = 6;
8402
+ requiredApiVersion = 7;
8269
8403
  assertOrmCoreVersion = async () => {
8270
8404
  try {
8271
8405
  const { compatibilityVersion } = await import("drizzle-orm/version");
@@ -15525,6 +15659,24 @@ var init_pgImports = __esm({
15525
15659
  }
15526
15660
  });
15527
15661
 
15662
+ // src/extensions/vector.ts
15663
+ var vectorOps;
15664
+ var init_vector = __esm({
15665
+ "src/extensions/vector.ts"() {
15666
+ "use strict";
15667
+ vectorOps = [
15668
+ "vector_l2_ops",
15669
+ "vector_ip_ops",
15670
+ "vector_cosine_ops",
15671
+ "vector_l1_ops",
15672
+ "bit_hamming_ops",
15673
+ "bit_jaccard_ops",
15674
+ "halfvec_l2_ops",
15675
+ "sparsevec_l2_ops"
15676
+ ];
15677
+ }
15678
+ });
15679
+
15528
15680
  // src/serializer/pgSerializer.ts
15529
15681
  var pgSerializer_exports = {};
15530
15682
  __export(pgSerializer_exports, {
@@ -15542,6 +15694,7 @@ var init_pgSerializer = __esm({
15542
15694
  init_serializer();
15543
15695
  init_source();
15544
15696
  init_outputs();
15697
+ init_vector();
15545
15698
  dialect5 = new import_pg_core2.PgDialect();
15546
15699
  indexName2 = (tableName, columns) => {
15547
15700
  return `${tableName}_${columns.join("_")}_index`;
@@ -15549,6 +15702,16 @@ var init_pgSerializer = __esm({
15549
15702
  generatePgSnapshot = (tables, enums, schemas, schemaFilter) => {
15550
15703
  const result = {};
15551
15704
  const indexesInSchema = {};
15705
+ const enumsToReturn = enums.reduce((map, obj) => {
15706
+ const enumSchema3 = obj.schema || "public";
15707
+ const key = `${enumSchema3}.${obj.enumName}`;
15708
+ map[key] = {
15709
+ name: obj.enumName,
15710
+ schema: enumSchema3,
15711
+ values: obj.enumValues
15712
+ };
15713
+ return map;
15714
+ }, {});
15552
15715
  for (const table4 of tables) {
15553
15716
  const {
15554
15717
  name: tableName,
@@ -15579,6 +15742,7 @@ var init_pgSerializer = __esm({
15579
15742
  typeSchema,
15580
15743
  primaryKey,
15581
15744
  notNull
15745
+ // isenum: typeof enumsToReturn[column.getSQLType()] !== "undefined",
15582
15746
  };
15583
15747
  if (column7.isUnique) {
15584
15748
  const existingUnique = uniqueConstraintObject[column7.uniqueName];
@@ -15692,18 +15856,71 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
15692
15856
  });
15693
15857
  indexes.forEach((value) => {
15694
15858
  const columns2 = value.config.columns;
15695
- let name = value.config.name;
15696
- name = name ? name : indexName2(
15697
- tableName,
15698
- columns2.map((it) => it.name)
15699
- );
15700
- let indexColumns = columns2.map((it) => {
15859
+ let indexColumnNames = [];
15860
+ columns2.forEach((it) => {
15701
15861
  if ((0, import_drizzle_orm5.is)(it, import_drizzle_orm5.SQL)) {
15702
- return dialect5.sqlToQuery(it).sql;
15703
- } else {
15704
- return it.name;
15862
+ if (typeof value.config.name === "undefined") {
15863
+ console.log(
15864
+ `
15865
+ ${withStyle.errorWarning(
15866
+ `Please specify an index name in ${(0, import_drizzle_orm5.getTableName)(
15867
+ value.config.table
15868
+ )} table that has "${dialect5.sqlToQuery(it).sql}" expression. We can generate index names for indexes on columns only; for expressions in indexes, you need to specify the name yourself.`
15869
+ )}`
15870
+ );
15871
+ process.exit(1);
15872
+ }
15873
+ }
15874
+ it = it;
15875
+ if (!(0, import_drizzle_orm5.is)(it, import_drizzle_orm5.SQL) && it.type === "PgVector" && typeof it.indexConfig.opClass === "undefined") {
15876
+ console.log(
15877
+ `
15878
+ ${withStyle.errorWarning(
15879
+ `You are specifying an index on the ${source_default.blueBright(
15880
+ it.name
15881
+ )} column inside the ${source_default.blueBright(
15882
+ tableName
15883
+ )} table with the ${source_default.blueBright(
15884
+ "vector"
15885
+ )} type without specifying an operator class. Vector extension doesn't have a default operator class, so you need to specify one of the available options. Here is a list of available op classes for the vector extension: [${vectorOps.map((it2) => `${source_default.underline(`${it2}`)}`).join(
15886
+ ", "
15887
+ )}].
15888
+
15889
+ You can specify it using current syntax: ${source_default.underline(
15890
+ `index("${value.config.name}").using("${value.config.method}", table.${it.name}.op("${vectorOps[0]}"))`
15891
+ )}
15892
+
15893
+ You can check the "pg_vector" docs for more info: https://github.com/pgvector/pgvector?tab=readme-ov-file#indexing
15894
+ `
15895
+ )}`
15896
+ );
15897
+ process.exit(1);
15705
15898
  }
15899
+ indexColumnNames.push(it.name);
15706
15900
  });
15901
+ const name = value.config.name ? value.config.name : indexName2(tableName, indexColumnNames);
15902
+ let indexColumns = columns2.map(
15903
+ (it) => {
15904
+ var _a, _b, _c, _d, _e2;
15905
+ if ((0, import_drizzle_orm5.is)(it, import_drizzle_orm5.SQL)) {
15906
+ return {
15907
+ expression: dialect5.sqlToQuery(it, "indexes").sql,
15908
+ asc: true,
15909
+ isExpression: true,
15910
+ nulls: "last"
15911
+ };
15912
+ } else {
15913
+ it = it;
15914
+ return {
15915
+ expression: it.name,
15916
+ isExpression: false,
15917
+ asc: ((_a = it.indexConfig) == null ? void 0 : _a.order) === "asc",
15918
+ nulls: ((_b = it.indexConfig) == null ? void 0 : _b.nulls) ? (_c = it.indexConfig) == null ? void 0 : _c.nulls : ((_d = it.indexConfig) == null ? void 0 : _d.order) === "desc" ? "first" : "last",
15919
+ opclass: (_e2 = it.indexConfig) == null ? void 0 : _e2.opClass
15920
+ };
15921
+ }
15922
+ }
15923
+ );
15707
15924
  if (typeof indexesInSchema[schema5 ?? "public"] !== "undefined") {
15708
15925
  if (indexesInSchema[schema5 ?? "public"].includes(name)) {
15709
15926
  console.log(
@@ -15725,7 +15942,11 @@ ${withStyle.errorWarning(
15725
15942
  indexesObject[name] = {
15726
15943
  name,
15727
15944
  columns: indexColumns,
15728
- isUnique: value.config.unique ?? false
15945
+ isUnique: value.config.unique ?? false,
15946
+ where: value.config.where ? dialect5.sqlToQuery(value.config.where).sql : void 0,
15947
+ concurrently: value.config.concurrently ?? false,
15948
+ method: value.config.method ?? "btree",
15949
+ with: value.config.with ?? {}
15729
15950
  };
15730
15951
  });
15731
15952
  const tableKey2 = `${schema5 ?? "public"}.${tableName}`;
@@ -15739,16 +15960,6 @@ ${withStyle.errorWarning(
15739
15960
  uniqueConstraints: uniqueConstraintObject
15740
15961
  };
15741
15962
  }
15742
- const enumsToReturn = enums.reduce((map, obj) => {
15743
- const enumSchema3 = obj.schema || "public";
15744
- const key = `${enumSchema3}.${obj.enumName}`;
15745
- map[key] = {
15746
- name: obj.enumName,
15747
- schema: enumSchema3,
15748
- values: obj.enumValues
15749
- };
15750
- return map;
15751
- }, {});
15752
15963
  const schemasObject = Object.fromEntries(
15753
15964
  schemas.filter((it) => {
15754
15965
  if (schemaFilter) {
@@ -15759,7 +15970,7 @@ ${withStyle.errorWarning(
15759
15970
  }).map((it) => [it.schemaName, it.schemaName])
15760
15971
  );
15761
15972
  return {
15762
- version: "6",
15973
+ version: "7",
15763
15974
  dialect: "postgresql",
15764
15975
  tables: result,
15765
15976
  enums: enumsToReturn,
@@ -16031,7 +16242,10 @@ ${withStyle.errorWarning(
16031
16242
  columnTypeMapped = trimChar(columnTypeMapped, '"');
16032
16243
  columnToReturn[columnName] = {
16033
16244
  name: columnName,
16034
- type: columnAdditionalDT === "USER-DEFINED" ? enumType3 : columnTypeMapped,
16245
+ type: (
16246
+ // filter vectors, but in future we should filter any extension that was installed by user
16247
+ columnAdditionalDT === "USER-DEFINED" && enumType3 !== "vector" ? enumType3 : columnTypeMapped
16248
+ ),
16035
16249
  typeSchema: enumsToReturn[`${tableSchema}.${enumType3}`] !== void 0 ? enumsToReturn[`${tableSchema}.${enumType3}`].schema : void 0,
16036
16250
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
16037
16251
  // default: isSerial ? undefined : defaultValue,
@@ -16042,15 +16256,42 @@ ${withStyle.errorWarning(
16042
16256
  }
16043
16257
  }
16044
16258
  const dbIndexes = await db2.query(
16045
- `SELECT t.relname as table_name, i.relname AS index_name, ix.indisunique AS is_unique, a.attname AS column_name
16046
- FROM pg_class t
16047
- JOIN pg_index ix ON t.oid = ix.indrelid
16048
- JOIN pg_class i ON i.oid = ix.indexrelid
16049
- JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
16050
- JOIN pg_namespace ns ON ns.oid = t.relnamespace
16051
- WHERE ns.nspname = '${tableSchema}'
16052
- AND t.relname = '${tableName}'
16053
- and ix.indisprimary = false;`
16259
+ `SELECT DISTINCT ON (t.relname, ic.relname, k.i) t.relname as table_name, ic.relname AS indexname,
16260
+ k.i AS index_order,
16261
+ i.indisunique as is_unique,
16262
+ am.amname as method,
16263
+ ic.reloptions as with,
16264
+ coalesce(a.attname,
16265
+ (('{' || pg_get_expr(
16266
+ i.indexprs,
16267
+ i.indrelid
16268
+ )
16269
+ || '}')::text[]
16270
+ )[k.i]
16271
+ ) AS column_name,
16272
+ CASE
16273
+ WHEN pg_get_expr(i.indexprs, i.indrelid) IS NOT NULL THEN 1
16274
+ ELSE 0
16275
+ END AS is_expression,
16276
+ i.indoption[k.i-1] & 1 = 1 AS descending,
16277
+ i.indoption[k.i-1] & 2 = 2 AS nulls_first,
16278
+ pg_get_expr(
16279
+ i.indpred,
16280
+ i.indrelid
16281
+ ) as where,
16282
+ opc.opcname
16283
+ FROM pg_class t
16284
+ LEFT JOIN pg_index i ON t.oid = i.indrelid
16285
+ LEFT JOIN pg_class ic ON ic.oid = i.indexrelid
16286
+ CROSS JOIN LATERAL (SELECT unnest(i.indkey), generate_subscripts(i.indkey, 1) + 1) AS k(attnum, i)
16287
+ LEFT JOIN pg_attribute AS a
16288
+ ON i.indrelid = a.attrelid AND k.attnum = a.attnum
16289
+ JOIN pg_namespace c on c.oid = t.relnamespace
16290
+ LEFT JOIN pg_am AS am ON ic.relam = am.oid
16291
+ JOIN pg_opclass opc ON opc.oid = ANY(i.indclass)
16292
+ WHERE
16293
+ c.nspname = '${tableSchema}' AND
16294
+ t.relname = '${tableName}';`
16054
16295
  );
16055
16296
  const dbIndexFromConstraint = await db2.query(
16056
16297
  `SELECT
@@ -16067,18 +16308,51 @@ ${withStyle.errorWarning(
16067
16308
  );
16068
16309
  const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
16069
16310
  for (const dbIndex of dbIndexes) {
16070
- const indexName4 = dbIndex.index_name;
16311
+ const indexName4 = dbIndex.indexname;
16071
16312
  const indexColumnName = dbIndex.column_name;
16072
16313
  const indexIsUnique = dbIndex.is_unique;
16314
+ const indexMethod = dbIndex.method;
16315
+ const indexWith = dbIndex.with;
16316
+ const indexWhere = dbIndex.where;
16317
+ const opclass = dbIndex.opcname;
16318
+ const isExpression = dbIndex.is_expression === 1;
16319
+ const desc = dbIndex.descending;
16320
+ const nullsFirst = dbIndex.nulls_first;
16321
+ const mappedWith = {};
16322
+ if (indexWith !== null) {
16323
+ indexWith.forEach((it) => {
16324
+ const splitted = it.split("=");
16325
+ mappedWith[splitted[0]] = splitted[1];
16326
+ });
16327
+ }
16073
16328
  if (idxsInConsteraint.includes(indexName4))
16074
16329
  continue;
16075
16330
  if (typeof indexToReturn[indexName4] !== "undefined") {
16076
- indexToReturn[indexName4].columns.push(indexColumnName);
16331
+ indexToReturn[indexName4].columns.push({
16332
+ expression: indexColumnName,
16333
+ asc: !desc,
16334
+ nulls: nullsFirst ? "first" : "last",
16335
+ opclass,
16336
+ isExpression
16337
+ });
16077
16338
  } else {
16078
16339
  indexToReturn[indexName4] = {
16079
16340
  name: indexName4,
16080
- columns: [indexColumnName],
16081
- isUnique: indexIsUnique
16341
+ columns: [
16342
+ {
16343
+ expression: indexColumnName,
16344
+ asc: !desc,
16345
+ nulls: nullsFirst ? "first" : "last",
16346
+ opclass,
16347
+ isExpression
16348
+ }
16349
+ ],
16350
+ isUnique: indexIsUnique,
16351
+ // should not be a part of diff detecs
16352
+ concurrently: false,
16353
+ method: indexMethod,
16354
+ where: indexWhere === null ? void 0 : indexWhere,
16355
+ with: mappedWith
16082
16356
  };
16083
16357
  }
16084
16358
  }
@@ -16114,7 +16388,7 @@ ${withStyle.errorWarning(
16114
16388
  }
16115
16389
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
16116
16390
  return {
16117
- version: "6",
16391
+ version: "7",
16118
16392
  dialect: "postgresql",
16119
16393
  tables: result,
16120
16394
  enums: enumsToReturn,
@@ -16898,7 +17172,7 @@ var init_sqlgenerator = __esm({
16898
17172
  if (pgNativeTypes.has(it))
16899
17173
  return true;
16900
17174
  const toCheck = it.replace(/ /g, "");
16901
- 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(") || /^(\w+)(\[\d*])+$/.test(it);
17175
+ 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(") || /^(\w+)(\[\d*])+$/.test(it);
16902
17176
  };
16903
17177
  Convertor = class {
16904
17178
  };
@@ -17860,14 +18134,34 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
17860
18134
  };
17861
18135
  CreatePgIndexConvertor = class extends Convertor {
17862
18136
  can(statement, dialect7) {
17863
- return statement.type === "create_index" && dialect7 === "postgresql";
18137
+ return statement.type === "create_index_pg" && dialect7 === "postgresql";
17864
18138
  }
17865
18139
  convert(statement) {
17866
- const { name, columns, isUnique } = PgSquasher.unsquashIdx(statement.data);
18140
+ const {
18141
+ name,
18142
+ columns,
18143
+ isUnique,
18144
+ concurrently,
18145
+ with: withMap,
18146
+ method,
18147
+ where
18148
+ } = statement.data;
17867
18149
  const indexPart = isUnique ? "UNIQUE INDEX" : "INDEX";
17868
- const value = columns.map((it) => `"${it}"`).join(",");
18150
+ const value = columns.map(
18151
+ (it) => `${it.expression}${it.opclass ? ` ${it.opclass}` : it.asc ? "" : " DESC"}${it.asc && it.nulls && it.nulls === "last" || it.opclass ? "" : ` NULLS ${it.nulls.toUpperCase()}`}`
18152
+ ).join(",");
17869
18153
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${statement.tableName}"` : `"${statement.tableName}"`;
17870
- return `CREATE ${indexPart} IF NOT EXISTS "${name}" ON ${tableNameWithSchema} (${value});`;
18154
+ function reverseLogic(mappedWith) {
18155
+ let reversedString = "";
18156
+ for (const key in mappedWith) {
18157
+ if (mappedWith.hasOwnProperty(key)) {
18158
+ reversedString += `${key}=${mappedWith[key]},`;
18159
+ }
18160
+ }
18161
+ reversedString = reversedString.slice(0, -1);
18162
+ return reversedString;
18163
+ }
18164
+ return `CREATE ${indexPart}${concurrently ? " CONCURRENTLY" : ""} IF NOT EXISTS "${name}" ON ${tableNameWithSchema} USING ${method} (${value})${Object.keys(withMap).length !== 0 ? ` WITH (${reverseLogic(withMap)})` : ""}${where ? ` WHERE ${where}` : ""};`;
17871
18165
  }
17872
18166
  };
17873
18167
  CreateMySqlIndexConvertor = class extends Convertor {
@@ -18521,7 +18815,7 @@ var init_jsonDiffer = __esm({
18521
18815
  });
18522
18816
 
18523
18817
  // src/jsonStatements.ts
18524
- var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
18818
+ var preparePgCreateTableJson, prepareMySqlCreateTableJson, prepareSQLiteCreateTable, prepareDropTableJson, prepareRenameTableJson, prepareCreateEnumJson, prepareAddValuesToEnumJson, prepareDropEnumJson, prepareMoveEnumJson, prepareRenameEnumJson, prepareCreateSchemasJson, prepareRenameSchemasJson, prepareDeleteSchemasJson, prepareRenameColumns, _prepareDropColumns, _prepareAddColumns, _prepareSqliteAddColumns, prepareAlterColumnsMysql, preparePgAlterColumns, prepareSqliteAlterColumns, preparePgCreateIndexesJson, prepareCreateIndexesJson, prepareCreateReferencesJson, prepareDropReferencesJson, prepareAlterReferencesJson, prepareDropIndexesJson, prepareAddCompositePrimaryKeySqlite, prepareDeleteCompositePrimaryKeySqlite, prepareAlterCompositePrimaryKeySqlite, prepareAddCompositePrimaryKeyPg, prepareDeleteCompositePrimaryKeyPg, prepareAlterCompositePrimaryKeyPg, prepareAddUniqueConstraintPg, prepareDeleteUniqueConstraintPg, prepareAddCompositePrimaryKeyMySql, prepareDeleteCompositePrimaryKeyMySql, prepareAlterCompositePrimaryKeyMySql;
18525
18819
  var init_jsonStatements = __esm({
18526
18820
  "src/jsonStatements.ts"() {
18527
18821
  "use strict";
@@ -19286,6 +19580,28 @@ var init_jsonStatements = __esm({
19286
19580
  }
19287
19581
  return [...dropPkStatements, ...setPkStatements, ...statements];
19288
19582
  };
19583
+ preparePgCreateIndexesJson = (tableName, schema5, indexes, fullSchema, action) => {
19584
+ if (action === "push") {
19585
+ return Object.values(indexes).map((indexData) => {
19586
+ const unsquashedIndex = PgSquasher.unsquashIdxPush(indexData);
19587
+ const data = fullSchema.tables[`${schema5 === "" ? "public" : schema5}.${tableName}`].indexes[unsquashedIndex.name];
19588
+ return {
19589
+ type: "create_index_pg",
19590
+ tableName,
19591
+ data,
19592
+ schema: schema5
19593
+ };
19594
+ });
19595
+ }
19596
+ return Object.values(indexes).map((indexData) => {
19597
+ return {
19598
+ type: "create_index_pg",
19599
+ tableName,
19600
+ data: PgSquasher.unsquashIdx(indexData),
19601
+ schema: schema5
19602
+ };
19603
+ });
19604
+ };
19289
19605
  prepareCreateIndexesJson = (tableName, schema5, indexes) => {
19290
19606
  return Object.values(indexes).map((indexData) => {
19291
19607
  return {
@@ -19661,7 +19977,7 @@ var init_snapshotsDiffer = __esm({
19661
19977
  }
19662
19978
  return column7;
19663
19979
  };
19664
- applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, tablesResolver2, columnsResolver2, prevFull, curFull) => {
19980
+ applyPgSnapshotsDiff = async (json1, json2, schemasResolver2, enumsResolver2, tablesResolver2, columnsResolver2, prevFull, curFull, action) => {
19665
19981
  const schemasDiff = diffSchemasOrTables(json1.schemas, json2.schemas);
19666
19982
  const {
19667
19983
  created: createdSchemas,
@@ -19823,7 +20139,13 @@ var init_snapshotsDiffer = __esm({
19823
20139
  const typedResult = diffResultScheme.parse(diffResult);
19824
20140
  const jsonStatements = [];
19825
20141
  const jsonCreateIndexesForCreatedTables = createdTables.map((it) => {
19826
- return prepareCreateIndexesJson(it.name, it.schema, it.indexes);
20142
+ return preparePgCreateIndexesJson(
20143
+ it.name,
20144
+ it.schema,
20145
+ it.indexes,
20146
+ curFull,
20147
+ action
20148
+ );
19827
20149
  }).flat();
19828
20150
  const jsonDropTables = deletedTables.map((it) => {
19829
20151
  return prepareDropTableJson(it);
@@ -19947,10 +20269,12 @@ var init_snapshotsDiffer = __esm({
19947
20269
  return preparePgAlterColumns(it.name, it.schema, it.altered, json2);
19948
20270
  }).flat();
19949
20271
  const jsonCreateIndexesFoAlteredTables = alteredTables.map((it) => {
19950
- return prepareCreateIndexesJson(
20272
+ return preparePgCreateIndexesJson(
19951
20273
  it.name,
19952
20274
  it.schema,
19953
- it.addedIndexes || {}
20275
+ it.addedIndexes || {},
20276
+ curFull,
20277
+ action
19954
20278
  );
19955
20279
  }).flat();
19956
20280
  const jsonDropIndexesForAllAlteredTables = alteredTables.map((it) => {
@@ -19976,7 +20300,13 @@ var init_snapshotsDiffer = __esm({
19976
20300
  {}
19977
20301
  );
19978
20302
  jsonCreateIndexesFoAlteredTables.push(
19979
- ...prepareCreateIndexesJson(it.name, it.schema, createdIndexes || {})
20303
+ ...preparePgCreateIndexesJson(
20304
+ it.name,
20305
+ it.schema,
20306
+ createdIndexes || {},
20307
+ curFull,
20308
+ action
20309
+ )
19980
20310
  );
19981
20311
  jsonDropIndexesForAllAlteredTables.push(
19982
20312
  ...prepareDropIndexesJson(it.name, it.schema, droppedIndexes || {})
@@ -22083,7 +22413,10 @@ var init_migrate = __esm({
22083
22413
  const schemaPath = config.schema;
22084
22414
  try {
22085
22415
  assertV1OutFolder(outFolder);
22086
- const { snapshots, journal } = prepareMigrationFolder(outFolder, "postgresql");
22416
+ const { snapshots, journal } = prepareMigrationFolder(
22417
+ outFolder,
22418
+ "postgresql"
22419
+ );
22087
22420
  const { prev, cur, custom: custom2 } = await preparePgMigrationSnapshot(
22088
22421
  snapshots,
22089
22422
  schemaPath
@@ -22134,8 +22467,8 @@ var init_migrate = __esm({
22134
22467
  );
22135
22468
  const validatedPrev = pgSchema.parse(prev);
22136
22469
  const validatedCur = pgSchema.parse(cur);
22137
- const squashedPrev = squashPgScheme(validatedPrev);
22138
- const squashedCur = squashPgScheme(validatedCur);
22470
+ const squashedPrev = squashPgScheme(validatedPrev, "push");
22471
+ const squashedCur = squashPgScheme(validatedCur, "push");
22139
22472
  const { sqlStatements, statements, _meta } = await applyPgSnapshotsDiff(
22140
22473
  squashedPrev,
22141
22474
  squashedCur,
@@ -22144,7 +22477,8 @@ var init_migrate = __esm({
22144
22477
  tablesResolver,
22145
22478
  columnsResolver,
22146
22479
  validatedPrev,
22147
- validatedCur
22480
+ validatedCur,
22481
+ "push"
22148
22482
  );
22149
22483
  return { sqlStatements, statements, squashedPrev, squashedCur };
22150
22484
  };
@@ -24271,9 +24605,9 @@ var require_glob_parent = __commonJS({
24271
24605
  }
24272
24606
  });
24273
24607
 
24274
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/utils.js
24608
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/utils.js
24275
24609
  var require_utils2 = __commonJS({
24276
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/utils.js"(exports2) {
24610
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/utils.js"(exports2) {
24277
24611
  "use strict";
24278
24612
  exports2.isInteger = (num) => {
24279
24613
  if (typeof num === "number") {
@@ -24293,7 +24627,7 @@ var require_utils2 = __commonJS({
24293
24627
  return (Number(max) - Number(min)) / Number(step) >= limit;
24294
24628
  };
24295
24629
  exports2.escapeNode = (block, n = 0, type) => {
24296
- const node = block.nodes[n];
24630
+ let node = block.nodes[n];
24297
24631
  if (!node)
24298
24632
  return;
24299
24633
  if (type && node.type === type || node.type === "open" || node.type === "close") {
@@ -24344,14 +24678,8 @@ var require_utils2 = __commonJS({
24344
24678
  const result = [];
24345
24679
  const flat = (arr) => {
24346
24680
  for (let i2 = 0; i2 < arr.length; i2++) {
24347
- const ele = arr[i2];
24348
- if (Array.isArray(ele)) {
24349
- flat(ele);
24350
- continue;
24351
- }
24352
- if (ele !== void 0) {
24353
- result.push(ele);
24354
- }
24681
+ let ele = arr[i2];
24682
+ Array.isArray(ele) ? flat(ele, result) : ele !== void 0 && result.push(ele);
24355
24683
  }
24356
24684
  return result;
24357
24685
  };
@@ -24361,15 +24689,15 @@ var require_utils2 = __commonJS({
24361
24689
  }
24362
24690
  });
24363
24691
 
24364
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/stringify.js
24692
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/stringify.js
24365
24693
  var require_stringify = __commonJS({
24366
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/stringify.js"(exports2, module2) {
24694
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/stringify.js"(exports2, module2) {
24367
24695
  "use strict";
24368
24696
  var utils = require_utils2();
24369
24697
  module2.exports = (ast, options = {}) => {
24370
- const stringify4 = (node, parent = {}) => {
24371
- const invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
24372
- const invalidNode = node.invalid === true && options.escapeInvalid === true;
24698
+ let stringify4 = (node, parent = {}) => {
24699
+ let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
24700
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
24373
24701
  let output = "";
24374
24702
  if (node.value) {
24375
24703
  if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
@@ -24381,7 +24709,7 @@ var require_stringify = __commonJS({
24381
24709
  return node.value;
24382
24710
  }
24383
24711
  if (node.nodes) {
24384
- for (const child of node.nodes) {
24712
+ for (let child of node.nodes) {
24385
24713
  output += stringify4(child);
24386
24714
  }
24387
24715
  }
@@ -24826,24 +25154,23 @@ var require_fill_range = __commonJS({
24826
25154
  }
24827
25155
  });
24828
25156
 
24829
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/compile.js
25157
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/compile.js
24830
25158
  var require_compile = __commonJS({
24831
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/compile.js"(exports2, module2) {
25159
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/compile.js"(exports2, module2) {
24832
25160
  "use strict";
24833
25161
  var fill = require_fill_range();
24834
25162
  var utils = require_utils2();
24835
25163
  var compile = (ast, options = {}) => {
24836
- const walk = (node, parent = {}) => {
24837
- const invalidBlock = utils.isInvalidBrace(parent);
24838
- const invalidNode = node.invalid === true && options.escapeInvalid === true;
24839
- const invalid = invalidBlock === true || invalidNode === true;
24840
- const prefix = options.escapeInvalid === true ? "\\" : "";
25164
+ let walk = (node, parent = {}) => {
25165
+ let invalidBlock = utils.isInvalidBrace(parent);
25166
+ let invalidNode = node.invalid === true && options.escapeInvalid === true;
25167
+ let invalid = invalidBlock === true || invalidNode === true;
25168
+ let prefix = options.escapeInvalid === true ? "\\" : "";
24841
25169
  let output = "";
24842
25170
  if (node.isOpen === true) {
24843
25171
  return prefix + node.value;
24844
25172
  }
24845
25173
  if (node.isClose === true) {
24846
- console.log("node.isClose", prefix, node.value);
24847
25174
  return prefix + node.value;
24848
25175
  }
24849
25176
  if (node.type === "open") {
@@ -24859,14 +25186,14 @@ var require_compile = __commonJS({
24859
25186
  return node.value;
24860
25187
  }
24861
25188
  if (node.nodes && node.ranges > 0) {
24862
- const args = utils.reduce(node.nodes);
24863
- const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
25189
+ let args = utils.reduce(node.nodes);
25190
+ let range = fill(...args, { ...options, wrap: false, toRegex: true });
24864
25191
  if (range.length !== 0) {
24865
25192
  return args.length > 1 && range.length > 1 ? `(${range})` : range;
24866
25193
  }
24867
25194
  }
24868
25195
  if (node.nodes) {
24869
- for (const child of node.nodes) {
25196
+ for (let child of node.nodes) {
24870
25197
  output += walk(child, node);
24871
25198
  }
24872
25199
  }
@@ -24878,15 +25205,15 @@ var require_compile = __commonJS({
24878
25205
  }
24879
25206
  });
24880
25207
 
24881
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/expand.js
25208
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/expand.js
24882
25209
  var require_expand = __commonJS({
24883
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/expand.js"(exports2, module2) {
25210
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/expand.js"(exports2, module2) {
24884
25211
  "use strict";
24885
25212
  var fill = require_fill_range();
24886
25213
  var stringify4 = require_stringify();
24887
25214
  var utils = require_utils2();
24888
25215
  var append = (queue = "", stash = "", enclose = false) => {
24889
- const result = [];
25216
+ let result = [];
24890
25217
  queue = [].concat(queue);
24891
25218
  stash = [].concat(stash);
24892
25219
  if (!stash.length)
@@ -24894,9 +25221,9 @@ var require_expand = __commonJS({
24894
25221
  if (!queue.length) {
24895
25222
  return enclose ? utils.flatten(stash).map((ele) => `{${ele}}`) : stash;
24896
25223
  }
24897
- for (const item of queue) {
25224
+ for (let item of queue) {
24898
25225
  if (Array.isArray(item)) {
24899
- for (const value of item) {
25226
+ for (let value of item) {
24900
25227
  result.push(append(value, stash, enclose));
24901
25228
  }
24902
25229
  } else {
@@ -24910,8 +25237,8 @@ var require_expand = __commonJS({
24910
25237
  return utils.flatten(result);
24911
25238
  };
24912
25239
  var expand2 = (ast, options = {}) => {
24913
- const rangeLimit = options.rangeLimit === void 0 ? 1e3 : options.rangeLimit;
24914
- const walk = (node, parent = {}) => {
25240
+ let rangeLimit = options.rangeLimit === void 0 ? 1e3 : options.rangeLimit;
25241
+ let walk = (node, parent = {}) => {
24915
25242
  node.queue = [];
24916
25243
  let p4 = parent;
24917
25244
  let q = parent.queue;
@@ -24928,7 +25255,7 @@ var require_expand = __commonJS({
24928
25255
  return;
24929
25256
  }
24930
25257
  if (node.nodes && node.ranges > 0) {
24931
- const args = utils.reduce(node.nodes);
25258
+ let args = utils.reduce(node.nodes);
24932
25259
  if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
24933
25260
  throw new RangeError("expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.");
24934
25261
  }
@@ -24940,7 +25267,7 @@ var require_expand = __commonJS({
24940
25267
  node.nodes = [];
24941
25268
  return;
24942
25269
  }
24943
- const enclose = utils.encloseBrace(node);
25270
+ let enclose = utils.encloseBrace(node);
24944
25271
  let queue = node.queue;
24945
25272
  let block = node;
24946
25273
  while (block.type !== "brace" && block.type !== "root" && block.parent) {
@@ -24948,7 +25275,7 @@ var require_expand = __commonJS({
24948
25275
  queue = block.queue;
24949
25276
  }
24950
25277
  for (let i2 = 0; i2 < node.nodes.length; i2++) {
24951
- const child = node.nodes[i2];
25278
+ let child = node.nodes[i2];
24952
25279
  if (child.type === "comma" && node.type === "brace") {
24953
25280
  if (i2 === 1)
24954
25281
  queue.push("");
@@ -24975,12 +25302,12 @@ var require_expand = __commonJS({
24975
25302
  }
24976
25303
  });
24977
25304
 
24978
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/constants.js
25305
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/constants.js
24979
25306
  var require_constants2 = __commonJS({
24980
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/constants.js"(exports2, module2) {
25307
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/constants.js"(exports2, module2) {
24981
25308
  "use strict";
24982
25309
  module2.exports = {
24983
- MAX_LENGTH: 1e4,
25310
+ MAX_LENGTH: 1024 * 64,
24984
25311
  // Digits
24985
25312
  CHAR_0: "0",
24986
25313
  /* 0 */
@@ -25076,9 +25403,9 @@ var require_constants2 = __commonJS({
25076
25403
  }
25077
25404
  });
25078
25405
 
25079
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/parse.js
25406
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/parse.js
25080
25407
  var require_parse2 = __commonJS({
25081
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/lib/parse.js"(exports2, module2) {
25408
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/lib/parse.js"(exports2, module2) {
25082
25409
  "use strict";
25083
25410
  var stringify4 = require_stringify();
25084
25411
  var {
@@ -25114,20 +25441,21 @@ var require_parse2 = __commonJS({
25114
25441
  if (typeof input !== "string") {
25115
25442
  throw new TypeError("Expected a string");
25116
25443
  }
25117
- const opts = options || {};
25118
- const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
25444
+ let opts = options || {};
25445
+ let max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
25119
25446
  if (input.length > max) {
25120
25447
  throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
25121
25448
  }
25122
- const ast = { type: "root", input, nodes: [] };
25123
- const stack = [ast];
25449
+ let ast = { type: "root", input, nodes: [] };
25450
+ let stack = [ast];
25124
25451
  let block = ast;
25125
25452
  let prev = ast;
25126
25453
  let brackets = 0;
25127
- const length = input.length;
25454
+ let length = input.length;
25128
25455
  let index4 = 0;
25129
25456
  let depth = 0;
25130
25457
  let value;
25458
+ let memo = {};
25131
25459
  const advance = () => input[index4++];
25132
25460
  const push = (node) => {
25133
25461
  if (node.type === "text" && prev.type === "dot") {
@@ -25160,6 +25488,7 @@ var require_parse2 = __commonJS({
25160
25488
  }
25161
25489
  if (value === CHAR_LEFT_SQUARE_BRACKET) {
25162
25490
  brackets++;
25491
+ let closed = true;
25163
25492
  let next;
25164
25493
  while (index4 < length && (next = advance())) {
25165
25494
  value += next;
@@ -25198,7 +25527,7 @@ var require_parse2 = __commonJS({
25198
25527
  continue;
25199
25528
  }
25200
25529
  if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
25201
- const open = value;
25530
+ let open = value;
25202
25531
  let next;
25203
25532
  if (options.keepQuotes !== true) {
25204
25533
  value = "";
@@ -25220,8 +25549,8 @@ var require_parse2 = __commonJS({
25220
25549
  }
25221
25550
  if (value === CHAR_LEFT_CURLY_BRACE) {
25222
25551
  depth++;
25223
- const dollar = prev.value && prev.value.slice(-1) === "$" || block.dollar === true;
25224
- const brace = {
25552
+ let dollar = prev.value && prev.value.slice(-1) === "$" || block.dollar === true;
25553
+ let brace = {
25225
25554
  type: "brace",
25226
25555
  open: true,
25227
25556
  close: false,
@@ -25241,7 +25570,7 @@ var require_parse2 = __commonJS({
25241
25570
  push({ type: "text", value });
25242
25571
  continue;
25243
25572
  }
25244
- const type = "close";
25573
+ let type = "close";
25245
25574
  block = stack.pop();
25246
25575
  block.close = true;
25247
25576
  push({ type, value });
@@ -25252,7 +25581,7 @@ var require_parse2 = __commonJS({
25252
25581
  if (value === CHAR_COMMA && depth > 0) {
25253
25582
  if (block.ranges > 0) {
25254
25583
  block.ranges = 0;
25255
- const open = block.nodes.shift();
25584
+ let open = block.nodes.shift();
25256
25585
  block.nodes = [open, { type: "text", value: stringify4(block) }];
25257
25586
  }
25258
25587
  push({ type: "comma", value });
@@ -25260,7 +25589,7 @@ var require_parse2 = __commonJS({
25260
25589
  continue;
25261
25590
  }
25262
25591
  if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
25263
- const siblings = block.nodes;
25592
+ let siblings = block.nodes;
25264
25593
  if (depth === 0 || siblings.length === 0) {
25265
25594
  push({ type: "text", value });
25266
25595
  continue;
@@ -25281,7 +25610,7 @@ var require_parse2 = __commonJS({
25281
25610
  }
25282
25611
  if (prev.type === "range") {
25283
25612
  siblings.pop();
25284
- const before = siblings[siblings.length - 1];
25613
+ let before = siblings[siblings.length - 1];
25285
25614
  before.value += prev.value + value;
25286
25615
  prev = before;
25287
25616
  block.ranges--;
@@ -25306,8 +25635,8 @@ var require_parse2 = __commonJS({
25306
25635
  node.invalid = true;
25307
25636
  }
25308
25637
  });
25309
- const parent = stack[stack.length - 1];
25310
- const index5 = parent.nodes.indexOf(block);
25638
+ let parent = stack[stack.length - 1];
25639
+ let index5 = parent.nodes.indexOf(block);
25311
25640
  parent.nodes.splice(index5, 1, ...block.nodes);
25312
25641
  }
25313
25642
  } while (stack.length > 0);
@@ -25318,9 +25647,9 @@ var require_parse2 = __commonJS({
25318
25647
  }
25319
25648
  });
25320
25649
 
25321
- // node_modules/.pnpm/braces@3.0.3/node_modules/braces/index.js
25650
+ // node_modules/.pnpm/braces@3.0.2/node_modules/braces/index.js
25322
25651
  var require_braces = __commonJS({
25323
- "node_modules/.pnpm/braces@3.0.3/node_modules/braces/index.js"(exports2, module2) {
25652
+ "node_modules/.pnpm/braces@3.0.2/node_modules/braces/index.js"(exports2, module2) {
25324
25653
  "use strict";
25325
25654
  var stringify4 = require_stringify();
25326
25655
  var compile = require_compile();
@@ -25329,8 +25658,8 @@ var require_braces = __commonJS({
25329
25658
  var braces = (input, options = {}) => {
25330
25659
  let output = [];
25331
25660
  if (Array.isArray(input)) {
25332
- for (const pattern of input) {
25333
- const result = braces.create(pattern, options);
25661
+ for (let pattern of input) {
25662
+ let result = braces.create(pattern, options);
25334
25663
  if (Array.isArray(result)) {
25335
25664
  output.push(...result);
25336
25665
  } else {
@@ -26907,9 +27236,9 @@ var require_picomatch2 = __commonJS({
26907
27236
  }
26908
27237
  });
26909
27238
 
26910
- // node_modules/.pnpm/micromatch@4.0.7/node_modules/micromatch/index.js
27239
+ // node_modules/.pnpm/micromatch@4.0.5/node_modules/micromatch/index.js
26911
27240
  var require_micromatch = __commonJS({
26912
- "node_modules/.pnpm/micromatch@4.0.7/node_modules/micromatch/index.js"(exports2, module2) {
27241
+ "node_modules/.pnpm/micromatch@4.0.5/node_modules/micromatch/index.js"(exports2, module2) {
26913
27242
  "use strict";
26914
27243
  var util2 = require("util");
26915
27244
  var braces = require_braces();
@@ -111358,6 +111687,7 @@ var init_connections = __esm({
111358
111687
  const { drizzle } = await import("drizzle-orm/node-postgres");
111359
111688
  const { migrate } = await import("drizzle-orm/node-postgres/migrator");
111360
111689
  const client = "url" in credentials2 ? new pg.default.Pool({ connectionString: credentials2.url, max: 1 }) : new pg.default.Pool({ ...credentials2, max: 1 });
111690
+ await client.connect();
111361
111691
  const db2 = drizzle(client);
111362
111692
  const migrateFn = async (config) => {
111363
111693
  return migrate(db2, config);
@@ -115165,6 +115495,7 @@ var init_introspect_pg = __esm({
115165
115495
  init_utils3();
115166
115496
  init_pgSerializer();
115167
115497
  init_global();
115498
+ init_vector();
115168
115499
  pgImportsList = /* @__PURE__ */ new Set([
115169
115500
  "pgTable",
115170
115501
  "pgEnum",
@@ -115193,7 +115524,8 @@ var init_introspect_pg = __esm({
115193
115524
  "macaddr8",
115194
115525
  "bigint",
115195
115526
  "doublePrecision",
115196
- "uuid"
115527
+ "uuid",
115528
+ "vector"
115197
115529
  ]);
115198
115530
  objToStatement23 = (json) => {
115199
115531
  json = Object.fromEntries(Object.entries(json).filter((it) => it[1]));
@@ -115330,6 +115662,7 @@ var init_introspect_pg = __esm({
115330
115662
  patched = patched.startsWith("numeric(") ? "numeric" : patched;
115331
115663
  patched = patched.startsWith("time(") ? "time" : patched;
115332
115664
  patched = patched.startsWith("timestamp(") ? "timestamp" : patched;
115665
+ patched = patched.startsWith("vector(") ? "vector" : patched;
115333
115666
  return patched;
115334
115667
  }).filter((type) => {
115335
115668
  return pgImportsList.has(type);
@@ -115520,7 +115853,7 @@ var init_introspect_pg = __esm({
115520
115853
  }
115521
115854
  if (lowered === "date") {
115522
115855
  let out = `${withCasing2(name, casing2)}: date("${name}")`;
115523
- defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue ? `.default(${defaultValue})` : "";
115856
+ defaultValue = defaultValue === "now()" ? ".defaultNow()" : defaultValue === "CURRENT_DATE" ? `.default(sql\`${defaultValue}\`)` : defaultValue ? `.default(${defaultValue})` : "";
115524
115857
  out += defaultValue;
115525
115858
  return out;
115526
115859
  }
@@ -115580,6 +115913,23 @@ var init_introspect_pg = __esm({
115580
115913
  out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
115581
115914
  return out;
115582
115915
  }
115916
+ if (lowered.startsWith("vector")) {
115917
+ const split = lowered.split(" ");
115918
+ let out;
115919
+ if (lowered.length !== 6) {
115920
+ out = `${withCasing2(
115921
+ name,
115922
+ casing2
115923
+ )}: vector("${name}", { dimensions: ${lowered.substring(
115924
+ 7,
115925
+ lowered.length - 1
115926
+ )} })`;
115927
+ } else {
115928
+ out = `${withCasing2(name, casing2)}: vector("${name}")`;
115929
+ }
115930
+ out += typeof defaultValue !== "undefined" ? `.default(${defaultValue})` : "";
115931
+ return out;
115932
+ }
115583
115933
  if (lowered.startsWith("char")) {
115584
115934
  let out;
115585
115935
  if (lowered.length !== 4) {
@@ -115693,13 +116043,35 @@ var init_introspect_pg = __esm({
115693
116043
  let idxKey = it.name.startsWith(tableName) && it.name !== tableName ? it.name.slice(tableName.length + 1) : it.name;
115694
116044
  idxKey = idxKey.endsWith("_index") ? idxKey.slice(0, -"_index".length) + "_idx" : idxKey;
115695
116045
  idxKey = withCasing2(idxKey, casing2);
115696
- const indexGeneratedName = indexName2(tableName, it.columns);
116046
+ const indexGeneratedName = indexName2(
116047
+ tableName,
116048
+ it.columns.map((it2) => it2.expression)
116049
+ );
115697
116050
  const escapedIndexName = indexGeneratedName === it.name ? "" : `"${it.name}"`;
115698
116051
  statement += ` ${idxKey}: `;
115699
116052
  statement += it.isUnique ? "uniqueIndex(" : "index(";
115700
116053
  statement += `${escapedIndexName})`;
115701
- statement += `.on(${it.columns.map((it2) => `table.${withCasing2(it2, casing2)}`).join(", ")}),`;
115702
- statement += `
116054
+ statement += `${it.concurrently ? `.concurrently()` : ""}`;
116055
+ statement += `.using("${it.method}", ${it.columns.map((it2) => {
116056
+ if (it2.isExpression) {
116057
+ return `sql\`${it2.expression}\``;
116058
+ } else {
116059
+ return `table.${withCasing2(it2.expression, casing2)}${it2.opclass && vectorOps.includes(it2.opclass) ? `.op("${it2.opclass}")` : ""}`;
116060
+ }
116061
+ }).join(", ")})`;
116062
+ statement += it.where ? `.where(sql\`${it.where}\`)` : "";
116063
+ function reverseLogic(mappedWith) {
116064
+ let reversedString = "{";
116065
+ for (const key in mappedWith) {
116066
+ if (mappedWith.hasOwnProperty(key)) {
116067
+ reversedString += `${key}: "${mappedWith[key]}",`;
116068
+ }
116069
+ }
116070
+ reversedString = reversedString.length > 1 ? reversedString.slice(0, reversedString.length - 1) : reversedString;
116071
+ return `${reversedString}}`;
116072
+ }
116073
+ statement += it.with && Object.keys(it.with).length > 0 ? `.with(${reverseLogic(it.with)})` : "";
116074
+ statement += `,
115703
116075
  `;
115704
116076
  });
115705
116077
  return statement;
@@ -120141,7 +120513,11 @@ var upPgHandler = (out) => {
120141
120513
  raw: report.rawMap[it]
120142
120514
  })).forEach((it) => {
120143
120515
  const path5 = it.path;
120144
- const result = updateUpToV6(it.raw);
120516
+ let resultV6 = it.raw;
120517
+ if (it.raw.version === "5") {
120518
+ resultV6 = updateUpToV6(it.raw);
120519
+ }
120520
+ const result = updateUpToV7(resultV6);
120145
120521
  console.log(`[${source_default.green("\u2713")}] ${path5}`);
120146
120522
  (0, import_fs2.writeFileSync)(path5, JSON.stringify(result, null, 2));
120147
120523
  });
@@ -120177,6 +120553,36 @@ var updateUpToV6 = (json) => {
120177
120553
  enums
120178
120554
  };
120179
120555
  };
120556
+ var updateUpToV7 = (json) => {
120557
+ const schema5 = pgSchemaV6.parse(json);
120558
+ const tables = Object.fromEntries(
120559
+ Object.entries(schema5.tables).map((it) => {
120560
+ const table4 = it[1];
120561
+ const mappedIndexes = Object.fromEntries(
120562
+ Object.entries(table4.indexes).map((idx) => {
120563
+ const { columns, ...rest } = idx[1];
120564
+ const mappedColumns = columns.map((it2) => {
120565
+ return {
120566
+ expression: it2,
120567
+ isExpression: false,
120568
+ asc: true,
120569
+ nulls: "last",
120570
+ opClass: void 0
120571
+ };
120572
+ });
120573
+ return [idx[0], { columns: mappedColumns, ...rest }];
120574
+ })
120575
+ );
120576
+ return [it[0], { ...table4, indexes: mappedIndexes }];
120577
+ })
120578
+ );
120579
+ return {
120580
+ ...schema5,
120581
+ version: "7",
120582
+ dialect: "postgresql",
120583
+ tables
120584
+ };
120585
+ };
120180
120586
 
120181
120587
  // src/cli/commands/sqliteUp.ts
120182
120588
  init_source();
@@ -121342,7 +121748,7 @@ var printVersions = async () => {
121342
121748
  var versions = async () => {
121343
121749
  const { npmVersion } = await ormCoreVersions();
121344
121750
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
121345
- const envVersion = "0.21.4";
121751
+ const envVersion = "0.22.0";
121346
121752
  const kitVersion = envVersion ? `v${envVersion}` : "--";
121347
121753
  const versions2 = `drizzle-kit: ${kitVersion}
121348
121754
  ${ormVersion}`;