drizzle-kit 0.20.8 → 0.20.9-03fb33f

Sign up to get free protection for your applications and to get access to all the features.
package/utils.d.ts CHANGED
@@ -106,6 +106,7 @@ export declare const statementsForDiffs: (in1: any, in2: any) => Promise<{
106
106
  columnsFrom: string[];
107
107
  tableTo: string;
108
108
  columnsTo: string[];
109
+ schemaTo: string;
109
110
  }>;
110
111
  schema: string;
111
112
  compositePrimaryKeys: Record<string, {
@@ -168,6 +169,7 @@ export declare const statementsForDiffs: (in1: any, in2: any) => Promise<{
168
169
  columnsFrom: string[];
169
170
  tableTo: string;
170
171
  columnsTo: string[];
172
+ schemaTo: string;
171
173
  }>;
172
174
  schema: string;
173
175
  compositePrimaryKeys: Record<string, {
package/utils.js CHANGED
@@ -4817,6 +4817,7 @@ var init_pgSchema = __esm({
4817
4817
  tableFrom: stringType(),
4818
4818
  columnsFrom: stringType().array(),
4819
4819
  tableTo: stringType(),
4820
+ schemaTo: stringType(),
4820
4821
  columnsTo: stringType().array(),
4821
4822
  onUpdate: stringType().optional(),
4822
4823
  onDelete: stringType().optional()
@@ -4974,7 +4975,7 @@ var init_pgSchema = __esm({
4974
4975
  return result;
4975
4976
  },
4976
4977
  squashFK: (fk4) => {
4977
- return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""}`;
4978
+ return `${fk4.name};${fk4.tableFrom};${fk4.columnsFrom.join(",")};${fk4.tableTo};${fk4.columnsTo.join(",")};${fk4.onUpdate ?? ""};${fk4.onDelete ?? ""};${fk4.schemaTo ?? ""}`;
4978
4979
  },
4979
4980
  squashPK: (pk) => {
4980
4981
  return `${pk.columns.join(",")};${pk.name}`;
@@ -5002,12 +5003,14 @@ var init_pgSchema = __esm({
5002
5003
  tableTo,
5003
5004
  columnsToStr,
5004
5005
  onUpdate,
5005
- onDelete
5006
+ onDelete,
5007
+ schemaTo
5006
5008
  ] = input.split(";");
5007
5009
  const result = fk2.parse({
5008
5010
  name,
5009
5011
  tableFrom,
5010
5012
  columnsFrom: columnsFromStr.split(","),
5013
+ schemaTo,
5011
5014
  tableTo,
5012
5015
  columnsTo: columnsToStr.split(","),
5013
5016
  onUpdate,
@@ -11898,10 +11901,9 @@ var pgSerializer_exports = {};
11898
11901
  __export(pgSerializer_exports, {
11899
11902
  fromDatabase: () => fromDatabase2,
11900
11903
  generatePgSnapshot: () => generatePgSnapshot,
11901
- indexName: () => indexName2,
11902
- toDrizzle: () => toDrizzle
11904
+ indexName: () => indexName2
11903
11905
  });
11904
- var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn, toDrizzle;
11906
+ var import_pg_core2, import_pg_core3, import_drizzle_orm5, dialect4, indexName2, generatePgSnapshot, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
11905
11907
  var init_pgSerializer = __esm({
11906
11908
  "src/serializer/pgSerializer.ts"() {
11907
11909
  import_pg_core2 = require("drizzle-orm/pg-core");
@@ -12039,12 +12041,14 @@ ${withStyle.errorWarning(`We've found duplicated unique constraint names in ${so
12039
12041
  const onUpdate = fk4.onUpdate;
12040
12042
  const reference = fk4.reference();
12041
12043
  const tableTo = (0, import_drizzle_orm5.getTableName)(reference.foreignTable);
12044
+ const schemaTo = (0, import_pg_core3.getTableConfig)(reference.foreignTable).schema;
12042
12045
  const columnsFrom = reference.columns.map((it) => it.name);
12043
12046
  const columnsTo = reference.foreignColumns.map((it) => it.name);
12044
12047
  return {
12045
12048
  name,
12046
12049
  tableFrom,
12047
12050
  tableTo,
12051
+ schemaTo,
12048
12052
  columnsFrom,
12049
12053
  columnsTo,
12050
12054
  onDelete,
@@ -12221,24 +12225,29 @@ ${withStyle.errorWarning(
12221
12225
  }
12222
12226
  const tableForeignKeys = await db.query(
12223
12227
  `SELECT
12224
- tc.table_schema,
12225
- tc.constraint_name,
12226
- tc.table_name,
12227
- kcu.column_name,
12228
- ccu.table_schema AS foreign_table_schema,
12229
- ccu.table_name AS foreign_table_name,
12230
- ccu.column_name AS foreign_column_name,
12231
- rc.delete_rule, rc.update_rule
12232
- FROM
12233
- information_schema.table_constraints AS tc
12234
- JOIN information_schema.key_column_usage AS kcu
12235
- ON tc.constraint_name = kcu.constraint_name
12236
- AND tc.table_schema = kcu.table_schema
12237
- JOIN information_schema.constraint_column_usage AS ccu
12238
- ON ccu.constraint_name = tc.constraint_name
12239
- AND ccu.table_schema = tc.table_schema
12240
- JOIN information_schema.referential_constraints AS rc
12241
- ON ccu.constraint_name = rc.constraint_name
12228
+ tc.table_schema,
12229
+ tc.constraint_name,
12230
+ tc.table_name,
12231
+ kcu.column_name,
12232
+ (
12233
+ SELECT ccu.table_schema
12234
+ FROM information_schema.constraint_column_usage ccu
12235
+ WHERE ccu.constraint_name = tc.constraint_name
12236
+ LIMIT 1
12237
+ ) AS foreign_table_schema,
12238
+ ccu.table_name AS foreign_table_name,
12239
+ ccu.column_name AS foreign_column_name,
12240
+ rc.delete_rule,
12241
+ rc.update_rule
12242
+ FROM
12243
+ information_schema.table_constraints AS tc
12244
+ JOIN information_schema.key_column_usage AS kcu
12245
+ ON tc.constraint_name = kcu.constraint_name
12246
+ AND tc.table_schema = kcu.table_schema
12247
+ JOIN information_schema.constraint_column_usage AS ccu
12248
+ ON ccu.constraint_name = tc.constraint_name
12249
+ JOIN information_schema.referential_constraints AS rc
12250
+ ON ccu.constraint_name = rc.constraint_name
12242
12251
  WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name='${tableName}' and tc.table_schema='${tableSchema}';`
12243
12252
  );
12244
12253
  foreignKeysCount += tableForeignKeys.length;
@@ -12249,6 +12258,7 @@ ${withStyle.errorWarning(
12249
12258
  const columnFrom = fk4.column_name;
12250
12259
  const tableTo = fk4.foreign_table_name;
12251
12260
  const columnTo = fk4.foreign_column_name;
12261
+ const schemaTo = fk4.foreign_table_schema;
12252
12262
  const foreignKeyName = fk4.constraint_name;
12253
12263
  const onUpdate = fk4.update_rule.toLowerCase();
12254
12264
  const onDelete = fk4.delete_rule.toLowerCase();
@@ -12260,6 +12270,7 @@ ${withStyle.errorWarning(
12260
12270
  name: foreignKeyName,
12261
12271
  tableFrom: tableName,
12262
12272
  tableTo,
12273
+ schemaTo,
12263
12274
  columnsFrom: [columnFrom],
12264
12275
  columnsTo: [columnTo],
12265
12276
  onDelete,
@@ -12531,108 +12542,6 @@ ${withStyle.errorWarning(
12531
12542
  }
12532
12543
  }
12533
12544
  };
12534
- toDrizzle = (schema4, schemaName) => {
12535
- const tables = {};
12536
- Object.values(schema4.tables).forEach((t) => {
12537
- const columns = {};
12538
- Object.values(t.columns).forEach((c) => {
12539
- const columnName = c.name;
12540
- const type = c.type;
12541
- let columnBuilder;
12542
- if (type === "bigint") {
12543
- columnBuilder = new import_pg_core2.PgBigInt53Builder(columnName);
12544
- } else if (type === "bigserial") {
12545
- columnBuilder = new import_pg_core2.PgBigSerial53Builder(columnName);
12546
- } else if (type === "boolean") {
12547
- columnBuilder = new import_pg_core2.PgBooleanBuilder(columnName);
12548
- } else if (type === "cidr") {
12549
- columnBuilder = new import_pg_core2.PgCidrBuilder(columnName);
12550
- } else if (type === "date") {
12551
- columnBuilder = new import_pg_core2.PgDateBuilder(columnName);
12552
- } else if (type === "double precision") {
12553
- columnBuilder = new import_pg_core2.PgDoublePrecisionBuilder(columnName);
12554
- } else if (type === "inet") {
12555
- columnBuilder = new import_pg_core2.PgInetBuilder(columnName);
12556
- } else if (type === "integer") {
12557
- columnBuilder = new import_pg_core2.PgIntegerBuilder(columnName);
12558
- } else if (type === "interval" || type.startsWith("interval ")) {
12559
- columnBuilder = new import_pg_core2.PgIntervalBuilder(columnName, {});
12560
- } else if (type === "json") {
12561
- columnBuilder = new import_pg_core2.PgJsonBuilder(columnName);
12562
- } else if (type === "jsonb") {
12563
- columnBuilder = new import_pg_core2.PgJsonbBuilder(columnName);
12564
- } else if (type === "macaddr") {
12565
- columnBuilder = new import_pg_core2.PgMacaddrBuilder(columnName);
12566
- } else if (type === "macaddr8") {
12567
- columnBuilder = new import_pg_core2.PgMacaddr8Builder(columnName);
12568
- } else if (type === "numeric" || type.startsWith("numeric(")) {
12569
- columnBuilder = new import_pg_core2.PgNumericBuilder(columnName);
12570
- } else if (type === "real") {
12571
- columnBuilder = new import_pg_core2.PgRealBuilder(columnName);
12572
- } else if (type === "serial") {
12573
- columnBuilder = new import_pg_core2.PgSerialBuilder(columnName);
12574
- } else if (type === "smallint") {
12575
- columnBuilder = new import_pg_core2.PgSmallIntBuilder(columnName);
12576
- } else if (type === "smallserial") {
12577
- columnBuilder = new import_pg_core2.PgSmallSerialBuilder(columnName);
12578
- } else if (type === "text") {
12579
- columnBuilder = new import_pg_core2.PgTextBuilder(columnName, {});
12580
- } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
12581
- columnBuilder = new import_pg_core2.PgTimeBuilder(columnName, false, void 0);
12582
- } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
12583
- columnBuilder = new import_pg_core2.PgTimestampBuilder(columnName, false, void 0);
12584
- } else if (type === "uuid") {
12585
- columnBuilder = new import_pg_core2.PgUUIDBuilder(columnName);
12586
- } else if (type === "varchar" || type.startsWith("varchar(")) {
12587
- columnBuilder = new import_pg_core2.PgVarcharBuilder(columnName, {});
12588
- } else if (type === "char" || type.startsWith("char(")) {
12589
- columnBuilder = new import_pg_core2.PgCharBuilder(columnName, {});
12590
- } else {
12591
- columnBuilder = (0, import_pg_core2.customType)({
12592
- dataType() {
12593
- return type;
12594
- }
12595
- })(columnName);
12596
- }
12597
- if (c.notNull) {
12598
- columnBuilder = columnBuilder.notNull();
12599
- }
12600
- if (c.default) {
12601
- columnBuilder = columnBuilder.default(c.default);
12602
- }
12603
- if (c.primaryKey) {
12604
- columnBuilder = columnBuilder.primaryKey();
12605
- }
12606
- columns[columnName] = columnBuilder;
12607
- });
12608
- if (schemaName === "public") {
12609
- tables[t.name] = (0, import_pg_core2.pgTable)(t.name, columns, (cb) => {
12610
- const res = {};
12611
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12612
- const gh = cpk.columns.map((c) => cb[c]);
12613
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12614
- gh,
12615
- cpk.name
12616
- );
12617
- });
12618
- return res;
12619
- });
12620
- } else {
12621
- tables[t.name] = (0, import_pg_core2.pgSchema)(schemaName).table(t.name, columns, (cb) => {
12622
- const res = {};
12623
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
12624
- const gh = cpk.columns.map((c) => cb[c]);
12625
- res[cpk.name] = new import_pg_core2.PrimaryKeyBuilder(
12626
- gh,
12627
- cpk.name
12628
- );
12629
- });
12630
- return res;
12631
- });
12632
- }
12633
- });
12634
- return tables;
12635
- };
12636
12545
  }
12637
12546
  });
