drizzle-kit 1.0.0-beta.1-251c8ba → 1.0.0-beta.1-5e64efc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin.cjs +99 -16
  2. package/package.json +1 -1
package/bin.cjs CHANGED
@@ -85706,6 +85706,70 @@ __export(introspect_exports, {
85706
85706
  introspectSqlite: () => introspectSqlite,
85707
85707
  relationsToTypeScript: () => relationsToTypeScript
85708
85708
  });
85709
+ function postgresToRelationsPull(schema6) {
85710
+ return Object.values(schema6.tables).map((table6) => ({
85711
+ schema: table6.schema,
85712
+ foreignKeys: Object.values(table6.foreignKeys),
85713
+ uniques: [
85714
+ ...Object.values(table6.uniqueConstraints).map((unq) => ({
85715
+ columns: unq.columns
85716
+ })),
85717
+ ...Object.values(table6.indexes).map((idx) => ({
85718
+ columns: idx.columns.map((idxc) => {
85719
+ if (!idxc.isExpression && idx.isUnique) {
85720
+ return idxc.expression;
85721
+ }
85722
+ }).filter((item) => item !== void 0)
85723
+ }))
85724
+ ]
85725
+ }));
85726
+ }
85727
+ function gelToRelationsPull(schema6) {
85728
+ return Object.values(schema6.tables).map((table6) => ({
85729
+ schema: table6.schema,
85730
+ foreignKeys: Object.values(table6.foreignKeys),
85731
+ uniques: [
85732
+ ...Object.values(table6.uniqueConstraints).map((unq) => ({
85733
+ columns: unq.columns
85734
+ })),
85735
+ ...Object.values(table6.indexes).map((idx) => ({
85736
+ columns: idx.columns.map((idxc) => {
85737
+ if (!idxc.isExpression && idx.isUnique) {
85738
+ return idxc.expression;
85739
+ }
85740
+ }).filter((item) => item !== void 0)
85741
+ }))
85742
+ ]
85743
+ }));
85744
+ }
85745
+ function mysqlToRelationsPull(schema6) {
85746
+ return Object.values(schema6.tables).map((table6) => ({
85747
+ schema: void 0,
85748
+ foreignKeys: Object.values(table6.foreignKeys),
85749
+ uniques: [
85750
+ ...Object.values(table6.uniqueConstraints).map((unq) => ({
85751
+ columns: unq.columns
85752
+ })),
85753
+ ...Object.values(table6.indexes).map((idx) => ({
85754
+ columns: idx.columns
85755
+ }))
85756
+ ]
85757
+ }));
85758
+ }
85759
+ function sqliteToRelationsPull(schema6) {
85760
+ return Object.values(schema6.tables).map((table6) => ({
85761
+ schema: void 0,
85762
+ foreignKeys: Object.values(table6.foreignKeys),
85763
+ uniques: [
85764
+ ...Object.values(table6.uniqueConstraints).map((unq) => ({
85765
+ columns: unq.columns
85766
+ })),
85767
+ ...Object.values(table6.indexes).map((idx) => ({
85768
+ columns: idx.columns
85769
+ }))
85770
+ ]
85771
+ }));
85772
+ }
85709
85773
  var import_fs11, import_hanji14, import_path7, import_pluralize, introspectPostgres, introspectGel, introspectMysql, introspectSingleStore, introspectSqlite, introspectLibSQL, withCasing4, relationsToTypeScript;
