drizzle-kit 0.24.0 → 0.24.1-781dea0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. package/api.d.mts +10 -0
  2. package/api.d.ts +10 -0
  3. package/api.js +159 -107
  4. package/api.mjs +159 -107
  5. package/bin.cjs +1018 -478
  6. package/package.json +3 -3
  7. package/utils.js +2 -1
  8. package/utils.mjs +2 -1
package/api.d.mts CHANGED
@@ -801,23 +801,28 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
801
801
  isArray: zod.ZodOptional<zod.ZodBoolean>;
802
802
  dimensions: zod.ZodOptional<zod.ZodNumber>;
803
803
  rawType: zod.ZodOptional<zod.ZodString>;
804
+ isDefaultAnExpression: zod.ZodOptional<zod.ZodBoolean>;
804
805
  }, "strip", zod.ZodTypeAny, {
806
+ isDefaultAnExpression?: boolean | undefined;
805
807
  isArray?: boolean | undefined;
806
808
  dimensions?: number | undefined;
807
809
  rawType?: string | undefined;
808
810
  }, {
811
+ isDefaultAnExpression?: boolean | undefined;
809
812
  isArray?: boolean | undefined;
810
813
  dimensions?: number | undefined;
811
814
  rawType?: string | undefined;
812
815
  }>>>;
