Skip to content

Commit 3a3c620

Browse files
committed
Column size notation has been added. 🐛 The constraint is changed from being displayed as one to multiple.
1 parent 2b5794a commit 3a3c620

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

ERD.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,13 @@ erDiagram
432432
}
433433
"shopping_sellers" {
434434
String id PK
435-
String shopping_member_id FK
435+
String shopping_member_id FK,UK
436436
DateTime created_at
437437
DateTime deleted_at "nullable"
438438
}
439439
"shopping_administrators" {
440440
String id PK
441-
String shopping_member_id FK
441+
String shopping_member_id FK,UK
442442
DateTime created_at
443443
DateTime deleted_at "nullable"
444444
}
@@ -1440,7 +1440,7 @@ erDiagram
14401440
}
14411441
"shopping_order_publishes" {
14421442
String id PK
1443-
String shopping_order_id FK
1443+
String shopping_order_id FK,UK
14441444
String shopping_address_id FK
14451445
String password "nullable"
14461446
DateTime created_at
@@ -1784,24 +1784,24 @@ erDiagram
17841784
Int sequence
17851785
}
17861786
"shopping_coupon_section_criterias" {
1787-
String id PK
1787+
String id PK,FK
17881788
String shopping_section_id FK
17891789
}
17901790
"shopping_coupon_channel_criterias" {
1791-
String id PK
1791+
String id PK,FK
17921792
String shopping_channel_id FK
17931793
String shopping_channel_category_id FK "nullable"
17941794
}
17951795
"shopping_coupon_seller_criterias" {
1796-
String id PK
1796+
String id PK,FK
17971797
String shopping_seller_id FK
17981798
}
17991799
"shopping_coupon_sale_criterias" {
1800-
String id PK
1800+
String id PK,FK
18011801
String shopping_sale_id FK
18021802
}
18031803
"shopping_coupon_funnel_criterias" {
1804-
String id PK
1804+
String id PK,FK
18051805
String kind
18061806
String key "nullable"
18071807
String value
@@ -1810,13 +1810,13 @@ erDiagram
18101810
String id PK
18111811
String shopping_customer_id FK
18121812
String shopping_coupon_id FK
1813-
String shopping_coupon_disposable_id FK "nullable"
1813+
String shopping_coupon_disposable_id FK,UK "nullable"
18141814
DateTime created_at
18151815
DateTime expired_at "nullable"
18161816
}
18171817
"shopping_coupon_ticket_payments" {
18181818
String id PK
1819-
String shopping_coupon_ticket_id FK
1819+
String shopping_coupon_ticket_id FK,UK
18201820
String shopping_order_id FK
18211821
Int sequence
18221822
DateTime created_at
@@ -2228,7 +2228,7 @@ erDiagram
22282228
}
22292229
"shopping_deposit_charge_publishes" {
22302230
String id PK
2231-
String shopping_deposit_charge_id FK
2231+
String shopping_deposit_charge_id FK,UK
22322232
String password "nullable"
22332233
DateTime created_at
22342234
DateTime paid_at "nullable"
@@ -2474,32 +2474,32 @@ outcome. The minus value must be expressed by multiplying the
24742474
```mermaid
24752475
erDiagram
24762476
"shopping_sale_snapshot_inquiries" {
2477-
String id PK
2477+
String id PK,FK
24782478
String shopping_sale_snapshot_id FK
24792479
String shopping_customer_id FK
24802480
String type
24812481
DateTime created_at
24822482
DateTime read_by_seller_at "nullable"
24832483
}
24842484
"shopping_sale_snapshot_questions" {
2485-
String id PK
2485+
String id PK,FK
24862486
Boolean secret
24872487
}
24882488
"shopping_sale_snapshot_reviews" {
2489-
String id PK
2489+
String id PK,FK
24902490
String shopping_order_good_id FK
24912491
}
24922492
"shopping_sale_snapshot_review_snapshots" {
2493-
String id PK
2493+
String id PK,FK
24942494
Float score
24952495
}
24962496
"shopping_sale_snapshot_inquiry_answers" {
2497-
String id PK
2498-
String shopping_sale_snapshot_inquiry_id FK
2497+
String id PK,FK
2498+
String shopping_sale_snapshot_inquiry_id FK,UK
24992499
String shopping_seller_customer_id FK
25002500
}
25012501
"shopping_sale_snapshot_inquiry_comments" {
2502-
String id PK
2502+
String id PK,FK
25032503
String shopping_customer_id FK
25042504
String actor_type
25052505
}
@@ -2750,7 +2750,7 @@ erDiagram
27502750
DateTime created_at
27512751
}
27522752
"shopping_sale_snapshot_inquiries" {
2753-
String id PK
2753+
String id PK,FK
27542754
String shopping_sale_snapshot_id FK
27552755
String shopping_customer_id FK
27562756
String type

src/writers/MermaidWriter.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DMMF } from "@prisma/generator-helper";
22
import { PrismaUtil } from "../utils/PrismaUtil";
3+
import { FieldUtil } from "../utils/field-util";
34

45
export namespace MermaidWriter {
56
export const write = (chapter: DMMF.Model[]) =>
@@ -30,25 +31,23 @@ export namespace MermaidWriter {
3031

3132
const writeField =
3233
(model: DMMF.Model) =>
33-
(field: DMMF.Field): string =>
34-
[
35-
field.type, // type
36-
field.dbName ?? field.name, // name
37-
field.isId
38-
? "PK"
39-
: model.fields.some(
40-
(f) =>
41-
f.kind === "object" &&
42-
f.relationFromFields?.[0] === field.name,
43-
)
44-
? "FK"
45-
: field.isUnique
46-
? "UK"
47-
: "", // constraint
48-
field.isRequired ? "" : `"nullable"`, // nullable
34+
(field: DMMF.Field): string => {
35+
const isFK = model.fields.some(
36+
(f) => f.kind === "object" && f.relationFromFields?.[0] === field.name,
37+
);
38+
const targetField = FieldUtil(field, isFK);
39+
40+
return [
41+
targetField.data().size
42+
? targetField.format("t(s)")
43+
: targetField.format("t"),
44+
targetField.format("n"),
45+
targetField.format("k"),
46+
targetField.format("r"),
4947
]
5048
.filter((str) => !!str.length)
5149
.join(" ");
50+
};
5251

5352
const writeRelationship =
5453
(props: { group: DMMF.Model[]; model: DMMF.Model }) =>

test/drive.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,21 @@ erDiagram
451451
String drive_repository_folder_id FK "nullable"
452452
String drive_customer_id FK
453453
String type
454-
String name
454+
String(255) name
455455
DateTime created_at
456456
DateTime updated_at
457457
DateTime deleted_at "nullable"
458458
}
459459
"drive_repository_folders" {
460-
String id PK
460+
String id PK,FK
461461
}
462462
"drive_repository_files" {
463-
String id PK
464-
String extension "nullable"
463+
String id PK,FK
464+
String(8) extension "nullable"
465465
String url
466466
}
467467
"drive_repository_shortcuts" {
468-
String id PK
468+
String id PK,FK
469469
String drive_repository_bucket_id FK
470470
}
471471
"drive_repository_accesses" {

0 commit comments

Comments
 (0)