85710
85774
  var init_introspect = __esm({
85711
85775
  "src/cli/commands/introspect.ts"() {
@@ -85775,7 +85839,7 @@ var init_introspect = __esm({
85775
85839
  );
85776
85840
  const schema6 = { id: originUUID, prevId: "", ...res };
85777
85841
  const ts = schemaToTypeScript4(schema6, casing2);
85778
- const relationsTs = relationsToTypeScript(schema6, casing2);
85842
+ const relationsTs = relationsToTypeScript(postgresToRelationsPull(schema6), casing2);
85779
85843
  const { internal, ...schemaWithoutInternals } = schema6;
85780
85844
  const schemaFile = (0, import_path7.join)(out, "schema.ts");
85781
85845
  (0, import_fs11.writeFileSync)(schemaFile, ts.file);
@@ -85870,7 +85934,7 @@ var init_introspect = __esm({
85870
85934
  );
85871
85935
  const schema6 = { id: originUUID, prevId: "", ...res };
85872
85936
  const ts = schemaToTypeScript2(schema6, casing2);
85873
- const relationsTs = relationsToTypeScript(schema6, casing2);
85937
+ const relationsTs = relationsToTypeScript(gelToRelationsPull(schema6), casing2);
85874
85938
  const { internal, ...schemaWithoutInternals } = schema6;
85875
85939
  const schemaFile = (0, import_path7.join)(out, "schema.ts");
85876
85940
  (0, import_fs11.writeFileSync)(schemaFile, ts.file);
@@ -85925,7 +85989,7 @@ var init_introspect = __esm({
85925
85989
  );
85926
85990
  const schema6 = { id: originUUID, prevId: "", ...res };
85927
85991
  const ts = schemaToTypeScript3(schema6, casing2);
85928
- const relationsTs = relationsToTypeScript(schema6, casing2);
85992
+ const relationsTs = relationsToTypeScript(mysqlToRelationsPull(schema6), casing2);
85929
85993
  const { internal, ...schemaWithoutInternals } = schema6;
85930
85994
  const schemaFile = (0, import_path7.join)(out, "schema.ts");
85931
85995
  (0, import_fs11.writeFileSync)(schemaFile, ts.file);
@@ -86081,7 +86145,7 @@ var init_introspect = __esm({
86081
86145
  );
86082
86146
  const schema6 = { id: originUUID, prevId: "", ...res };
86083
86147
  const ts = schemaToTypeScript(schema6, casing2);
86084
- const relationsTs = relationsToTypeScript(schema6, casing2);
86148
+ const relationsTs = relationsToTypeScript(sqliteToRelationsPull(schema6), casing2);
86085
86149
  const schemaFile = (0, import_path7.join)(out, "schema.ts");
86086
86150
  (0, import_fs11.writeFileSync)(schemaFile, ts.file);
86087
86151
  const relationsFile = (0, import_path7.join)(out, "relations.ts");
@@ -86163,7 +86227,7 @@ var init_introspect = __esm({
86163
86227
  );
86164
86228
  const schema6 = { id: originUUID, prevId: "", ...res };
86165
86229
  const ts = schemaToTypeScript(schema6, casing2);
86166
- const relationsTs = relationsToTypeScript(schema6, casing2);
86230
+ const relationsTs = relationsToTypeScript(sqliteToRelationsPull(schema6), casing2);
86167
86231
  const schemaFile = (0, import_path7.join)(out, "schema.ts");
86168
86232
  (0, import_fs11.writeFileSync)(schemaFile, ts.file);
86169
86233
  const relationsFile = (0, import_path7.join)(out, "relations.ts");
@@ -86223,7 +86287,7 @@ var init_introspect = __esm({
86223
86287
  relationsToTypeScript = (schema6, casing2) => {
86224
86288
  const imports = [];
86225
86289
  const tableRelations = {};
86226
- Object.values(schema6.tables).forEach((table6) => {
86290
+ schema6.forEach((table6) => {
86227
86291
  const fks = Object.values(table6.foreignKeys);
86228
86292
  if (fks.length === 2) {
86229
86293
  const [fk1, fk22] = fks;
@@ -86255,6 +86319,7 @@ var init_introspect = __esm({
86255
86319
  }
86256
86320
  tableRelations[toTable2].push({
86257
86321
  name: (0, import_pluralize.plural)(toTable1),
86322
+ // this type is used for .many() side of relation, when another side has .through() with from and to fields
86258
86323
  type: "many-through",
86259
86324
  tableFrom: toTable2,
86260
86325
  columnsFrom: fk22.columnsTo,
@@ -86290,14 +86355,27 @@ var init_introspect = __esm({
86290
86355
  if (!tableRelations[keyTo]) {
86291
86356
  tableRelations[keyTo] = [];
86292
86357
  }
86293
- tableRelations[keyTo].push({
86294
- name: (0, import_pluralize.plural)(tableFrom),
86295
- type: "many",
86296
- tableFrom: tableTo,
86297
- columnsFrom: columnsTo,
86298
- tableTo: tableFrom,
86299
- columnsTo: columnsFrom
86300
- });
86358
+ if (table6.uniques.find(
86359
+ (constraint) => constraint.columns.length === columnsFrom.length && constraint.columns.every((col, i2) => col === columnsFrom[i2])
86360
+ )) {
86361
+ tableRelations[keyTo].push({
86362
+ name: (0, import_pluralize.plural)(tableFrom),
86363
+ type: "one-one",
86364
+ tableFrom: tableTo,
86365
+ columnsFrom: columnsTo,
86366
+ tableTo: tableFrom,
86367
+ columnsTo: columnsFrom
86368
+ });
86369
+ } else {
86370
+ tableRelations[keyTo].push({
86371
+ name: (0, import_pluralize.plural)(tableFrom),
86372
+ type: "many",
86373
+ tableFrom: tableTo,
86374
+ columnsFrom: columnsTo,
86375
+ tableTo: tableFrom,
86376
+ columnsTo: columnsFrom
86377
+ });
86378
+ }
86301
86379
  });
86302
86380
  }
86303
86381
  });
@@ -86317,7 +86395,7 @@ import * as schema from "./schema";
86317
86395
  if (hasMultipleRelations) {
86318
86396
  if (relation.type === "one") {
86319
86397
  relationName = `${relation.tableFrom}_${relation.columnsFrom.join("_")}_${relation.tableTo}_${relation.columnsTo.join("_")}`;
86320
- } else if (relation.type === "many") {
86398
+ } else if (relation.type === "many" || relation.type === "one-one") {
86321
86399
  relationName = `${relation.tableTo}_${relation.columnsTo.join("_")}_${relation.tableFrom}_${relation.columnsFrom.join("_")}`;
86322
86400
  } else if (relation.type === "through") {
86323
86401
  relationName = `${relation.tableFrom}_${relation.columnsFrom.join("_")}_${relation.tableTo}_${relation.columnsTo.join("_")}_via_${relation.tableThrough}`;
@@ -86355,6 +86433,11 @@ import * as schema from "./schema";
86355
86433
  ${relation.name}: r.many.${relation.tableTo}(` + (relation.relationName ? `{
86356
86434
  alias: "${relation.relationName}"
86357
86435
  }` : "") + `),`;
86436
+ } else if (relation.type === "one-one") {
86437
+ relationString += `
86438
+ ${relation.name}: r.one.${relation.tableTo}(` + (relation.relationName ? `{
86439
+ alias: "${relation.relationName}"
86440
+ }` : "") + `),`;
86358
86441
  } else {
86359
86442
  const from = relation.columnsThroughFrom.length === 1 ? `r.${relation.tableFrom}.${relation.columnsFrom[0]}.through(r.${relation.tableThrough}.${relation.columnsThroughFrom[0]})` : `[${relation.columnsThroughFrom.map((it) => `r.${relation.tableFrom}.${it}.through(${relation.tableThrough}.${it})`).join(", ")}]`;
86360
86443
  const to = relation.columnsThroughTo.length === 1 ? `r.${relation.tableTo}.${relation.columnsTo[0]}.through(r.${relation.tableThrough}.${relation.columnsThroughTo[0]})` : `[${relation.columnsThroughTo.map((it) => `r.${relation.tableTo}.${it}.through(${relation.tableThrough}.${it})`).join(", ")}]`;
@@ -92729,7 +92812,7 @@ init_utils5();
92729
92812
  var version2 = async () => {
92730
92813
  const { npmVersion } = await ormCoreVersions();
92731
92814
  const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
92732
- const envVersion = "1.0.0-beta.1-251c8ba";
92815
+ const envVersion = "1.0.0-beta.1-5e64efc";
92733
92816
  const kitVersion = envVersion ? `v${envVersion}` : "--";
92734
92817
  const versions = `drizzle-kit: ${kitVersion}
92735
92818
  ${ormVersion}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-kit",
3
- "version": "1.0.0-beta.1-251c8ba",
3
+ "version": "1.0.0-beta.1-5e64efc",
4
4
  "homepage": "https://orm.drizzle.team",
5
5
  "keywords": [
6
6
  "drizzle",