-
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.
fix: Issue with matching names when overwritting field names to @Map …
…names (#115) If field names were equal in different models, for example `id`, and you had an `@map` to overwrite that default field name, the generator would grab the first name instead of the correct name in each model.
- Loading branch information
Showing
12 changed files
with
7,573 additions
and
18,723 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings | ||
|
||
DATABASE_URL="postgresql://johndoe:[email protected]:6543/mydb?schema=public" | ||
ERD_DEBUG=true | ||
|
||
<!-- ERD_DEBUG=true --> |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.DS_Store | ||
node_modules | ||
dist | ||
prisma.mmd | ||
prisma.mmd | ||
prisma/debug |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
import * as child_process from 'child_process'; | ||
|
||
test('space removal in mapped field names', async () => { | ||
const fileName = '114.svg'; | ||
const folderName = '__tests__'; | ||
child_process.execSync(`rm -f ${folderName}/${fileName}`); | ||
child_process.execSync( | ||
`npx prisma generate --schema ./prisma/issues/114.prisma` | ||
); | ||
const svgContent = child_process | ||
.execSync(`cat ${folderName}/${fileName}`) | ||
.toString(); | ||
// did the model get added | ||
expect(svgContent).toContain('orders'); | ||
expect(svgContent).toContain('customers'); | ||
expect(svgContent).toContain('employees'); | ||
expect(svgContent).toContain('stores'); | ||
// did the field mapped names get added | ||
expect(svgContent).toContain('customer_id'); | ||
expect(svgContent).toContain('store_id'); | ||
expect(svgContent).toContain('employee_id'); | ||
expect(svgContent).toContain('order_id'); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -35,7 +35,9 @@ | |
"keywords": [ | ||
"Prisma", | ||
"TypeScript", | ||
"Mermaid" | ||
"Mermaid", | ||
"Entity Relationship Diagram", | ||
"ERD" | ||
], | ||
"contributors": [ | ||
{ | ||
|
@@ -44,18 +46,18 @@ | |
} | ||
], | ||
"devDependencies": { | ||
"@babel/core": "^7.18.6", | ||
"@babel/preset-env": "^7.18.6", | ||
"@babel/core": "^7.18.9", | ||
"@babel/preset-env": "^7.18.9", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@types/jest": "^28.1.4", | ||
"@types/jest": "^28.1.6", | ||
"all-contributors-cli": "^6.20.0", | ||
"babel-jest": "^28.1.2", | ||
"concurrently": "^7.2.2", | ||
"babel-jest": "^28.1.3", | ||
"concurrently": "^7.3.0", | ||
"husky": "^8.0.1", | ||
"jest": "^28.1.2", | ||
"jest": "^28.1.3", | ||
"lint-staged": "^13.0.3", | ||
"prettier": "2.7.1", | ||
"prisma": "^4.0.0", | ||
"prisma": "^4.1.0", | ||
"standard-version": "^9.5.0", | ||
"tslib": "^2.4.0", | ||
"typescript": "^4.7.4" | ||
|
@@ -65,14 +67,15 @@ | |
"**/*.ts": "npm run test" | ||
}, | ||
"dependencies": { | ||
"@mermaid-js/mermaid-cli": "^9.1.3", | ||
"@prisma/client": "^4.0.0", | ||
"@prisma/generator-helper": "^4.0.0", | ||
"@mermaid-js/mermaid-cli": "^9.1.4", | ||
"@prisma/client": "^4.1.0", | ||
"@prisma/generator-helper": "^4.1.0", | ||
"dotenv": "^16.0.1" | ||
}, | ||
"peerDependencies": { | ||
"@mermaid-js/mermaid-cli": "^9.1.3", | ||
"@mermaid-js/mermaid-cli": "^9.1.4", | ||
"@prisma/client": "^4.0.0", | ||
"@prisma/generator-helper": "^4.0.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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,49 @@ | ||
generator erd { | ||
provider = "node ./dist/index.js" | ||
output = "../../__tests__/114.svg" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Store { | ||
id String @id @default(uuid()) @map("store_id") | ||
employees Employee[] | ||
customers Customer[] | ||
@@map("stores") | ||
} | ||
|
||
model Employee { | ||
id String @id @default(uuid()) @map("employee_id") | ||
storeId String @map("store_id") | ||
store Store @relation(fields: [storeId], references: [id]) | ||
orders Order[] | ||
@@map("employees") | ||
} | ||
|
||
model Customer { | ||
id String @id @default(uuid()) @map("customer_id") | ||
storeId String @map("store_id") | ||
store Store @relation(fields: [storeId], references: [id]) | ||
orders Order[] | ||
@@map("customers") | ||
} | ||
|
||
model Order { | ||
id String @id @default(uuid()) @map("order_id") | ||
employeeId String @map("employee_id") | ||
customerId String @map("customer_id") | ||
employee Employee @relation(fields: [employeeId], references: [id]) | ||
customer Customer @relation(fields: [customerId], references: [id]) | ||
@@map("orders") | ||
} |
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