Skip to content

Commit

Permalink
feat: Nullable keys in ERD
Browse files Browse the repository at this point in the history
  • Loading branch information
keonik committed May 26, 2022
1 parent c792db7 commit f7d7304
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ERD.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/36.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/66.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/73.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/CompositeTypes.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/Enums.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/ManyToMany.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/Mappings.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion __tests__/MongoDB.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/nullables.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions __tests__/nullables.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as child_process from 'child_process';

test('nullables.prisma', async () => {
const fileName = 'nullables.svg';
const folderName = '__tests__';
child_process.execSync(`rm -f ${folderName}/${fileName}`);
child_process.execSync(
`npx prisma generate --schema ./prisma/nullables.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(`nullable`);
expect(svgAsString).toContain(`inviteeEmail`);
expect(svgAsString).toContain(`cancelCode`);
expect(svgAsString).toContain(`name`);
});
2 changes: 1 addition & 1 deletion __tests__/simple-1-n.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions prisma/nullables.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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__/nullables.svg"
}

model Booking {
id Int @id @default(autoincrement())
inviteeEmail String?
startDateUTC DateTime
cancelCode String?
events Event[]
}

model Event {
id Int @id @default(autoincrement())
name String?
startDate DateTime
bookings Booking[]
}
4 changes: 3 additions & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ ${
` ${field.type.trimStart()} ${field.name.replace(
/^_/,
'z_'
)}`
)} ${field.isId ? 'PK' : ''} ${
field.isRequired ? '' : '"nullable"'
}`
)
.join('\n')
}
Expand Down

0 comments on commit f7d7304

Please sign in to comment.