813
816
  }, "strip", zod.ZodTypeAny, {
814
817
  columns: Record<string, {
818
+ isDefaultAnExpression?: boolean | undefined;
815
819
  isArray?: boolean | undefined;
816
820
  dimensions?: number | undefined;
817
821
  rawType?: string | undefined;
818
822
  } | undefined>;
819
823
  }, {
820
824
  columns: Record<string, {
825
+ isDefaultAnExpression?: boolean | undefined;
821
826
  isArray?: boolean | undefined;
822
827
  dimensions?: number | undefined;
823
828
  rawType?: string | undefined;
@@ -826,6 +831,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
826
831
  }, "strip", zod.ZodTypeAny, {
827
832
  tables: Record<string, {
828
833
  columns: Record<string, {
834
+ isDefaultAnExpression?: boolean | undefined;
829
835
  isArray?: boolean | undefined;
830
836
  dimensions?: number | undefined;
831
837
  rawType?: string | undefined;
@@ -834,6 +840,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
834
840
  }, {
835
841
  tables: Record<string, {
836
842
  columns: Record<string, {
843
+ isDefaultAnExpression?: boolean | undefined;
837
844
  isArray?: boolean | undefined;
838
845
  dimensions?: number | undefined;
839
846
  rawType?: string | undefined;
@@ -936,6 +943,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
936
943
  internal?: {
937
944
  tables: Record<string, {
938
945
  columns: Record<string, {
946
+ isDefaultAnExpression?: boolean | undefined;
939
947
  isArray?: boolean | undefined;
940
948
  dimensions?: number | undefined;
941
949
  rawType?: string | undefined;
@@ -1025,6 +1033,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1025
1033
  internal?: {
1026
1034
  tables: Record<string, {
1027
1035
  columns: Record<string, {
1036
+ isDefaultAnExpression?: boolean | undefined;
1028
1037
  isArray?: boolean | undefined;
1029
1038
  dimensions?: number | undefined;
1030
1039
  rawType?: string | undefined;
@@ -1506,6 +1515,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1506
1515
  isArray?: boolean | undefined;
1507
1516
  dimensions?: number | undefined;
1508
1517
  rawType?: string | undefined;
1518
+ isDefaultAnExpression?: boolean | undefined;
1509
1519
  } | undefined>;
1510
1520
  } | undefined>;
1511
1521
  } | undefined;
package/api.d.ts CHANGED
@@ -801,23 +801,28 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
801
801
  isArray: zod.ZodOptional<zod.ZodBoolean>;
802
802
  dimensions: zod.ZodOptional<zod.ZodNumber>;
803
803
  rawType: zod.ZodOptional<zod.ZodString>;
804
+ isDefaultAnExpression: zod.ZodOptional<zod.ZodBoolean>;
804
805
  }, "strip", zod.ZodTypeAny, {
806
+ isDefaultAnExpression?: boolean | undefined;
805
807
  isArray?: boolean | undefined;
806
808
  dimensions?: number | undefined;
807
809
  rawType?: string | undefined;
808
810
  }, {
811
+ isDefaultAnExpression?: boolean | undefined;
809
812
  isArray?: boolean | undefined;
810
813
  dimensions?: number | undefined;
811
814
  rawType?: string | undefined;
812
815
  }>>>;
813
816
  }, "strip", zod.ZodTypeAny, {
814
817
  columns: Record<string, {
818
+ isDefaultAnExpression?: boolean | undefined;
815
819
  isArray?: boolean | undefined;
816
820
  dimensions?: number | undefined;
817
821
  rawType?: string | undefined;
818
822
  } | undefined>;
819
823
  }, {
820
824
  columns: Record<string, {
825
+ isDefaultAnExpression?: boolean | undefined;
821
826
  isArray?: boolean | undefined;
822
827
  dimensions?: number | undefined;
823
828
  rawType?: string | undefined;
@@ -826,6 +831,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
826
831
  }, "strip", zod.ZodTypeAny, {
827
832
  tables: Record<string, {
828
833
  columns: Record<string, {
834
+ isDefaultAnExpression?: boolean | undefined;
829
835
  isArray?: boolean | undefined;
830
836
  dimensions?: number | undefined;
831
837
  rawType?: string | undefined;
@@ -834,6 +840,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
834
840
  }, {
835
841
  tables: Record<string, {
836
842
  columns: Record<string, {
843
+ isDefaultAnExpression?: boolean | undefined;
837
844
  isArray?: boolean | undefined;
838
845
  dimensions?: number | undefined;
839
846
  rawType?: string | undefined;
@@ -936,6 +943,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
936
943
  internal?: {
937
944
  tables: Record<string, {
938
945
  columns: Record<string, {
946
+ isDefaultAnExpression?: boolean | undefined;
939
947
  isArray?: boolean | undefined;
940
948
  dimensions?: number | undefined;
941
949
  rawType?: string | undefined;
@@ -1025,6 +1033,7 @@ declare const pgSchema: zod.ZodObject<zod.objectUtil.extendShape<{
1025
1033
  internal?: {
1026
1034
  tables: Record<string, {
1027
1035
  columns: Record<string, {
1036
+ isDefaultAnExpression?: boolean | undefined;
1028
1037
  isArray?: boolean | undefined;
1029
1038
  dimensions?: number | undefined;
1030
1039
  rawType?: string | undefined;
@@ -1506,6 +1515,7 @@ declare const upPgSnapshot: (snapshot: Record<string, unknown>) => {
1506
1515
  isArray?: boolean | undefined;
1507
1516
  dimensions?: number | undefined;
1508
1517
  rawType?: string | undefined;
1518
+ isDefaultAnExpression?: boolean | undefined;
1509
1519
  } | undefined>;
1510
1520
  } | undefined>;
1511
1521
  } | undefined;
package/api.js CHANGED
@@ -7464,11 +7464,30 @@ var init_mysqlSchema = __esm({
7464
7464
  }
7465
7465
  });
7466
7466
 
7467
+ // src/extensions/vector.ts
7468
+ var vectorOps;
7469
+ var init_vector = __esm({
7470
+ "src/extensions/vector.ts"() {
7471
+ "use strict";
7472
+ vectorOps = [
7473
+ "vector_l2_ops",
7474
+ "vector_ip_ops",
7475
+ "vector_cosine_ops",
7476
+ "vector_l1_ops",
7477
+ "bit_hamming_ops",
7478
+ "bit_jaccard_ops",
7479
+ "halfvec_l2_ops",
7480
+ "sparsevec_l2_ops"
7481
+ ];
7482
+ }
7483
+ });
7484
+
7467
7485
  // src/serializer/pgSchema.ts
7468
7486
  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;
7469
7487
  var init_pgSchema = __esm({
7470
7488
  "src/serializer/pgSchema.ts"() {
7471
7489
  "use strict";
7490
+ init_vector();
7472
7491
  init_global();
7473
7492
  init_lib();
7474
7493
  indexV2 = objectType({
@@ -7715,7 +7734,8 @@ var init_pgSchema = __esm({
7715
7734
  objectType({
7716
7735
  isArray: booleanType().optional(),
7717
7736
  dimensions: numberType().optional(),
7718
- rawType: stringType().optional()
7737
+ rawType: stringType().optional(),
7738
+ isDefaultAnExpression: booleanType().optional()
7719
7739
  }).optional()
7720
7740
  )
7721
7741
  }).optional()
@@ -7853,7 +7873,7 @@ var init_pgSchema = __esm({
7853
7873
  squashIdx: (idx) => {
7854
7874
  index2.parse(idx);
7855
7875
  return `${idx.name};${idx.columns.map(
7856
- (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass}`
7876
+ (c) => `${c.expression}--${c.isExpression}--${c.asc}--${c.nulls}--${c.opclass && vectorOps.includes(c.opclass) ? c.opclass : ""}`
7857
7877
  ).join(",,")};${idx.isUnique};${idx.concurrently};${idx.method};${idx.where};${JSON.stringify(idx.with)}`;
7858
7878
  },
7859
7879
  unsquashIdx: (input) => {
@@ -11502,7 +11522,7 @@ var init_sqlgenerator = __esm({
11502
11522
  isPgNativeType = (it) => {
11503
11523
  if (pgNativeTypes.has(it)) return true;
11504
11524
  const toCheck = it.replace(/ /g, "");
11505
- 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);
11525
+ 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);
11506
11526
  };
11507
11527
  Convertor = class {
11508
11528
  };
@@ -19373,7 +19393,7 @@ function jaccardDistance(column4, value) {
19373
19393
  }
19374
19394
  return sql`${column4} <%> ${value}`;
19375
19395
  }
19376
- var init_vector = __esm({
19396
+ var init_vector2 = __esm({
19377
19397
  "../drizzle-orm/dist/sql/functions/vector.js"() {
19378
19398
  "use strict";
19379
19399
  init_sql();
@@ -19385,7 +19405,7 @@ var init_functions = __esm({
19385
19405
  "../drizzle-orm/dist/sql/functions/index.js"() {
19386
19406
  "use strict";
19387
19407
  init_aggregate();
19388
- init_vector();
19408
+ init_vector2();
19389
19409
  }
19390
19410
  });
19391
19411
 
@@ -21049,7 +21069,7 @@ var init_sparsevec = __esm({
21049
21069
 
21050
21070
  // ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
21051
21071
  var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
21052
- var init_vector2 = __esm({
21072
+ var init_vector3 = __esm({
21053
21073
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
21054
21074
  "use strict";
21055
21075
  init_entity();
@@ -21121,7 +21141,7 @@ var init_columns = __esm({
21121
21141
  init_bit();
21122
21142
  init_halfvec();
21123
21143
  init_sparsevec();
21124
- init_vector2();
21144
+ init_vector3();
21125
21145
  }
21126
21146
  });
21127
21147
 
@@ -24619,24 +24639,6 @@ var init_pg_core = __esm({
24619
24639
  }
24620
24640
  });
24621
24641
 
24622
- // src/extensions/vector.ts
24623
- var vectorOps;
24624
- var init_vector3 = __esm({
24625
- "src/extensions/vector.ts"() {
24626
- "use strict";
24627
- vectorOps = [
24628
- "vector_l2_ops",
24629
- "vector_ip_ops",
24630
- "vector_cosine_ops",
24631
- "vector_l1_ops",
24632
- "bit_hamming_ops",
24633
- "bit_jaccard_ops",
24634
- "halfvec_l2_ops",
24635
- "sparsevec_l2_ops"
24636
- ];
24637
- }
24638
- });
24639
-
24640
24642
  // src/serializer/pgSerializer.ts
24641
24643
  function stringFromIdentityProperty(field) {
24642
24644
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
@@ -24674,7 +24676,7 @@ function buildArrayString(array, sqlType) {
24674
24676
  }).join(",");
24675
24677
  return `{${values}}`;
24676
24678
  }
24677
- var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24679
+ var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, defaultForColumn;
24678
24680
  var init_pgSerializer = __esm({
24679
24681
  "src/serializer/pgSerializer.ts"() {
24680
24682
  "use strict";
@@ -24682,7 +24684,7 @@ var init_pgSerializer = __esm({
24682
24684
  init_dist();
24683
24685
  init_pg_core();
24684
24686
  init_pg_core();
24685
- init_vector3();
24687
+ init_vector();
24686
24688
  init_outputs();
24687
24689
  init_utils();
24688
24690
  init_serializer();
@@ -24795,7 +24797,7 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
24795
24797
  columnToSet.default = `'${buildArrayString(
24796
24798
  column4.default,
24797
24799
  sqlTypeLowered
24798
- )}'::${sqlTypeLowered}`;
24800
+ )}'`;
24799
24801
  } else {
24800
24802
  columnToSet.default = column4.default;
24801
24803
  }
@@ -25142,7 +25144,7 @@ ${withStyle.errorWarning(
25142
25144
  WHEN 'int2'::regtype THEN 'smallserial'
25143
25145
  END
25144
25146
  ELSE format_type(a.atttypid, a.atttypmod)
25145
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
25147
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
25146
25148
  pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
25147
25149
  INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
25148
25150
  INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
@@ -25153,6 +25155,7 @@ ${withStyle.errorWarning(
25153
25155
  INFORMATION_SCHEMA.COLUMNS.identity_cycle
25154
25156
  FROM pg_attribute a
25155
25157
  JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
25158
+ JOIN pg_type t ON t.oid = a.atttypid LEFT JOIN pg_namespace ns ON ns.oid = t.typnamespace
25156
25159
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
25157
25160
  AND a.attnum > 0
25158
25161
  AND NOT a.attisdropped
@@ -25172,30 +25175,42 @@ ${withStyle.errorWarning(
25172
25175
  }
25173
25176
  const tableForeignKeys = await db.query(
25174
25177
  `SELECT
25175
- tc.table_schema,
25176
- tc.constraint_name,
25177
- tc.table_name,
25178
- kcu.column_name,
25179
- (
25180
- SELECT ccu.table_schema
25181
- FROM information_schema.constraint_column_usage ccu
25182
- WHERE ccu.constraint_name = tc.constraint_name
25183
- LIMIT 1
25184
- ) AS foreign_table_schema,
25185
- ccu.table_name AS foreign_table_name,
25186
- ccu.column_name AS foreign_column_name,
25187
- rc.delete_rule,
25188
- rc.update_rule
25189
- FROM
25190
- information_schema.table_constraints AS tc
25191
- JOIN information_schema.key_column_usage AS kcu
25192
- ON tc.constraint_name = kcu.constraint_name
25193
- AND tc.table_schema = kcu.table_schema
25194
- JOIN information_schema.constraint_column_usage AS ccu
25195
- ON ccu.constraint_name = tc.constraint_name
25196
- JOIN information_schema.referential_constraints AS rc
25197
- ON ccu.constraint_name = rc.constraint_name
25198
- WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
25178
+ con.contype AS constraint_type,
25179
+ nsp.nspname AS constraint_schema,
25180
+ con.conname AS constraint_name,
25181
+ rel.relname AS table_name,
25182
+ att.attname AS column_name,
25183
+ fnsp.nspname AS foreign_table_schema,
25184
+ frel.relname AS foreign_table_name,
25185
+ fatt.attname AS foreign_column_name,
25186
+ CASE con.confupdtype
25187
+ WHEN 'a' THEN 'NO ACTION'
25188
+ WHEN 'r' THEN 'RESTRICT'
25189
+ WHEN 'n' THEN 'SET NULL'
25190
+ WHEN 'c' THEN 'CASCADE'
25191
+ WHEN 'd' THEN 'SET DEFAULT'
25192
+ END AS update_rule,
25193
+ CASE con.confdeltype
25194
+ WHEN 'a' THEN 'NO ACTION'
25195
+ WHEN 'r' THEN 'RESTRICT'
25196
+ WHEN 'n' THEN 'SET NULL'
25197
+ WHEN 'c' THEN 'CASCADE'
25198
+ WHEN 'd' THEN 'SET DEFAULT'
25199
+ END AS delete_rule
25200
+ FROM
25201
+ pg_catalog.pg_constraint con
25202
+ JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
25203
+ JOIN pg_catalog.pg_namespace nsp ON nsp.oid = con.connamespace
25204
+ LEFT JOIN pg_catalog.pg_attribute att ON att.attnum = ANY (con.conkey)
25205
+ AND att.attrelid = con.conrelid
25206
+ LEFT JOIN pg_catalog.pg_class frel ON frel.oid = con.confrelid
25207
+ LEFT JOIN pg_catalog.pg_namespace fnsp ON fnsp.oid = frel.relnamespace
25208
+ LEFT JOIN pg_catalog.pg_attribute fatt ON fatt.attnum = ANY (con.confkey)
25209
+ AND fatt.attrelid = con.confrelid
25210
+ WHERE
25211
+ nsp.nspname = '${tableSchema}'
25212
+ AND rel.relname = '${tableName}'
25213
+ AND con.contype IN ('f');`
25199
25214
  );
25200
25215
  foreignKeysCount += tableForeignKeys.length;
25201
25216
  if (progressCallback) {
@@ -25207,8 +25222,8 @@ ${withStyle.errorWarning(
25207
25222
  const columnTo = fk4.foreign_column_name;
25208
25223
  const schemaTo = fk4.foreign_table_schema;
25209
25224
  const foreignKeyName = fk4.constraint_name;
25210
- const onUpdate = fk4.update_rule.toLowerCase();
25211
- const onDelete = fk4.delete_rule.toLowerCase();
25225
+ const onUpdate = fk4.update_rule?.toLowerCase();
25226
+ const onDelete = fk4.delete_rule?.toLowerCase();
25212
25227
  if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
25213
25228
  foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
25214
25229
  foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
@@ -25253,6 +25268,8 @@ ${withStyle.errorWarning(
25253
25268
  const columnDimensions = columnResponse.array_dimensions;
25254
25269
  const enumType2 = columnResponse.enum_name;
25255
25270
  let columnType = columnResponse.data_type;
25271
+ const typeSchema = columnResponse.type_schema;
25272
+ const defaultValueRes = columnResponse.column_default;
25256
25273
  const isGenerated = columnResponse.is_generated === "ALWAYS";
25257
25274
  const generationExpression = columnResponse.generation_expression;
25258
25275
  const isIdentity = columnResponse.is_identity === "YES";
@@ -25283,12 +25300,7 @@ ${withStyle.errorWarning(
25283
25300
  columns: cprimaryKey.map((c) => c.column_name)
25284
25301
  };
25285
25302
  }
25286
- const defaultValue = defaultForColumn(columnResponse);
25287
- const isSerial = columnType === "serial";
25288
25303
  let columnTypeMapped = columnType;
25289
- if (columnTypeMapped.startsWith("numeric(")) {
25290
- columnTypeMapped = columnTypeMapped.replace(",", ", ");
25291
- }
25292
25304
  if (columnAdditionalDT === "ARRAY") {
25293
25305
  if (typeof internals.tables[tableName] === "undefined") {
25294
25306
  internals.tables[tableName] = {
@@ -25316,6 +25328,34 @@ ${withStyle.errorWarning(
25316
25328
  }
25317
25329
  }
25318
25330
  }
25331
+ const defaultValue = defaultForColumn(
25332
+ columnResponse,
25333
+ internals,
25334
+ tableName
25335
+ );
25336
+ if (defaultValue === "NULL" || defaultValueRes && defaultValueRes.startsWith("(") && defaultValueRes.endsWith(")")) {
25337
+ if (typeof internals.tables[tableName] === "undefined") {
25338
+ internals.tables[tableName] = {
25339
+ columns: {
25340
+ [columnName]: {
25341
+ isDefaultAnExpression: true
25342
+ }
25343
+ }
25344
+ };
25345
+ } else {
25346
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25347
+ internals.tables[tableName].columns[columnName] = {
25348
+ isDefaultAnExpression: true
25349
+ };
25350
+ } else {
25351
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25352
+ }
25353
+ }
25354
+ }
25355
+ const isSerial = columnType === "serial";
25356
+ if (columnTypeMapped.startsWith("numeric(")) {
25357
+ columnTypeMapped = columnTypeMapped.replace(",", ", ");
25358
+ }
25319
25359
  if (columnAdditionalDT === "ARRAY") {
25320
25360
  for (let i = 1; i < Number(columnDimensions); i++) {
25321
25361
  columnTypeMapped += "[]";
@@ -25329,7 +25369,7 @@ ${withStyle.errorWarning(
25329
25369
  // filter vectors, but in future we should filter any extension that was installed by user
25330
25370
  columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
25331
25371
  ),
25332
- typeSchema: enumsToReturn[`${tableSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${tableSchema}.${enumType2}`].schema : void 0,
25372
+ typeSchema: enumsToReturn[`${typeSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${typeSchema}.${enumType2}`].schema : void 0,
25333
25373
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
25334
25374
  // default: isSerial ? undefined : defaultValue,
25335
25375
  notNull: columnResponse.is_nullable === "NO",
@@ -25347,7 +25387,7 @@ ${withStyle.errorWarning(
25347
25387
  } : void 0
25348
25388
  };
25349
25389
  if (identityName) {
25350
- delete sequencesToReturn[`${tableSchema}.${identityName}`];
25390
+ delete sequencesToReturn[`${tableSchema}.${identityName.startsWith('"') && identityName.endsWith('"') ? identityName.slice(1, -1) : identityName}`];
25351
25391
  delete sequencesToReturn[identityName];
25352
25392
  }
25353
25393
  if (!isSerial && typeof defaultValue !== "undefined") {
@@ -25500,59 +25540,71 @@ ${withStyle.errorWarning(
25500
25540
  internal: internals
25501
25541
  };
25502
25542
  };
25503
- columnToDefault = {
25504
- "numeric(": "::numeric",
25505
- // text: "::text",
25506
- // "character varying": "::character varying",
25507
- // "double precision": "::double precision",
25508
- // "time with time zone": "::time with time zone",
25509
- "time without time zone": "::time without time zone",
25510
- // "timestamp with time zone": "::timestamp with time zone",
25511
- "timestamp without time zone": "::timestamp without time zone",
25512
- "timestamp(": "::timestamp without time zone",
25513
- // date: "::date",
25514
- // interval: "::interval",
25515
- // character: "::bpchar",
25516
- // macaddr8: "::macaddr8",
25517
- // macaddr: "::macaddr",
25518
- // inet: "::inet",
25519
- // cidr: "::cidr",
25520
- // jsonb: "::jsonb",
25521
- // json: "::json",
25522
- "character(": "::bpchar"
25523
- };
25524
- defaultForColumn = (column4) => {
25543
+ defaultForColumn = (column4, internals, tableName) => {
25544
+ const columnName = column4.attname;
25545
+ const isArray = internals?.tables[tableName]?.columns[columnName]?.isArray ?? false;
25525
25546
  if (column4.column_default === null) {
25526
25547
  return void 0;
25527
25548
  }
25528
25549
  if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
25529
25550
  return void 0;
25530
25551
  }
25531
- const hasDifferentDefaultCast = Object.keys(columnToDefault).find((it) => column4.data_type.startsWith(it));
25552
+ if (column4.column_default.endsWith("[]")) {
25553
+ column4.column_default = column4.column_default.slice(0, -2);
25554
+ }
25555
+ column4.column_default = column4.column_default.replace(/::(.*?)(?<![^\w"])(?=$)/, "");
25532
25556
  const columnDefaultAsString = column4.column_default.toString();
25533
- if (columnDefaultAsString.endsWith(
25534
- hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
25535
- )) {
25536
- const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
25537
- const rt = column4.column_default.toString().substring(1, nonPrefixPart);
25538
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
25539
- return Number(rt);
25540
- } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25541
- const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
25542
- return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
25543
- } else if (column4.data_type === "boolean") {
25544
- return column4.column_default === "true";
25545
- } else {
25546
- return `'${rt}'`;
25547
- }
25548
- } else {
25549
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column4.data_type.startsWith("numeric")) {
25557
+ if (isArray) {
25558
+ return `'{${columnDefaultAsString.slice(2, -2).split(/\s*,\s*/g).map((value) => {
25559
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type.slice(0, -2))) {
25560
+ return value;
25561
+ } else if (column4.data_type.startsWith("timestamp")) {
25562
+ return `${value}`;
25563
+ } else if (column4.data_type.slice(0, -2) === "interval") {
25564
+ return value.replaceAll('"', `"`);
25565
+ } else if (column4.data_type.slice(0, -2) === "boolean") {
25566
+ return value === "t" ? "true" : "false";
25567
+ } else if (["json", "jsonb"].includes(column4.data_type.slice(0, -2))) {
25568
+ return JSON.stringify(JSON.stringify(JSON.parse(JSON.parse(value)), null, 0));
25569
+ } else {
25570
+ return `"${value}"`;
25571
+ }
25572
+ }).join(",")}}'`;
25573
+ }
25574
+ if (["integer", "smallint", "bigint", "double precision", "real"].includes(column4.data_type)) {
25575
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString)) {
25550
25576
  return Number(columnDefaultAsString);
25551
- } else if (column4.data_type === "boolean") {
25552
- return column4.column_default === "true";
25553
25577
  } else {
25554
- return `${columnDefaultAsString}`;
25578
+ if (typeof internals.tables[tableName] === "undefined") {
25579
+ internals.tables[tableName] = {
25580
+ columns: {
25581
+ [columnName]: {
25582
+ isDefaultAnExpression: true
25583
+ }
25584
+ }
25585
+ };
25586
+ } else {
25587
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25588
+ internals.tables[tableName].columns[columnName] = {
25589
+ isDefaultAnExpression: true
25590
+ };
25591
+ } else {
25592
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25593
+ }
25594
+ }
25595
+ return columnDefaultAsString;
25555
25596
  }
25597
+ } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25598
+ const jsonWithoutSpaces = JSON.stringify(JSON.parse(columnDefaultAsString.slice(1, -1)));
25599
+ return `'${jsonWithoutSpaces}'::${column4.data_type}`;
25600
+ } else if (column4.data_type === "boolean") {
25601
+ return column4.column_default === "true";
25602
+ } else if (columnDefaultAsString === "NULL") {
25603
+ return `NULL`;
25604
+ } else if (columnDefaultAsString.startsWith("'") && columnDefaultAsString.endsWith("'")) {
25605
+ return columnDefaultAsString;
25606
+ } else {
25607
+ return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
25556
25608
  }
25557
25609
  };
25558
25610
  }
@@ -33880,9 +33932,9 @@ var init_cli = __esm({
33880
33932
  tablesFilter: unionType([stringType(), stringType().array()]).optional(),
33881
33933
  schemaFilter: unionType([stringType(), stringType().array()]).optional().default(["public"]),
33882
33934
  extensionsFilters: literalType("postgis").array().optional(),
33883
- introspectCasing: casing,
33935
+ casing,
33884
33936
  breakpoints: booleanType().optional().default(true),
33885
- database: objectType({
33937
+ migrations: objectType({
33886
33938
  prefix: prefix.optional().default("index")
33887
33939
  }).optional()
33888
33940
  }).passthrough();