-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added possibility to generate diagram with relation fields and …
…Fixed generation of ERD with composite keys.(Closes #135) (#136) * Fixed composite primary keys * Added possibility to show relation fields in the result diagram
- Loading branch information
1 parent
7b1e27c
commit f36325b
Showing
7 changed files
with
212 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ dist | |
prisma.mmd | ||
prisma/debug | ||
coverage | ||
!__test__/*.ts | ||
!__test__/*.ts | ||
__tests__/*.svg | ||
__tests__/*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as child_process from 'child_process'; | ||
|
||
test('composite-pk.prisma', async () => { | ||
const fileName = 'CompositePk.svg'; | ||
const folderName = '__tests__'; | ||
child_process.execSync(`rm -f ${folderName}/${fileName}`); | ||
child_process.execSync( | ||
`npx prisma generate --schema ./prisma/composite-pk.prisma` | ||
); | ||
const listFile = child_process.execSync(`ls -la ${folderName}/${fileName}`); | ||
// did it generate a file | ||
expect(listFile.toString()).toContain(fileName); | ||
|
||
const svgAsString = child_process | ||
.execSync(`cat ${folderName}/${fileName}`) | ||
.toString(); | ||
|
||
const pks = svgAsString.match(/PK/g); | ||
|
||
// did it generate a file with the correct content | ||
expect(svgAsString).toContain(`<svg`); | ||
expect(svgAsString).toContain(`Booking`); | ||
expect(pks).toHaveLength(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as child_process from 'child_process'; | ||
|
||
test('include-relation-from-fields.prisma', async () => { | ||
const fileName = 'includeRelationFromFields.svg'; | ||
const folderName = '__tests__'; | ||
child_process.execSync(`rm -f ${folderName}/${fileName}`); | ||
child_process.execSync( | ||
`npx prisma generate --schema ./prisma/include-relation-from-fields.prisma` | ||
); | ||
const listFile = child_process.execSync(`ls -la ${folderName}/${fileName}`); | ||
// did it generate a file | ||
expect(listFile.toString()).toContain(fileName); | ||
|
||
const svgAsString = child_process | ||
.execSync(`cat ${folderName}/${fileName}`) | ||
.toString(); | ||
|
||
// did it generate a file with the correct content | ||
expect(svgAsString).toContain(`<svg`); | ||
expect(svgAsString).toContain(`User`); | ||
expect(svgAsString).toContain(`Product`); | ||
expect(svgAsString).toContain(`FavoriteProducts`); | ||
expect(svgAsString).toContain(`userId`); | ||
expect(svgAsString).toContain(`productId`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
generator erd { | ||
provider = "node ./dist/index.js" | ||
output = "../__tests__/CompositePk.svg" | ||
theme = "forest" | ||
} | ||
|
||
model Booking { | ||
id1 Int | ||
id2 Int | ||
inviteeEmail String | ||
startDateUTC DateTime | ||
cancelCode String | ||
@@id([id1, id2]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
generator erd { | ||
provider = "node ./dist/index.js" | ||
output = "../__tests__/includeRelationFromFields.svg" | ||
theme = "forest" | ||
includeRelationFromFields = true | ||
} | ||
|
||
model User { | ||
id String @id | ||
email String | ||
favoriteProducts FavoriteProducts[] | ||
} | ||
|
||
|
||
model Product { | ||
id String @id | ||
title String | ||
inFavorites FavoriteProducts[] | ||
} | ||
|
||
model FavoriteProducts { | ||
userId String | ||
user User @relation(fields: [userId], references: [id]) | ||
productId String | ||
product Product @relation(fields: [productId], references: [id]) | ||
@@id([userId, productId]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters