Skip to content

wire up prisma-dbml-generator so every prisma generate run produces a fresh schema.dbml for fresh ERD #933

Description

@iamtanuj18

application/backend/prisma/schema.prisma is the source of truth for CTRL's data model.

suggestion: wire up prisma-dbml-generator so every prisma generate run produces a fresh schema.dbml locally. The DBML file can itself be gitignored (intermediate artifact). When the schema changes, the developer pastes the fresh DBML into the dbdiagram.io project to keep the shared interactive ERD in sync, then exports the rendered SVG from dbdiagram.io and commits that into the ctrl-docs repo.

four tools were evaluated before going ahead with DBML — yamltools.dev, vanilla prisma-erd-generator, a forked version of it, and prisma-dbml-generator. Only the DBML path hits full accuracy for CTRL's schema features (@encrypted fields, @encryption:hash(x) markers, cascade rules, compound uniques, composite PKs) once rendered through dbdiagram.io.

Suggested implementation:

  1. yarn workspace backend add -D prisma-dbml-generator
  2. Add generator dbml { provider = "prisma-dbml-generator", output = "./dbml", outputName = "schema.dbml", projectName = "CTRL", projectDatabaseType = "PostgreSQL", includeRelationFields = "true" } to schema.prisma
  3. Add application/backend/prisma/dbml/ to .gitignore so the generated DBML stays local
  4. Run yarn workspace backend prisma generate once to produce the initial schema.dbml
  5. Create a dbdiagram.io project (free tier), paste the DBML content in, save, and grab the shareable URL for the interactive view
  6. Export the rendered ERD as SVG from dbdiagram.io and commit it into the ctrl-docs repo

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbackend taskdocumentationImprovements or additions to documentation

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions