hekireki 0.52.2 → 0.52.4

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.
package/README.md CHANGED
@@ -80,6 +80,13 @@ The `provider` of the generator block picks the output. Every option is optional
80
80
  Every ORM generator stores a `DateTime` as Prisma Client stores it, so the ORM and Prisma read
81
81
  each other's rows alike.
82
82
 
83
+ On MySQL, `hekireki-gorm` gives a `String` with no native type `VARCHAR(191)`, the column Prisma
84
+ Migrate creates, whatever `mysql.Config{DefaultStringSize}` says, a `uuid()` or `ulid()` key
85
+ included. The next `AutoMigrate` alters a column an earlier one made `longtext`, `varchar(n)` or
86
+ `char(36)` to it, which fails (or, outside strict mode, cuts the value) on a value longer than 191
87
+ characters: check with `SELECT MAX(CHAR_LENGTH(column))` first, and give a field that holds longer
88
+ values `@db.Text`.
89
+
83
90
  `hekireki-sqlalchemy` and `hekireki-django` give a `uuid()`, `cuid()`, `ulid()` or `nanoid()`
84
91
  default the value Prisma Client would make, with a package from PyPI where Python's standard
85
92
  library has none: `uuid6` for `uuid(7)`, `python-ulid` for `ulid()`, `cuid` for `cuid()`, `cuid2`
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/activerecord.ts
4
4
  registerGenerator("activerecord");
5
5
  export {};
package/dist/bin/ajv.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/ajv.ts
4
4
  registerGenerator("ajv");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/arktype.ts
4
4
  registerGenerator("arktype");
5
5
  export {};
package/dist/bin/atlas.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/atlas.ts
4
4
  registerGenerator("atlas");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/django.ts
4
4
  registerGenerator("django");
5
5
  export {};
package/dist/bin/docs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/docs.ts
4
4
  registerGenerator("docs");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/drizzle.ts
4
4
  registerGenerator("drizzle");
5
5
  export {};
package/dist/bin/ecto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/ecto.ts
4
4
  registerGenerator("ecto");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/efcore.ts
4
4
  registerGenerator("efcore");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/effect.ts
4
4
  registerGenerator("effect");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/eloquent.ts
4
4
  registerGenerator("eloquent");
5
5
  export {};
package/dist/bin/er.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/er.ts
4
4
  registerGenerator("er");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/exposed.ts
4
4
  registerGenerator("exposed");
5
5
  export {};
package/dist/bin/gorm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/gorm.ts
4
4
  registerGenerator("gorm");
5
5
  export {};
@@ -6,7 +6,7 @@ import { Console, Data, Effect, Schema } from "effect";
6
6
  import path from "node:path";
7
7
  import { CliError, Command, Flag } from "effect/cli";
8
8
  // package.json
9
- var version = "0.52.2";
9
+ var version = "0.52.4";
10
10
  // src/schema/path.ts