12638
12547
 
@@ -12671,8 +12580,7 @@ var init_sqliteImports = __esm({
12671
12580
  var sqliteSerializer_exports = {};
12672
12581
  __export(sqliteSerializer_exports, {
12673
12582
  fromDatabase: () => fromDatabase3,
12674
- generateSqliteSnapshot: () => generateSqliteSnapshot,
12675
- toDrizzle: () => toDrizzle2
12583
+ generateSqliteSnapshot: () => generateSqliteSnapshot
12676
12584
  });
12677
12585
  function mapSqlToSqliteType(sqlType) {
12678
12586
  if ([
@@ -12709,7 +12617,7 @@ function mapSqlToSqliteType(sqlType) {
12709
12617
  return "numeric";
12710
12618
  }
12711
12619
  }
12712
- var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3, toDrizzle2;
12620
+ var import_drizzle_orm7, import_sqlite_core2, dialect5, generateSqliteSnapshot, fromDatabase3;
12713
12621
  var init_sqliteSerializer = __esm({
12714
12622
  "src/serializer/sqliteSerializer.ts"() {
12715
12623
  import_drizzle_orm7 = require("drizzle-orm");
@@ -13077,50 +12985,6 @@ WHERE
13077
12985
  }
13078
12986
  };
13079
12987
  };
13080
- toDrizzle2 = (schema4) => {
13081
- const tables = {};
13082
- Object.values(schema4.tables).forEach((t) => {
13083
- const columns = {};
13084
- Object.values(t.columns).forEach((c) => {
13085
- const columnName = c.name;
13086
- const type = c.type;
13087
- let columnBuilder;
13088
- if (type === "integer") {
13089
- columnBuilder = new import_sqlite_core2.SQLiteIntegerBuilder(columnName);
13090
- } else if (type === "text") {
13091
- columnBuilder = new import_sqlite_core2.SQLiteTextBuilder(columnName, {});
13092
- } else if (type === "blob") {
13093
- columnBuilder = new import_sqlite_core2.SQLiteBlobBufferBuilder(columnName);
13094
- } else if (type === "real") {
13095
- columnBuilder = new import_sqlite_core2.SQLiteRealBuilder(columnName);
13096
- } else {
13097
- columnBuilder = new import_sqlite_core2.SQLiteNumericBuilder(columnName);
13098
- }
13099
- if (c.notNull) {
13100
- columnBuilder = columnBuilder.notNull();
13101
- }
13102
- if (c.default) {
13103
- columnBuilder = columnBuilder.default(c.default);
13104
- }
13105
- if (c.primaryKey) {
13106
- columnBuilder = columnBuilder.primaryKey();
13107
- }
13108
- columns[columnName] = columnBuilder;
13109
- });
13110
- tables[t.name] = (0, import_sqlite_core2.sqliteTable)(t.name, columns, (cb) => {
13111
- const res = {};
13112
- Object.values(t.compositePrimaryKeys).forEach((cpk) => {
13113
- const gh = cpk.columns.map((c) => cb[c]);
13114
- res[cpk.name] = new import_sqlite_core2.PrimaryKeyBuilder(
13115
- gh,
13116
- cpk.name
13117
- );
13118
- });
13119
- return res;
13120
- });
13121
- });
13122
- return tables;
13123
- };
13124
12988
  }
13125
12989
  });
13126
12990
 
@@ -16031,14 +15895,15 @@ ${BREAKPOINT}ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT ${statement.newCo
16031
15895
  columnsFrom,
16032
15896
  columnsTo,
16033
15897
  onDelete,
16034
- onUpdate
15898
+ onUpdate,
15899
+ schemaTo
16035
15900
  } = PgSquasher.unsquashFK(statement.data);
16036
15901
  const onDeleteStatement = onDelete ? ` ON DELETE ${onDelete}` : "";
16037
15902
  const onUpdateStatement = onUpdate ? ` ON UPDATE ${onUpdate}` : "";
16038
15903
  const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
16039
15904
  const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
16040
15905
  const tableNameWithSchema = statement.schema ? `"${statement.schema}"."${tableFrom}"` : `"${tableFrom}"`;
16041
- const tableToNameWithSchema = statement.schema ? `"${statement.schema}"."${tableTo}"` : `"${tableTo}"`;
15906
+ const tableToNameWithSchema = statement.schema ? `"${schemaTo}"."${tableTo}"` : `"${tableTo}"`;
16042
15907
  const alterStatement = `ALTER TABLE ${tableNameWithSchema} ADD CONSTRAINT "${name}" FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableToNameWithSchema}(${toColumnsString})${onDeleteStatement}${onUpdateStatement}`;
16043
15908
  let sql2 = "DO $$ BEGIN\n";
16044
15909
  sql2 += " " + alterStatement + ";\n";
@@ -18095,7 +17960,7 @@ var init_introspect_pg = __esm({
18095
17960
  const schemaStatements = Object.entries(schemas).map((it) => {
18096
17961
  return `export const ${it[1]} = pgSchema("${it[0]}");
18097
17962
  `;
18098
- }).join();
17963
+ }).join("");
18099
17964
  const tableStatements = Object.values(schema4.tables).map((table4) => {
18100
17965
  const tableSchema = schemas[table4.schema];
18101
17966
  const func = tableSchema ? `${tableSchema}.table` : "pgTable";
@@ -24908,6 +24773,161 @@ var init_sqliteIntrospect = __esm({
24908
24773
  }
24909
24774
  });
24910
24775
 
24776
+ // src/serializer/schemaToDrizzle.ts
24777
+ var import_pg_core4, import_sqlite_core3, pgSchemaToDrizzle, sqliteSchemaToDrizzle;
24778
+ var init_schemaToDrizzle = __esm({
24779
+ "src/serializer/schemaToDrizzle.ts"() {
24780
+ import_pg_core4 = require("drizzle-orm/pg-core");
24781
+ import_sqlite_core3 = require("drizzle-orm/sqlite-core");
24782
+ pgSchemaToDrizzle = (schema4, schemaName) => {
24783
+ const tables = {};
24784
+ Object.values(schema4.tables).forEach((t) => {
24785
+ const columns = {};
24786
+ Object.values(t.columns).forEach((c) => {
24787
+ const columnName = c.name;
24788
+ const type = c.type;
24789
+ let columnBuilder;
24790
+ if (type === "bigint") {
24791
+ columnBuilder = new import_pg_core4.PgBigInt53Builder(columnName);
24792
+ } else if (type === "bigserial") {
24793
+ columnBuilder = new import_pg_core4.PgBigSerial53Builder(columnName);
24794
+ } else if (type === "boolean") {
24795
+ columnBuilder = new import_pg_core4.PgBooleanBuilder(columnName);
24796
+ } else if (type === "cidr") {
24797
+ columnBuilder = new import_pg_core4.PgCidrBuilder(columnName);
24798
+ } else if (type === "date") {
24799
+ columnBuilder = new import_pg_core4.PgDateBuilder(columnName);
24800
+ } else if (type === "double precision") {
24801
+ columnBuilder = new import_pg_core4.PgDoublePrecisionBuilder(columnName);
24802
+ } else if (type === "inet") {
24803
+ columnBuilder = new import_pg_core4.PgInetBuilder(columnName);
24804
+ } else if (type === "integer") {
24805
+ columnBuilder = new import_pg_core4.PgIntegerBuilder(columnName);
24806
+ } else if (type === "interval" || type.startsWith("interval ")) {
24807
+ columnBuilder = new import_pg_core4.PgIntervalBuilder(columnName, {});
24808
+ } else if (type === "json") {
24809
+ columnBuilder = new import_pg_core4.PgJsonBuilder(columnName);
24810
+ } else if (type === "jsonb") {
24811
+ columnBuilder = new import_pg_core4.PgJsonbBuilder(columnName);
24812
+ } else if (type === "macaddr") {
24813
+ columnBuilder = new import_pg_core4.PgMacaddrBuilder(columnName);
24814
+ } else if (type === "macaddr8") {
24815
+ columnBuilder = new import_pg_core4.PgMacaddr8Builder(columnName);
24816
+ } else if (type === "numeric" || type.startsWith("numeric(")) {
24817
+ columnBuilder = new import_pg_core4.PgNumericBuilder(columnName);
24818
+ } else if (type === "real") {
24819
+ columnBuilder = new import_pg_core4.PgRealBuilder(columnName);
24820
+ } else if (type === "serial") {
24821
+ columnBuilder = new import_pg_core4.PgSerialBuilder(columnName);
24822
+ } else if (type === "smallint") {
24823
+ columnBuilder = new import_pg_core4.PgSmallIntBuilder(columnName);
24824
+ } else if (type === "smallserial") {
24825
+ columnBuilder = new import_pg_core4.PgSmallSerialBuilder(columnName);
24826
+ } else if (type === "text") {
24827
+ columnBuilder = new import_pg_core4.PgTextBuilder(columnName, {});
24828
+ } else if (type === "time" || type.startsWith("time(") || type === "time with time zone") {
24829
+ columnBuilder = new import_pg_core4.PgTimeBuilder(columnName, false, void 0);
24830
+ } else if (type === "timestamp" || type.startsWith("timestamp(") || type === "timestamp with time zone") {
24831
+ columnBuilder = new import_pg_core4.PgTimestampBuilder(columnName, false, void 0);
24832
+ } else if (type === "uuid") {
24833
+ columnBuilder = new import_pg_core4.PgUUIDBuilder(columnName);
24834
+ } else if (type === "varchar" || type.startsWith("varchar(")) {
24835
+ columnBuilder = new import_pg_core4.PgVarcharBuilder(columnName, {});
24836
+ } else if (type === "char" || type.startsWith("char(")) {
24837
+ columnBuilder = new import_pg_core4.PgCharBuilder(columnName, {});
24838
+ } else {
24839
+ columnBuilder = (0, import_pg_core4.customType)({
24840
+ dataType() {
24841
+ return type;
24842
+ }
24843
+ })(columnName);
24844
+ }
24845
+ if (c.notNull) {
24846
+ columnBuilder = columnBuilder.notNull();
24847
+ }
24848
+ if (c.default) {
24849
+ columnBuilder = columnBuilder.default(c.default);
24850
+ }
24851
+ if (c.primaryKey) {
24852
+ columnBuilder = columnBuilder.primaryKey();
24853
+ }
24854
+ columns[columnName] = columnBuilder;
24855
+ });
24856
+ if (schemaName === "public") {
24857
+ tables[t.name] = (0, import_pg_core4.pgTable)(t.name, columns, (cb) => {
24858
+ const res = {};
24859
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24860
+ const gh = cpk.columns.map((c) => cb[c]);
24861
+ res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
24862
+ gh,
24863
+ cpk.name
24864
+ );
24865
+ });
24866
+ return res;
24867
+ });
24868
+ } else {
24869
+ tables[t.name] = (0, import_pg_core4.pgSchema)(schemaName).table(t.name, columns, (cb) => {
24870
+ const res = {};
24871
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24872
+ const gh = cpk.columns.map((c) => cb[c]);
24873
+ res[cpk.name] = new import_pg_core4.PrimaryKeyBuilder(
24874
+ gh,
24875
+ cpk.name
24876
+ );
24877
+ });
24878
+ return res;
24879
+ });
24880
+ }
24881
+ });
24882
+ return tables;
24883
+ };
24884
+ sqliteSchemaToDrizzle = (schema4) => {
24885
+ const tables = {};
24886
+ Object.values(schema4.tables).forEach((t) => {
24887
+ const columns = {};
24888
+ Object.values(t.columns).forEach((c) => {
24889
+ const columnName = c.name;
24890
+ const type = c.type;
24891
+ let columnBuilder;
24892
+ if (type === "integer") {
24893
+ columnBuilder = new import_sqlite_core3.SQLiteIntegerBuilder(columnName);
24894
+ } else if (type === "text") {
24895
+ columnBuilder = new import_sqlite_core3.SQLiteTextBuilder(columnName, {});
24896
+ } else if (type === "blob") {
24897
+ columnBuilder = new import_sqlite_core3.SQLiteBlobBufferBuilder(columnName);
24898
+ } else if (type === "real") {
24899
+ columnBuilder = new import_sqlite_core3.SQLiteRealBuilder(columnName);
24900
+ } else {
24901
+ columnBuilder = new import_sqlite_core3.SQLiteNumericBuilder(columnName);
24902
+ }
24903
+ if (c.notNull) {
24904
+ columnBuilder = columnBuilder.notNull();
24905
+ }
24906
+ if (c.default) {
24907
+ columnBuilder = columnBuilder.default(c.default);
24908
+ }
24909
+ if (c.primaryKey) {
24910
+ columnBuilder = columnBuilder.primaryKey();
24911
+ }
24912
+ columns[columnName] = columnBuilder;
24913
+ });
24914
+ tables[t.name] = (0, import_sqlite_core3.sqliteTable)(t.name, columns, (cb) => {
24915
+ const res = {};
24916
+ Object.values(t.compositePrimaryKeys).forEach((cpk) => {
24917
+ const gh = cpk.columns.map((c) => cb[c]);
24918
+ res[cpk.name] = new import_sqlite_core3.PrimaryKeyBuilder(
24919
+ gh,
24920
+ cpk.name
24921
+ );
24922
+ });
24923
+ return res;
24924
+ });
24925
+ });
24926
+ return tables;
24927
+ };
24928
+ }
24929
+ });
24930
+
24911
24931
  // node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js
