Skip to content

Wire up prisma-dbml-generator so schema.dbml regenerates on prisma:generate - #935

Open
iamtanuj18 wants to merge 3 commits into
devfrom
933-add-erd-generation
Open

Wire up prisma-dbml-generator so schema.dbml regenerates on prisma:generate#935
iamtanuj18 wants to merge 3 commits into
devfrom
933-add-erd-generation

Conversation

@iamtanuj18

Copy link
Copy Markdown

Fixes #933.

Wires up prisma-dbml-generator as a Prisma generator so application/backend/prisma/dbml/schema.dbml regenerates automatically on every yarn workspace backend prisma:generate. The DBML file is committed to git alongside schema.prisma so its diff surfaces on schema-touching PRs and reviewers see the structural change alongside the code change.

For the interactive visual, the DBML content pastes into a dbdiagram.io project at https://dbdiagram.io/d/CTRL-ERD-6a7554fa35ee2e87b04f19e0 which renders it with clickable relationships, hover tooltips for encryption metadata (@encrypted, @encryption:hash(x)), and pan/zoom. The interactive URL isn't auto-synced from the repo. Someone has to paste the fresh DBML in whenever the schema changes.

What's added

  • prisma-dbml-generator as a dev dep in the backend workspace
  • generator dbml { ... } block in schema.prisma configured for CTRL, PostgreSQL, and to include relation fields (needed so FK columns render)
  • application/backend/prisma/dbml/schema.dbml (auto-generated, 267 lines, matches the current schema including all @encrypted and @encryption:hash(x) notes)
  • prisma:erd:check script chained after every prisma:generate. Uses git diff --exit-code on the committed DBML to detect drift and prints a warning nudging whoever ran it to paste the new content into the dbdiagram.io project.

Known limitations

  1. Manual sync to dbdiagram.io. prisma-dbml-generator produces DBML text only, not SVG or any interactive rendering. dbdiagram.io doesn't expose an API for programmatic diagram updates on any tier, so keeping the interactive view current requires someone to paste the fresh DBML in. The prisma:erd:check warning nudges devs when they run prisma:generate locally, but the paste step itself is manual.

  2. Single editor on dbdiagram.io free tier. The CTRL project sits on my personal account so only I can update the pasted DBML. Worth migrating to a shared/team-owned account later within free tier perhaps.

  3. Manual npx prisma generate bypasses the check. All standard yarn workflows fire the drift check — yarn prisma:generate, yarn build, yarn prisma:migrate (and make seed since it calls migrate). The only path that skips is someone typing npx prisma generate or prisma generate directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant