Skip to content

Commit 2a13128

Browse files
committed
feat(dbml): add autogenerated comment
1 parent fd56524 commit 2a13128

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prisma DBML Generator
22

3-
Automatically generate a [DBML](https://www.dbml.org/home) schema from your Prisma Schema. Updates every time `npx prisma generate` runs. Use [dbdiagram.io](https://dbdiagram.io/home) to visualize your `dbml` files:
3+
Automatically generate a [DBML](https://www.dbml.org/home) schema from your Prisma Schema. Updates every time `npx prisma generate` runs. Use [dbdiagram.io](https://dbdiagram.io/home) to visualize your `dbml` files as Entity-Relationship Diagram:
44

55
![DB Diagram](./dbdiagram.png)
66

__tests__/dbml.test.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import {
55
datamodelDbmlRelations,
66
} from './fixtures/dbml.datamodel';
77
import { generateDMMF } from './utils/generateDMMF';
8-
import { generateDBMLSchema } from '../src/generator/dbml';
8+
import {
9+
autoGeneratedComment,
10+
generateDBMLSchema,
11+
} from '../src/generator/dbml';
912

1013
describe('DBML', () => {
1114
test('generating simple dbml schema', async () => {
1215
const dmmf = await generateDMMF(datamodelDbml);
1316

14-
const expectedDbml = `Table User {
17+
const expectedDbml = `${autoGeneratedComment}
18+
19+
Table User {
1520
id Int [pk, increment]
1621
name String [not null]
1722
profile Profile
@@ -40,7 +45,9 @@ Ref: Profile.userId - User.id`;
4045
test('generating dbml schema with comments', async () => {
4146
const dmmf = await generateDMMF(datamodelDbmlComments);
4247

43-
const expectedDbml = `Table User {
48+
const expectedDbml = `${autoGeneratedComment}
49+
50+
Table User {
4451
id Int [pk, increment]
4552
name String [not null]
4653
profile Profile
@@ -71,7 +78,9 @@ Ref: Profile.userId - User.id`;
7178
test('generating dbml schema with defaults', async () => {
7279
const dmmf = await generateDMMF(datamodelDbmlDefaults);
7380

74-
const expectedDbml = `Table User {
81+
const expectedDbml = `${autoGeneratedComment}
82+
83+
Table User {
7584
id String [pk]
7685
createdAt DateTime [default: \`now()\`, not null]
7786
name String
@@ -105,7 +114,9 @@ Ref: Post.authorId > User.id`;
105114
test('generating dbml schema with relationships', async () => {
106115
const dmmf = await generateDMMF(datamodelDbmlRelations);
107116

108-
const expectedDbml = `Table User {
117+
const expectedDbml = `${autoGeneratedComment}
118+
119+
Table User {
109120
id Int [pk, increment]
110121
posts Post
111122
profile Profile

prisma/dbml/schema.dbml

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//// ------------------------------------------------------
2+
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
3+
//// ------------------------------------------------------
4+
15
Table User {
26
id Int [pk, increment]
37
createdAt DateTime [default: `now()`, not null]

src/generator/dbml.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { generateTables } from './table';
33
import { generateEnums } from './enums';
44
import { generateRelations } from './relations';
55

6+
export const autoGeneratedComment = `//// ------------------------------------------------------
7+
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
8+
//// ------------------------------------------------------`;
9+
610
export function generateDBMLSchema(dmmf: DMMF.Document): string {
711
const tables = generateTables(dmmf.datamodel.models);
812
const enums = generateEnums(dmmf.datamodel.enums);
913
const refs = generateRelations(dmmf.datamodel.models);
1014

11-
return [...tables, ...enums, ...refs].join('\n\n');
15+
return [autoGeneratedComment, ...tables, ...enums, ...refs].join('\n\n');
1216
}

0 commit comments

Comments
 (0)