11
11
  /** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
12
12
  const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
@@ -149,7 +149,7 @@ const studioFlags = {
149
149
  function runStudio(args) {
150
150
  return Effect.gen(function* () {
151
151
  const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
152
- const { startStudioServer } = yield* Effect.promise(() => import("../start-Ba8wQAD1.js"));
152
+ const { startStudioServer } = yield* Effect.promise(() => import("../start-zBekMHfh.js"));
153
153
  const started = yield* startStudioServer({
154
154
  schemaPath,
155
155
  port: args.port,
@@ -201,7 +201,7 @@ const seedFlags = {
201
201
  };
202
202
  function runSeedCommand(args) {
203
203
  return Effect.gen(function* () {
204
- const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-DbZYkHVI.js"));
204
+ const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-DMNh0Fmc.js"));
205
205
  const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
206
206
  yield* Console.log(seedBanner(report));
207
207
  });
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/kysely.ts
4
4
  registerGenerator("kysely");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/openapi.ts
4
4
  registerGenerator("openapi");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/pydantic.ts
4
4
  registerGenerator("pydantic");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/sea-orm.ts
4
4
  registerGenerator("sea-orm");
5
5
  export {};
package/dist/bin/seed.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/seed.ts
4
4
  registerGenerator("seed");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/sqlalchemy.ts
4
4
  registerGenerator("sqlalchemy");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/typebox.ts
4
4
  registerGenerator("typebox");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/valibot.ts
4
4
  registerGenerator("valibot");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/zod-openapi-hono.ts
4
4
  registerGenerator("zod-openapi-hono");
5
5
  export {};
package/dist/bin/zod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-i7iQQ-V-.js";
2
+ import { t as registerGenerator } from "../bin-Py9KRh1_.js";
3
3
  // src/bin/zod.ts
4
4
  registerGenerator("zod");
5
5
  export {};
@@ -2,7 +2,7 @@ import { c as removePath, o as readDirectory, s as readFile, t as exists, u as w
2
2
  import { A as primaryKeyFields$1, C as isJoinSideA, D as lengthArg, E as isUlidDefault, F as uuidDefaultVersion, L as isSameList, M as relationEnds, N as scalarFields, O as manyToManyRelations, P as tableName, R as fmt, S as isImplicitManyToMany, T as isNowDefault$1, _ as cuidDefaultVersion, a as schemaText, b as isAutoincrement, g as columnName, h as backRelation, i as readSchemaFiles, j as referentialActions, k as nanoidDefault, m as formatSql, t as dialectOf, v as fieldColumn, w as isListDefault, x as isFunctionDefault, y as implicitJoinTables, z as fmtMarkdown } from "./schema-CyJTUCF1.js";
3
3
  import { n as emitMany, r as emitRaw, t as emit } from "./emit-DsCT5gLu.js";
4
4
  import { _ as stripAnnotations, a as makeOfflineSchemaEngineAdapter, c as makeSchema, d as erRelations, f as inferredERRelations, g as makeValidationExtractor, h as isAnnotationLine, i as openSchemaEngine, l as annotatedERRelations, m as extractObjectType, n as openNativeSchemaEngine, p as docBlockLines, r as engineCommand, t as findSchemaEngineBinary, u as erKey } from "./native-engine-DeQEnJxi.js";
5
- import { a as makeSnakeCase, i as makePascalCase, n as indexPrefix, r as lowerFirst, t as constraintName } from "./case-D3JCqTLI.js";
5
+ import { a as makeSnakeCase, i as makePascalCase, n as indexPrefix, r as lowerFirst, t as constraintName } from "./case-CCSiaowC.js";
6
6
  import { a as splitStatements, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
7
7
  import { createRequire } from "node:module";
8
8
  import { Data, Effect } from "effect";
@@ -13611,8 +13611,13 @@ function resolveNativeType$1(field) {
13611
13611
  }
13612
13612
  return GORM_NATIVE_FIXED[nativeName] ?? null;
13613
13613
  }
13614
- /** A relation through the foreign key `fkField` holds, which is on either end of it. */
13615
- function foreignKeyAssociation(name, targetModel, fkField) {
13614
+ /**
13615
+ * A relation through the foreign key `fkField` holds, which is on either end of it. A referential
13616
+ * action the schema leaves out is Prisma's: `Restrict` on delete for a required relation (`NoAction`
13617
+ * on SQL Server, which has no RESTRICT) and `SetNull` for an optional one, `Cascade` on update.
13618
+ */
13619
+ function foreignKeyAssociation(name, targetModel, fkField, provider) {
13620
+ const requiredOnDelete = provider === "sqlserver" ? "NoAction" : "Restrict";
13616
13621
  const foreignKeys = fkField.relationFromFields ?? [];
13617
13622
  return {
13618
13623
  name,
@@ -13621,11 +13626,12 @@ function foreignKeyAssociation(name, targetModel, fkField) {
13621
13626
  references: fkField.relationToFields?.[0] ?? "id",
13622
13627
  foreignKeys,
13623
13628
  referencesList: fkField.relationToFields ?? ["id"],
13624
- onDelete: fkField.relationOnDelete,
13625
- onUpdate: fkField.relationOnUpdate
13629
+ fkFieldName: fkField.name,
13630
+ onDelete: fkField.relationOnDelete ?? (fkField.isRequired ? requiredOnDelete : "SetNull"),
13631
+ onUpdate: fkField.relationOnUpdate ?? "Cascade"
13626
13632
  };
13627
13633
  }
13628
- function getAssociations$2(model, allModels) {
13634
+ function getAssociations$2(model, allModels, provider) {
13629
13635
  const belongsTo = [];
13630
13636
  const hasMany = [];
13631
13637
  const hasOne = [];
@@ -13633,7 +13639,7 @@ function getAssociations$2(model, allModels) {
13633
13639
  for (const end of relationEnds(model, allModels)) {
13634
13640
  const { field } = end;
13635
13641
  if (end.kind === "belongsTo") {
13636
- belongsTo.push(foreignKeyAssociation(field.name, field.type, field));
13642
+ belongsTo.push(foreignKeyAssociation(field.name, field.type, field, provider));
13637
13643
  continue;
13638
13644
  }
13639
13645
  if (end.kind === "manyToMany") {
@@ -13646,7 +13652,7 @@ function getAssociations$2(model, allModels) {
13646
13652
  continue;
13647
13653
  }
13648
13654
  const association = {
13649
- ...foreignKeyAssociation(field.name, field.type, end.inverse),
13655
+ ...foreignKeyAssociation(field.name, field.type, end.inverse, provider),
13650
13656
  isList: end.kind === "hasMany"
13651
13657
  };
13652
13658
  if (end.kind === "hasMany") hasMany.push(association);
@@ -13704,24 +13710,44 @@ function dateTimeDefault$1(field, provider) {
13704
13710
  if (goType === "TimeOfDay") return `'${iso.slice(11, 23)}'`;
13705
13711
  return provider === "sqlite" ? `'${iso.replace("Z", "+00:00")}'` : `'${iso.slice(0, 10)} ${iso.slice(11, 23)}'`;
13706
13712
  }
13713
+ function isPostgresFamily(provider) {
13714
+ return provider === "postgresql" || provider === "cockroachdb";
13715
+ }
13707
13716
  function gormDefault(field, isPk, isCompositePk, enums, provider) {
13708
13717
  const isNowDefault = field.type === "DateTime" && isFunctionDefault(field.default) && field.default.name === "now";
13709
- return dbGeneratedDefault(field) ?? dateTimeDefault$1(field, provider) ?? ((!isPk || isCompositePk) && !isNowDefault && field.isUpdatedAt !== true ? enumMappedDefault$1(field, enums) ?? formatGoDefault(field.default, field.type, field.kind) : null);
13718
+ const nowDefault = isNowDefault && isPostgresFamily(provider) ? "CURRENT_TIMESTAMP" : null;
13719
+ return dbGeneratedDefault(field) ?? dateTimeDefault$1(field, provider) ?? nowDefault ?? ((!isPk || isCompositePk) && !isNowDefault && field.isUpdatedAt !== true ? enumMappedDefault$1(field, enums) ?? formatGoDefault(field.default, field.type, field.kind) : null);
13710
13720
  }
13711
- function primaryKeyTags(field, isPk) {
13721
+ function primaryKeyTags(field, isPk, provider) {
13712
13722
  if (!isPk) return [];
13713
13723
  const defaultName = isFunctionDefault(field.default) ? field.default.name : void 0;
13724
+ const fixedType = provider !== "mysql" && !isPostgresFamily(provider) && resolveNativeType$1(field) === null;
13714
13725
  return [
13715
13726
  "primaryKey",
13716
13727
  ...isAutoincrement(field) ? ["autoIncrement"] : [],
13717
- ...defaultName === "uuid" ? ["type:char(36)"] : [],
13718
- ...defaultName === "ulid" ? ["type:char(26)"] : []
13728
+ ...fixedType && defaultName === "uuid" ? ["type:char(36)"] : [],
13729
+ ...fixedType && defaultName === "ulid" ? ["type:char(26)"] : []
13719
13730
  ];
13720
13731
  }
13721
- function columnTypeTag(field, isPk) {
13732
+ function isMysqlDefaultString(field, provider) {
13733
+ if (provider !== "mysql" || field.type !== "String" || field.kind !== "scalar") return false;
13734
+ return !field.isList && !field.nativeType;
13735
+ }
13736
+ const POSTGRES_DEFAULT_TYPES = {
13737
+ Float: "double precision",
13738
+ Decimal: "decimal(65,30)",
13739
+ DateTime: "timestamp(3)"
13740
+ };
13741
+ function columnTypeTag(field, provider) {
13722
13742
  const nativeType = resolveNativeType$1(field);
13723
13743
  if (isDateTimeList(field)) return `type:${nativeType ?? "timestamp(3)"}[]`;
13724
- return nativeType !== null && (!isPk || !isFunctionDefault(field.default) || field.default.name !== "uuid") ? `type:${nativeType}` : null;
13744
+ if (isMysqlDefaultString(field, provider)) return "type:varchar(191)";
13745
+ if (nativeType !== null) return `type:${nativeType}`;
13746
+ const postgresType = isPostgresFamily(provider) && field.kind === "scalar" && !field.isList ? POSTGRES_DEFAULT_TYPES[field.type] : void 0;
13747
+ return postgresType === void 0 ? null : `type:${postgresType}`;
13748
+ }
13749
+ function sizeTag(field, provider) {
13750
+ return provider !== "cockroachdb" && field.kind === "scalar" && field.type === "Int" && !field.isList && !field.nativeType ? "size:32" : null;
13725
13751
  }
13726
13752
  function trackedTimeTags(field, fieldName) {
13727
13753
  if (!(isDateTimeScalar(field) || ["Int", "BigInt"].includes(field.type))) return [];
@@ -13732,29 +13758,42 @@ function buildGormTags(field, isPk, isCompositePk, compositeIndexTags, enums, pr
13732
13758
  const defaultVal = gormDefault(field, isPk, isCompositePk, enums, provider);
13733
13759
  return `\`gorm:"${[
13734
13760
  `column:${columnName}`,
13735
- ...primaryKeyTags(field, isPk),
13736
- field.isUnique ? "uniqueIndex" : null,
13761
+ ...primaryKeyTags(field, isPk, provider),
13762
+ field.isUnique && !compositeIndexTags.some((tag) => tag.startsWith("uniqueIndex:")) ? "uniqueIndex" : null,
13737
13763
  ...compositeIndexTags,
13738
- columnTypeTag(field, isPk),
13764
+ columnTypeTag(field, provider),
13765
+ sizeTag(field, provider),
13739
13766
  field.isList && field.kind !== "object" && !isDateTimeList(field) ? "serializer:json" : null,
13740
13767
  defaultVal !== null ? `default:${defaultVal}` : null,
13741
13768
  ...trackedTimeTags(field, fieldName),
13742
13769
  field.isRequired && !isPk ? "not null" : null
13743
13770
  ].filter((p) => p !== null).join(";")}" json:"${columnName}"\``;
13744
13771
  }
13745
- function collectCompositeIndexTags(model, indexes) {
13772
+ function readableTagName(name) {
13773
+ return name !== void 0 && !/[,;"`]/u.test(name) ? name : void 0;
13774
+ }
13775
+ function collectCompositeIndexTags(model, indexes, provider) {
13746
13776
  const tableName = model.dbName ?? model.name;
13747
13777
  const fieldByName = new Map(model.fields.map((mf) => [mf.name, mf]));
13778
+ const columnsOf = (fields) => fields.map((f) => fieldByName.get(f)?.dbName ?? f);
13779
+ const mappedUniques = new Map(indexes.filter((idx) => idx.model === model.name && idx.type === "unique").map((idx) => [idx.fields.map((f) => f.name).join(","), readableTagName(idx.dbName)]));
13780
+ const singleUniqueTags = model.fields.filter((f) => f.isUnique).map((f) => {
13781
+ const named = mappedUniques.get(f.name);
13782
+ return [f.name, `uniqueIndex:${named ?? constraintName(tableName, [f.dbName ?? f.name], "key", provider ?? "")}`];
13783
+ });
13748
13784
  const uniqueTags = model.uniqueFields.filter((fields) => fields.length > 1).flatMap((fields) => {
13749
- const cols = fields.map((f) => fieldByName.get(f)?.dbName ?? f);
13750
- const idxName = `${tableName}_${cols.join("_")}_key`;
13785
+ const idxName = mappedUniques.get(fields.join(",")) ?? constraintName(tableName, columnsOf(fields), "key", provider ?? "");
13751
13786
  return fields.map((f) => [f, `uniqueIndex:${idxName}`]);
13752
13787
  });
13753
13788
  const indexTags = indexes.filter((idx) => idx.model === model.name && (idx.type === "normal" || idx.type === "fulltext")).flatMap((idx) => {
13754
- const idxName = idx.dbName ?? idx.name ?? `${tableName}_${idx.fields.map((f) => fieldByName.get(f.name)?.dbName ?? f.name).join("_")}_idx`;
13789
+ const idxName = readableTagName(idx.dbName) ?? readableTagName(idx.name) ?? constraintName(tableName, columnsOf(idx.fields.map((f) => f.name)), "idx", provider ?? "");
13755
13790
  return idx.fields.map((f) => [f.name, `index:${idxName}`]);
13756
13791
  });
13757
- return [...uniqueTags, ...indexTags].reduce((map, [fieldName, tag]) => {
13792
+ return [
13793
+ ...singleUniqueTags,
13794
+ ...uniqueTags,
13795
+ ...indexTags
13796
+ ].reduce((map, [fieldName, tag]) => {
13758
13797
  const existing = map.get(fieldName) ?? [];
13759
13798
  map.set(fieldName, [...existing, tag]);
13760
13799
  return map;
@@ -13954,9 +13993,20 @@ const SQL_ACTION$1 = {
13954
13993
  NoAction: "NO ACTION",
13955
13994
  SetDefault: "SET DEFAULT"
13956
13995
  };
13957
- function constraintTag(onDelete, onUpdate) {
13958
- const clauses = [onUpdate !== void 0 && SQL_ACTION$1[onUpdate] !== void 0 ? `OnUpdate:${SQL_ACTION$1[onUpdate]}` : null, onDelete !== void 0 && SQL_ACTION$1[onDelete] !== void 0 ? `OnDelete:${SQL_ACTION$1[onDelete]}` : null].filter((c) => c !== null);
13959
- return clauses.length > 0 ? `constraint:${clauses.join(",")}` : null;
13996
+ function constraintTag(name, onDelete, onUpdate) {
13997
+ const actions = [SQL_ACTION$1[onUpdate] === void 0 ? null : `OnUpdate:${SQL_ACTION$1[onUpdate]}`, SQL_ACTION$1[onDelete] === void 0 ? null : `OnDelete:${SQL_ACTION$1[onDelete]}`].filter((c) => c !== null);
13998
+ if (actions.length === 0) return null;
13999
+ return `constraint:${[.../^[\w-]+$/u.test(name) ? [name] : [], ...actions].join(",")}`;
14000
+ }
14001
+ /**
14002
+ * The name Prisma Migrate gives the foreign key `holder` holds in the named fields:
14003
+ * `<table>_<columns>_fkey`.
14004
+ */
14005
+ function foreignKeyName(allModels, holder, fieldNames, provider) {
14006
+ const model = allModels.find((m) => m.name === holder);
14007
+ const columnOf = new Map(model?.fields.map((f) => [f.name, f.dbName ?? f.name]));
14008
+ const columns = fieldNames.map((name) => columnOf.get(name) ?? name);
14009
+ return constraintName(model?.dbName ?? holder, columns, "fkey", provider ?? "");
13960
14010
  }
13961
14011
  function buildRelationTag(parts) {
13962
14012
  return `\`gorm:"${parts.join(";")}"\``;
@@ -13970,7 +14020,7 @@ function buildRelationTag(parts) {
13970
14020
  function goCommentLines(text) {
13971
14021
  return text === void 0 ? [] : text.split("\n").map((line) => `//${line.trimEnd() === "" ? "" : ` ${line.trimEnd()}`}`);
13972
14022
  }
13973
- function generateRelationFields(model, allModels, associations) {
14023
+ function generateRelationFields(model, allModels, associations, provider, foreignKeyNames) {
13974
14024
  const of = (modelName) => (name) => goFieldNameIn(allModels, modelName, name);
13975
14025
  const own = of(model.name);
13976
14026
  const withDoc = (name, row) => [...goCommentLines(stripAnnotations(model.fields.find((f) => f.name === name)?.documentation)).map((line) => [line]), row];
@@ -13994,7 +14044,7 @@ function generateRelationFields(model, allModels, associations) {
13994
14044
  const tagParts = [
13995
14045
  `foreignKey:${assoc.foreignKeys.map(of(assoc.targetModel)).join(",")}`,
13996
14046
  ...assoc.foreignKeys.length > 1 || needsReferencesTag(assoc.references) ? [`references:${assoc.referencesList.map(own).join(",")}`] : [],
13997
- ...[constraintTag(assoc.onDelete, assoc.onUpdate)].filter((c) => c !== null)
14047
+ ...[constraintTag(foreignKeyNames.get(`${assoc.targetModel}.${assoc.fkFieldName}`) ?? foreignKeyName(allModels, assoc.targetModel, assoc.foreignKeys, provider), assoc.onDelete, assoc.onUpdate)].filter((c) => c !== null)
13998
14048
  ];
13999
14049
  return withDoc(assoc.name, [
14000
14050
  own(assoc.name),
@@ -14006,7 +14056,7 @@ function generateRelationFields(model, allModels, associations) {
14006
14056
  const tagParts = [
14007
14057
  `foreignKey:${assoc.foreignKeys.map(of(assoc.targetModel)).join(",")}`,
14008
14058
  ...assoc.foreignKeys.length > 1 || needsReferencesTag(assoc.references) ? [`references:${assoc.referencesList.map(own).join(",")}`] : [],
14009
- ...[constraintTag(assoc.onDelete, assoc.onUpdate)].filter((c) => c !== null)
14059
+ ...[constraintTag(foreignKeyNames.get(`${assoc.targetModel}.${assoc.fkFieldName}`) ?? foreignKeyName(allModels, assoc.targetModel, assoc.foreignKeys, provider), assoc.onDelete, assoc.onUpdate)].filter((c) => c !== null)
14010
14060
  ];
14011
14061
  return withDoc(assoc.name, [
14012
14062
  own(assoc.name),
@@ -14062,12 +14112,12 @@ function alignFields(rows) {
14062
14112
  });
14063
14113
  return rows.map((row, i) => `\t${row.map((cell, column) => column < row.length - 1 ? cell.padEnd(widths[column]?.(i) ?? 0) : cell).join("")}`);
14064
14114
  }
14065
- function generateModelStruct(model, allModels, enums, indexes, provider) {
14115
+ function generateModelStruct(model, allModels, enums, indexes, provider, foreignKeyNames = /* @__PURE__ */ new Map()) {
14066
14116
  const idField = model.fields.find((f) => f.isId);
14067
14117
  const compositePkFieldNames = new Set(idField ? [] : primaryKeyFields$1(model));
14068
14118
  const isCompositePk = !idField && compositePkFieldNames.size > 0;
14069
- const associations = getAssociations$2(model, allModels);
14070
- const compositeTagMap = collectCompositeIndexTags(model, indexes);
14119
+ const associations = getAssociations$2(model, allModels, provider);
14120
+ const compositeTagMap = collectCompositeIndexTags(model, indexes, provider);
14071
14121
  const tableName = model.dbName ?? model.name;
14072
14122
  const scalarFields = model.fields.filter((f) => f.kind !== "object");
14073
14123
  const names = goFieldNames(model);
@@ -14078,7 +14128,7 @@ function generateModelStruct(model, allModels, enums, indexes, provider) {
14078
14128
  rows.push(generateStructField(field, names.get(field.name) ?? goFieldName(field.name), isPk, isCompositePk, fieldIndexTags, enums, provider));
14079
14129
  return rows;
14080
14130
  });
14081
- const relationLines = generateRelationFields(model, allModels, associations);
14131
+ const relationLines = generateRelationFields(model, allModels, associations, provider, foreignKeyNames);
14082
14132
  const tableNameMethod = [
14083
14133
  "",
14084
14134
  `func (${goModelName(model.name)}) TableName() string {`,
@@ -14398,9 +14448,9 @@ function formatImports(groups) {
14398
14448
  ];
14399
14449
  }
14400
14450
  // src/generator/gorm.ts
14401
- function generateGormModels(models, enums, indexes, packageName = "model", provider) {
14451
+ function generateGormModels(models, enums, indexes, packageName = "model", provider, foreignKeyNames = /* @__PURE__ */ new Map()) {
14402
14452
  const idx = indexes ?? [];
14403
- const modelBodies = models.map((model) => generateModelStruct(model, models, enums, idx, provider));
14453
+ const modelBodies = models.map((model) => generateModelStruct(model, models, enums, idx, provider, foreignKeyNames));
14404
14454
  return [
14405
14455
  `package ${packageName}`,
14406
14456
  ...formatImports(collectImports(models)),
@@ -14421,7 +14471,7 @@ function gorm(options) {
14421
14471
  const packageName = getString(options.generator.config["package"]) ?? "model";
14422
14472
  const enums = options.dmmf.datamodel.enums;
14423
14473
  const indexes = options.dmmf.datamodel.indexes;
14424
- const code = generateGormModels(options.dmmf.datamodel.models, enums, indexes, packageName, options.datasources[0]?.activeProvider);
14474
+ const code = generateGormModels(options.dmmf.datamodel.models, enums, indexes, packageName, options.datasources[0]?.activeProvider, relationMaps(prismaBlocks(options.datamodel)));
14425
14475
  return yield* emitRaw(code, resolved.dir, resolved.file);
14426
14476
  });
14427
14477
  }
@@ -7,7 +7,8 @@ function makePascalCase(name) {
7
7
  }
8
8
  const IDENTIFIER_LIMITS = {
9
9
  sqlite: Infinity,
10
- mysql: 64
10
+ mysql: 64,
11
+ sqlserver: 128
11
12
  };
12
13
  /** The text with its first character in lower case: a model's Prisma Client delegate, a label. */
13
14
  function lowerFirst(text) {
@@ -16,7 +17,7 @@ function lowerFirst(text) {
16
17
  /**
17
18
  * The name Prisma Migrate gives a key, index or constraint the schema does not name: the table,
18
19
  * the columns and a suffix, the first two cut to the database's longest identifier (63 on
19
- * PostgreSQL, 64 on MySQL).
20
+ * PostgreSQL, 64 on MySQL, 128 on SQL Server).
20
21
  *
21
22
  * @example
22
23
  * ```sql
@@ -2,7 +2,7 @@ import { t as exists } from "./file-DOGnu_Q2.js";
2
2
  import { v as DEFAULT_SCHEMA_PATHS, y as prismaSchemaPath } from "./bin/hekireki.js";
3
3
  import { C as isJoinSideA, I as chunks, a as schemaText, h as backRelation, i as readSchemaFiles, n as parseSchema, t as dialectOf } from "./schema-CyJTUCF1.js";
4
4
  import { r as emitRaw } from "./emit-DsCT5gLu.js";
5
- import { r as lowerFirst } from "./case-D3JCqTLI.js";
5
+ import { r as lowerFirst } from "./case-CCSiaowC.js";
6
6
  import { a as loadSeedConfig, c as SeedConfigError, d as resolveDatabaseUrl, i as withTypeScriptImports, l as SeedDatabaseError, r as sequenceSql, s as resolveConfigPath, t as makeSeedSql, u as SeedGenerationError } from "./sql-LMMCiAlf.js";
7
7
  import { n as discoverClient, r as adapterOf } from "./discover-CLLycWcR.js";
8
8
  import { Effect } from "effect";
@@ -2,7 +2,7 @@ import { c as removePath, i as makeDirectory, l as watch, n as fileStamp, o as r
2
2
  import { _ as STUDIO_HOSTNAME, a as InvalidInputError, b as readPrismaConfig, c as ServerListenError, d as DatabaseError, g as SSE_PING_MS, h as PRISMA_FILE_URI, i as FormatError, l as UnknownFileError, m as MIGRATIONS_POLL_MS, n as ClientUnavailableError, o as SchemaLoadError, p as FORBIDDEN_HOST_MESSAGE, r as FileWriteError, s as SchemaParseError, t as ClientQueryError, u as UnknownModelError } from "./bin/hekireki.js";
3
3
  import { R as fmt, d as makePostgresSchema, i as readSchemaFiles$1, m as formatSql, n as parseSchema, r as readConfig } from "./schema-CyJTUCF1.js";
4
4
  import { c as makeSchema, i as openSchemaEngine, n as openNativeSchemaEngine, o as makeSchemaEngineAdapter, r as engineCommand, s as makeAnalysisSchema, t as findSchemaEngineBinary } from "./native-engine-DeQEnJxi.js";
5
- import { r as lowerFirst } from "./case-D3JCqTLI.js";
5
+ import { r as lowerFirst } from "./case-CCSiaowC.js";
6
6
  import { a as splitStatements, i as MigrationNotFoundError, l as toTsType, n as MigrateDatabaseError, s as literalDataType, t as MigrateConfigError } from "./errors-CRIxtr-P.js";
7
7
  import { f as placeholder, h as stringLiteral, i as withTypeScriptImports, m as quoteIdentifier, o as readConfigUrl, p as qualifiedName } from "./sql-LMMCiAlf.js";
8
8
  import { _ as openSqliteCopy, a as makePlan$1, c as checkOpened, d as DECISIONS_FILE, f as readDecisions, g as openShadowDatabase, h as openMysqlCopy, m as connectDatabase, p as writeDecisions, u as introspectDatabase } from "./plan-8rsBBJcs.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hekireki",
3
- "version": "0.52.2",
3
+ "version": "0.52.4",
4
4
  "description": "Hekireki is a code generator from Prisma schema to validation schemas, ORM models, OpenAPI and ER diagrams, with a Studio for your schema and its data",
5
5
  "keywords": [
6
6
  "activerecord",