24912
24932
  var require_constants = __commonJS({
24913
24933
  "node_modules/.pnpm/semver@7.5.4/node_modules/semver/internal/constants.js"(exports, module2) {
@@ -43251,15 +43271,15 @@ var require_promise = __commonJS({
43251
43271
  });
43252
43272
 
43253
43273
  // src/orm-extenstions/d1-driver/session.ts
43254
- var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12, import_sqlite_core3, import_drizzle_orm13, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
43274
+ var import_drizzle_orm10, import_drizzle_orm11, import_drizzle_orm12, import_sqlite_core4, import_drizzle_orm13, _a, SQLiteWranglerD1Session, _a2, PreparedQuery;
43255
43275
  var init_session = __esm({
43256
43276
  "src/orm-extenstions/d1-driver/session.ts"() {
43257
43277
  import_drizzle_orm10 = require("drizzle-orm");
43258
43278
  import_drizzle_orm11 = require("drizzle-orm");
43259
43279
  import_drizzle_orm12 = require("drizzle-orm");
43260
- import_sqlite_core3 = require("drizzle-orm/sqlite-core");
43280
+ import_sqlite_core4 = require("drizzle-orm/sqlite-core");
43261
43281
  import_drizzle_orm13 = require("drizzle-orm");
43262
- SQLiteWranglerD1Session = class extends import_sqlite_core3.SQLiteSession {
43282
+ SQLiteWranglerD1Session = class extends import_sqlite_core4.SQLiteSession {
43263
43283
  constructor(client, configPath, dbName, dialect6, schema4, options = {}) {
43264
43284
  super(dialect6);
43265
43285
  this.client = client;
@@ -43288,7 +43308,7 @@ var init_session = __esm({
43288
43308
  };
43289
43309
  _a = import_drizzle_orm10.entityKind;
43290
43310
  SQLiteWranglerD1Session[_a] = "SQLiteD1Session";
43291
- PreparedQuery = class extends import_sqlite_core3.SQLitePreparedQuery {
43311
+ PreparedQuery = class extends import_sqlite_core4.SQLitePreparedQuery {
43292
43312
  constructor(stmt, configPath, dbName, queryString, params, logger, fields, executeMethod, customResultMapper) {
43293
43313
  super("async", executeMethod, {
43294
43314
  sql: queryString,
@@ -43413,20 +43433,20 @@ function drizzle(client, configPath, dbName, config = {}) {
43413
43433
  const session = new SQLiteWranglerD1Session(client, configPath, dbName, dialect6, schema4, {
43414
43434
  logger
43415
43435
  });
43416
- return new import_sqlite_core4.BaseSQLiteDatabase(
43436
+ return new import_sqlite_core5.BaseSQLiteDatabase(
43417
43437
  "async",
43418
43438
  dialect6,
43419
43439
  session,
43420
43440
  schema4
43421
43441
  );
43422
43442
  }
43423
- var import_drizzle_orm14, import_sqlite_core4, WranglerDialect;
43443
+ var import_drizzle_orm14, import_sqlite_core5, WranglerDialect;
43424
43444
  var init_driver = __esm({
43425
43445
  "src/orm-extenstions/d1-driver/driver.ts"() {
43426
43446
  import_drizzle_orm14 = require("drizzle-orm");
43427
- import_sqlite_core4 = require("drizzle-orm/sqlite-core");
43447
+ import_sqlite_core5 = require("drizzle-orm/sqlite-core");
43428
43448
  init_session();
43429
- WranglerDialect = class extends import_sqlite_core4.SQLiteAsyncDialect {
43449
+ WranglerDialect = class extends import_sqlite_core5.SQLiteAsyncDialect {
43430
43450
  sqlToQuery(sql2) {
43431
43451
  return sql2.toQuery({
43432
43452
  escapeName: this.escapeName,
@@ -58742,13 +58762,13 @@ var init_wrangler_client = __esm({
58742
58762
  });
58743
58763
 
58744
58764
  // src/serializer/studioUtils.ts
58745
- var import_drizzle_orm15, import_mysql_core4, import_pg_core4, import_sqlite_core5, drizzleDb;
58765
+ var import_drizzle_orm15, import_mysql_core4, import_pg_core5, import_sqlite_core6, drizzleDb;
58746
58766
  var init_studioUtils = __esm({
58747
58767
  "src/serializer/studioUtils.ts"() {
58748
58768
  import_drizzle_orm15 = require("drizzle-orm");
58749
58769
  import_mysql_core4 = require("drizzle-orm/mysql-core");
58750
- import_pg_core4 = require("drizzle-orm/pg-core");
58751
- import_sqlite_core5 = require("drizzle-orm/sqlite-core");
58770
+ import_pg_core5 = require("drizzle-orm/pg-core");
58771
+ import_sqlite_core6 = require("drizzle-orm/sqlite-core");
58752
58772
  init_utils();
58753
58773
  init_utils3();
58754
58774
  init_global();
@@ -58857,8 +58877,7 @@ var init_utils5 = __esm({
58857
58877
  init_pgIntrospect();
58858
58878
  init_pgPushUtils();
58859
58879
  init_sqliteIntrospect();
58860
- init_sqliteSerializer();
58861
- init_pgSerializer();
58880
+ init_schemaToDrizzle();
58862
58881
  init_studioUtils();
58863
58882
  init_pgConnect();
58864
58883
  assertV1OutFolder = (out, dialect6) => {
@@ -59177,7 +59196,7 @@ var init_utils5 = __esm({
59177
59196
  preparedConnection.client,
59178
59197
  []
59179
59198
  );
59180
- const models = toDrizzle2(schema4);
59199
+ const models = sqliteSchemaToDrizzle(schema4);
59181
59200
  const drizzleDbInstance = await drizzleDb(
59182
59201
  connection,
59183
59202
  { sqliteSchema: models },
@@ -59202,7 +59221,7 @@ var init_utils5 = __esm({
59202
59221
  [],
59203
59222
  [schemaName]
59204
59223
  );
59205
- const models = toDrizzle(schema4, schemaName);
59224
+ const models = pgSchemaToDrizzle(schema4, schemaName);
59206
59225
  response[schemaName] = await drizzleDb(
59207
59226
  // @ts-ignore I don't know how to fix it yet. But will find a way
59208
59227
  connection,