drizzle-kit 0.24.0-6386ea9 → 0.24.0-8d86512

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) => {
@@ -19378,7 +19398,7 @@ function jaccardDistance(column4, value) {
19378
19398
  }
19379
19399
  return sql`${column4} <%> ${value}`;
19380
19400
  }
19381
- var init_vector = __esm({
19401
+ var init_vector2 = __esm({
19382
19402
  "../drizzle-orm/dist/sql/functions/vector.js"() {
19383
19403
  "use strict";
19384
19404
  init_sql();
@@ -19390,7 +19410,7 @@ var init_functions = __esm({
19390
19410
  "../drizzle-orm/dist/sql/functions/index.js"() {
19391
19411
  "use strict";
19392
19412
  init_aggregate();
19393
- init_vector();
19413
+ init_vector2();
19394
19414
  }
19395
19415
  });
19396
19416
 
@@ -21054,7 +21074,7 @@ var init_sparsevec = __esm({
21054
21074
 
21055
21075
  // ../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js
21056
21076
  var _a122, _b95, PgVectorBuilder, _a123, _b96, PgVector;
21057
- var init_vector2 = __esm({
21077
+ var init_vector3 = __esm({
21058
21078
  "../drizzle-orm/dist/pg-core/columns/vector_extension/vector.js"() {
21059
21079
  "use strict";
21060
21080
  init_entity();
@@ -21126,7 +21146,7 @@ var init_columns = __esm({
21126
21146
  init_bit();
21127
21147
  init_halfvec();
21128
21148
  init_sparsevec();
21129
- init_vector2();
21149
+ init_vector3();
21130
21150
  }
21131
21151
  });
21132
21152
 
@@ -24624,24 +24644,6 @@ var init_pg_core = __esm({
24624
24644
  }
24625
24645
  });
24626
24646
 
24627
- // src/extensions/vector.ts
24628
- var vectorOps;
24629
- var init_vector3 = __esm({
24630
- "src/extensions/vector.ts"() {
24631
- "use strict";
24632
- vectorOps = [
24633
- "vector_l2_ops",
24634
- "vector_ip_ops",
24635
- "vector_cosine_ops",
24636
- "vector_l1_ops",
24637
- "bit_hamming_ops",
24638
- "bit_jaccard_ops",
24639
- "halfvec_l2_ops",
24640
- "sparsevec_l2_ops"
24641
- ];
24642
- }
24643
- });
24644
-
24645
24647
  // src/serializer/pgSerializer.ts
24646
24648
  function stringFromIdentityProperty(field) {
24647
24649
  return typeof field === "string" ? field : typeof field === "undefined" ? void 0 : String(field);
@@ -24679,7 +24681,7 @@ function buildArrayString(array, sqlType) {
24679
24681
  }).join(",");
24680
24682
  return `{${values}}`;
24681
24683
  }
24682
- var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, defaultForColumn;
24684
+ var dialect4, indexName, generatePgSnapshot, trimChar, fromDatabase, columnToDefault, columnEnumNameToDefault, defaultForColumn;
24683
24685
  var init_pgSerializer = __esm({
24684
24686
  "src/serializer/pgSerializer.ts"() {
24685
24687
  "use strict";
@@ -24687,7 +24689,7 @@ var init_pgSerializer = __esm({
24687
24689
  init_dist();
24688
24690
  init_pg_core();
24689
24691
  init_pg_core();
24690
- init_vector3();
24692
+ init_vector();
24691
24693
  init_outputs();
24692
24694
  init_utils();
24693
24695
  init_serializer();
@@ -25147,7 +25149,7 @@ ${withStyle.errorWarning(
25147
25149
  WHEN 'int2'::regtype THEN 'smallserial'
25148
25150
  END
25149
25151
  ELSE format_type(a.atttypid, a.atttypmod)
25150
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name,
25152
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, ns.nspname as type_schema,
25151
25153
  pg_get_serial_sequence('"${tableSchema}"."${tableName}"', a.attname)::regclass as seq_name, INFORMATION_SCHEMA.COLUMNS.column_name,
25152
25154
  INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt,
25153
25155
  INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name,
@@ -25158,6 +25160,7 @@ ${withStyle.errorWarning(
25158
25160
  INFORMATION_SCHEMA.COLUMNS.identity_cycle
25159
25161
  FROM pg_attribute a
25160
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
25161
25164
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
25162
25165
  AND a.attnum > 0
25163
25166
  AND NOT a.attisdropped
@@ -25177,30 +25180,42 @@ ${withStyle.errorWarning(
25177
25180
  }
25178
25181
  const tableForeignKeys = await db.query(
25179
25182
  `SELECT
25180
- tc.table_schema,
25181
- tc.constraint_name,
25182
- tc.table_name,
25183
- kcu.column_name,
25184
- (
25185
- SELECT ccu.table_schema
25186
- FROM information_schema.constraint_column_usage ccu
25187
- WHERE ccu.constraint_name = tc.constraint_name
25188
- LIMIT 1
25189
- ) AS foreign_table_schema,
25190
- ccu.table_name AS foreign_table_name,
25191
- ccu.column_name AS foreign_column_name,
25192
- rc.delete_rule,
25193
- rc.update_rule
25194
- FROM
25195
- information_schema.table_constraints AS tc
25196
- JOIN information_schema.key_column_usage AS kcu
25197
- ON tc.constraint_name = kcu.constraint_name
25198
- AND tc.table_schema = kcu.table_schema
25199
- JOIN information_schema.constraint_column_usage AS ccu
25200
- ON ccu.constraint_name = tc.constraint_name
25201
- JOIN information_schema.referential_constraints AS rc
25202
- ON ccu.constraint_name = rc.constraint_name
25203
- 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');`
25204
25219
  );
25205
25220
  foreignKeysCount += tableForeignKeys.length;
25206
25221
  if (progressCallback) {
@@ -25258,6 +25273,7 @@ ${withStyle.errorWarning(
25258
25273
  const columnDimensions = columnResponse.array_dimensions;
25259
25274
  const enumType2 = columnResponse.enum_name;
25260
25275
  let columnType = columnResponse.data_type;
25276
+ const typeSchema = columnResponse.type_schema;
25261
25277
  const isGenerated = columnResponse.is_generated === "ALWAYS";
25262
25278
  const generationExpression = columnResponse.generation_expression;
25263
25279
  const isIdentity = columnResponse.is_identity === "YES";
@@ -25289,6 +25305,25 @@ ${withStyle.errorWarning(
25289
25305
  };
25290
25306
  }
25291
25307
  const defaultValue = defaultForColumn(columnResponse);
25308
+ if (defaultValue === "NULL") {
25309
+ if (typeof internals.tables[tableName] === "undefined") {
25310
+ internals.tables[tableName] = {
25311
+ columns: {
25312
+ [columnName]: {
25313
+ isDefaultAnExpression: true
25314
+ }
25315
+ }
25316
+ };
25317
+ } else {
25318
+ if (typeof internals.tables[tableName].columns[columnName] === "undefined") {
25319
+ internals.tables[tableName].columns[columnName] = {
25320
+ isDefaultAnExpression: true
25321
+ };
25322
+ } else {
25323
+ internals.tables[tableName].columns[columnName].isDefaultAnExpression = true;
25324
+ }
25325
+ }
25326
+ }
25292
25327
  const isSerial = columnType === "serial";
25293
25328
  let columnTypeMapped = columnType;
25294
25329
  if (columnTypeMapped.startsWith("numeric(")) {
@@ -25334,7 +25369,7 @@ ${withStyle.errorWarning(
25334
25369
  // filter vectors, but in future we should filter any extension that was installed by user
25335
25370
  columnAdditionalDT === "USER-DEFINED" && !["vector", "geometry"].includes(enumType2) ? enumType2 : columnTypeMapped
25336
25371
  ),
25337
- 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,
25338
25373
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
25339
25374
  // default: isSerial ? undefined : defaultValue,
25340
25375
  notNull: columnResponse.is_nullable === "NO",
@@ -25508,11 +25543,11 @@ ${withStyle.errorWarning(
25508
25543
  columnToDefault = {
25509
25544
  "numeric(": "::numeric",
25510
25545
  // text: "::text",
25511
- // "character varying": "::character varying",
25546
+ "character varying": "::character varying",
25512
25547
  // "double precision": "::double precision",
25513
25548
  // "time with time zone": "::time with time zone",
25514
25549
  "time without time zone": "::time without time zone",
25515
- // "timestamp with time zone": "::timestamp with time zone",
25550
+ // 'timestamp with time zone': '::timestamp with time zone',
25516
25551
  "timestamp without time zone": "::timestamp without time zone",
25517
25552
  "timestamp(": "::timestamp without time zone",
25518
25553
  // date: "::date",
@@ -25526,6 +25561,12 @@ ${withStyle.errorWarning(
25526
25561
  // json: "::json",
25527
25562
  "character(": "::bpchar"
25528
25563
  };
25564
+ columnEnumNameToDefault = {
25565
+ timestamptz: "::timestamp with time zone",
25566
+ timestmap: "::time without time zone",
25567
+ time: "::time without time zone",
25568
+ timetz: "::time with time zone"
25569
+ };
25529
25570
  defaultForColumn = (column4) => {
25530
25571
  if (column4.column_default === null) {
25531
25572
  return void 0;
@@ -25534,19 +25575,33 @@ ${withStyle.errorWarning(
25534
25575
  return void 0;
25535
25576
  }
25536
25577
  const hasDifferentDefaultCast = Object.keys(columnToDefault).find((it) => column4.data_type.startsWith(it));
25578
+ const hasDifferentDefaultCastForEnum = Object.keys(columnEnumNameToDefault).find(
25579
+ (it) => column4.enum_name.startsWith(it)
25580
+ );
25537
25581
  const columnDefaultAsString = column4.column_default.toString();
25538
- if (columnDefaultAsString.endsWith(
25582
+ const endsWithEnumName = columnDefaultAsString.endsWith(
25583
+ hasDifferentDefaultCastForEnum ? columnEnumNameToDefault[hasDifferentDefaultCastForEnum] : column4.data_type
25584
+ );
25585
+ const endsWithTypeName = columnDefaultAsString.endsWith(
25539
25586
  hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
25540
- )) {
25587
+ );
25588
+ if (endsWithTypeName || endsWithEnumName) {
25541
25589
  const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
25542
- const rt = column4.column_default.toString().substring(1, nonPrefixPart);
25590
+ let rt = column4.column_default.toString().substring(0, nonPrefixPart + 1);
25543
25591
  if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
25544
25592
  return Number(rt);
25545
25593
  } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
25594
+ if (rt.startsWith("'")) {
25595
+ rt = rt.slice(1, -1);
25596
+ }
25546
25597
  const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
25547
25598
  return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
25548
25599
  } else if (column4.data_type === "boolean") {
25549
25600
  return column4.column_default === "true";
25601
+ } else if (rt === "NULL") {
25602
+ return `NULL`;
25603
+ } else if (rt.startsWith("'") && rt.endsWith("'")) {
25604
+ return rt;
25550
25605
  } else {
25551
25606
  return `'${rt}'`;
25552
25607
  }
@@ -25555,8 +25610,10 @@ ${withStyle.errorWarning(
25555
25610
  return Number(columnDefaultAsString);
25556
25611
  } else if (column4.data_type === "boolean") {
25557
25612
  return column4.column_default === "true";
25613
+ } else if (columnDefaultAsString === "NULL") {
25614
+ return `NULL`;
25558
25615
  } else {
25559
- return `${columnDefaultAsString}`;
25616
+ return `${columnDefaultAsString.replace(/\\/g, "`\\")}`;
25560
25617
  }
25561
25618
  }
25562
25619
  };
@@ -33887,7 +33944,7 @@ var init_cli = __esm({
33887
33944
  extensionsFilters: literalType("postgis").array().optional(),
33888
33945
  introspectCasing: casing,
33889
33946
  breakpoints: booleanType().optional().default(true),
33890
- database: objectType({
33947
+ migrations: objectType({
33891
33948
  prefix: prefix.optional().default("index")
33892
33949
  }).optional()
33893
33950
  }).passthrough();