Skip to content

Create ER diagram during build#868

Merged
jmezach merged 18 commits intorr-wfm:masterfrom
ErikEJ:er-diagram
Apr 2, 2026
Merged

Create ER diagram during build#868
jmezach merged 18 commits intorr-wfm:masterfrom
ErikEJ:er-diagram

Conversation

@ErikEJ
Copy link
Copy Markdown
Collaborator

@ErikEJ ErikEJ commented Mar 17, 2026

fixes #867

@jmezach Decided to make it optional, and add to templates to make it visible.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds automatic Mermaid ER diagram generation as part of the SQL project build process. It extracts table, column, primary key, and foreign key metadata from the DacFX model and produces a .md file containing a Mermaid erDiagram block.

Changes:

  • New Diagram/ module in DacpacTool with model classes, DacFX-to-model extraction, and Mermaid rendering
  • New --ged CLI option and MSBuild property GenerateErDiagram (enabled by default) to trigger diagram generation
  • Test coverage for the diagram builder

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Converts simplified table model to Mermaid ER diagram syntax
src/DacpacTool/Diagram/DacpacModelFactory.cs Extracts tables/columns/keys from TSqlModel into simple model classes
src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Orchestrates diagram generation and file output
src/DacpacTool/Diagram/Model/*.cs Simple POCO model classes for tables, columns, keys
src/DacpacTool/BuildOptions.cs Adds GenerateErDiagram CLI option
src/DacpacTool/Program.cs Calls diagram builder when option is set
src/DacpacTool/DacpacTool.csproj Bumps LangVersion to 12.0
src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props Adds GenerateErDiagram default property (true)
src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Passes --ged flag and copies .md artifacts
test/DacpacTool.Tests/DiagramBuilderTests.cs Test for basic diagram generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.props Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs
@ErikEJ ErikEJ requested review from jeffrosenberg and jmezach March 17, 2026 13:16
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/Diagram/DacpacModelFactory.cs Outdated
Comment thread test/DacpacTool.Tests/DiagramBuilderTests.cs
@jmezach
Copy link
Copy Markdown
Member

jmezach commented Mar 18, 2026

@ErikEJ This is off to a great start I think, just a couple of comments. Also, do we have an example of what the output looks like?

@ErikEJ
Copy link
Copy Markdown
Collaborator Author

ErikEJ commented Mar 18, 2026

@jmezach Re "example" do you mean the rendered graphic? I can add one a link to it from the missing new readme section perhaps?

@jmezach
Copy link
Copy Markdown
Member

jmezach commented Mar 18, 2026

@ErikEJ Yeah, it was really just to satisfy my curiosity I guess ;). But I think it would be useful to have an example graphic in our README so that folks know what the feature would do

Comment thread src/DacpacTool/Diagram/DacpacModelFactory.cs Outdated
Comment thread src/DacpacTool/Diagram/Model/SimpleTable.cs Outdated
@ErikEJ
Copy link
Copy Markdown
Collaborator Author

ErikEJ commented Mar 19, 2026

@jmezach A smaller example like the one here?? #867

@jmezach
Copy link
Copy Markdown
Member

jmezach commented Mar 19, 2026

@ErikEJ Yeah I think a slightly smaller one would be useful to have in the README. Perhaps we can just generate one from our test projects and stick that into the README?

@ErikEJ ErikEJ requested a review from Copilot March 19, 2026 13:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional ER diagram generation (Mermaid markdown) to the SQLProj build pipeline, exposing it via an MSBuild property / CLI flag and surfacing it in the project template + documentation.

Changes:

  • Add GenerateErDiagram MSBuild property support that forwards a new --ged flag to DacpacTool and copies generated *_erdiagram.md to the output directory.
  • Implement ER diagram generation in DacpacTool by extracting tables/PKs/FKs from the DacFx model and emitting Mermaid ER markdown.
  • Add template option + README documentation and a unit test for diagram generation.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
test/TestProject/TestProject.csproj Enables ER diagram generation in the test project.
test/DacpacTool.Tests/DiagramBuilderTests.cs Adds a unit test validating Mermaid ER output and filtering out non-table objects.
src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Adds build argument (--ged) and copies *_erdiagram.md artifacts to output.
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/sqlproj.csproj Adds GenerateErDiagram property placeholder to the template.
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/.template.config/template.json Adds erDiagram boolean template parameter.
src/DacpacTool/Program.cs Invokes ER diagram generation during build when enabled.
src/DacpacTool/Diagram/Model/Simple*.cs Introduces simplified table/column/key model for diagram generation.
src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Writes the ER diagram markdown file next to the built dacpac.
src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Converts simplified model to Mermaid ER diagram text.
src/DacpacTool/Diagram/DacpacModelFactory.cs Extracts tables/columns/PK/FK info from TSqlModel.
src/DacpacTool/DacpacTool.csproj Bumps C# language version to support new syntax used by diagram code.
src/DacpacTool/BuildOptions.cs Adds --generateerdiagram / --ged CLI option.
README.md Documents enabling and output of ER diagram generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs
Comment thread README.md Outdated
Comment thread src/DacpacTool/Diagram/DacpacModelFactory.cs
Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Outdated
Comment thread README.md Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional build-time feature to generate a Mermaid ER diagram from the built dacpac, exposing it via MSBuild + CLI, surfacing it in the project template, and documenting the new capability.

Changes:

  • Add GenerateErDiagram MSBuild property and pass through to DacpacTool build via a new CLI switch.
  • Implement ER diagram generation by enumerating the DacFx model (tables/PK/FK/columns) and writing a *_erdiagram.md Mermaid file.
  • Add template + documentation updates and a basic unit test for diagram generation.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
test/TestProject/TestProject.csproj Enables ER diagram generation in the test project.
test/DacpacTool.Tests/DiagramBuilderTests.cs Adds a unit test validating basic Mermaid output.
src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Adds the build argument and copies generated *_erdiagram.md artifacts to output.
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/sqlproj.csproj Exposes GenerateErDiagram in the project template.
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/.template.config/template.json Adds a template parameter to toggle ER diagram generation.
src/DacpacTool/Program.cs Invokes ER diagram generation during build when enabled.
src/DacpacTool/BuildOptions.cs Adds the --generateerdiagram option (with alias).
src/DacpacTool/DacpacTool.csproj Bumps C# language version to support new syntax used by diagram model types.
src/DacpacTool/Diagram/Model/SimpleTable.cs Adds a simplified table model for diagram generation.
src/DacpacTool/Diagram/Model/SimplePrimaryKey.cs Adds a simplified PK model.
src/DacpacTool/Diagram/Model/SimpleForeignKey.cs Adds a simplified FK model.
src/DacpacTool/Diagram/Model/SimpleColumn.cs Adds a simplified column model.
src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Adds ErDiagramBuilder to generate and write the Mermaid markdown file.
src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Renders the simplified database model to Mermaid ER syntax.
src/DacpacTool/Diagram/DacpacModelFactory.cs Extracts tables/columns/PK/FK/type info from the DacFx TSqlModel.
README.md Documents the new ER diagram feature and how to enable it.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs
Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Outdated
Comment thread README.md Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Outdated
Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread src/DacpacTool/BuildOptions.cs Outdated
Comment thread README.md Outdated
Copy link
Copy Markdown
Member

@jmezach jmezach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think it makes sense to ship this as a 4.1 release. Just some merge conflicts to resolve now though ;).

Comment thread src/DacpacTool/Diagram/Model/SimpleColumn.cs
@nmummau
Copy link
Copy Markdown
Contributor

nmummau commented Mar 26, 2026

There might be an issue with duplicate table names across schemas. I created a PR on your fork: ErikEJ#157

@jmezach
Copy link
Copy Markdown
Member

jmezach commented Mar 26, 2026

@jeffrosenberg Can you have a look at this? I think this is good to merge.

@jmezach
Copy link
Copy Markdown
Member

jmezach commented Apr 1, 2026

@ErikEJ Looks like there are some conflicts here now that need resolving. I would love for this feature to land soon, perhaps @nmummau can do a review on this?

@ErikEJ ErikEJ requested a review from nmummau April 1, 2026 07:34
@ErikEJ
Copy link
Copy Markdown
Collaborator Author

ErikEJ commented Apr 1, 2026

@jmezach Merge conflict fixed now

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional build-time generation of a Mermaid ER diagram from the produced dacpac (via DacFx model enumeration), and surfaces the option in templates and docs.

Changes:

  • Adds GenerateEntityRelationshipDiagram MSBuild property, wiring it to a new -ged/--generateerdiagram option in DacpacTool build.
  • Introduces diagram generation implementation (model extraction + Mermaid rendering) and a unit test covering basic output.
  • Updates template + README to expose and document the feature, and copies the generated *_erdiagram.md into the build output.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/TestProject/TestProject.csproj Enables ER diagram generation in test project properties.
test/TestProject/TestProject_erdiagram.md Adds an example generated Mermaid markdown diagram artifact.
test/DacpacTool.Tests/DiagramBuilderTests.cs Adds unit test validating diagram generation output content.
src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Adds -ged argument wiring and copies diagram artifacts to $(TargetDir).
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/sqlproj.csproj Adds template property placeholder for ER diagram generation.
src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/.template.config/template.json Adds a boolean template parameter to toggle ER diagram generation.
src/DacpacTool/Program.cs Invokes diagram generation after successful build when enabled.
src/DacpacTool/Diagram/Model/SimpleTable.cs Introduces simplified table model for diagram generation.
src/DacpacTool/Diagram/Model/SimplePrimaryKey.cs Introduces simplified PK model for diagram generation.
src/DacpacTool/Diagram/Model/SimpleForeignKey.cs Introduces simplified FK model for diagram generation.
src/DacpacTool/Diagram/Model/SimpleColumn.cs Introduces simplified column model for diagram generation.
src/DacpacTool/Diagram/MermaidDiagramBuilder.cs Implements diagram creation + file emission.
src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Renders simplified model as Mermaid erDiagram markdown.
src/DacpacTool/Diagram/DacpacModelFactory.cs Extracts tables/columns/PKs/FKs/types from TSqlModel.
src/DacpacTool/BuildOptions.cs Adds CLI option to enable ER diagram generation.
README.md Documents the new GenerateEntityRelationshipDiagram feature and output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/DacpacTool/Diagram/MermaidDiagramBuilder.cs
Comment thread src/MSBuild.Sdk.SqlProj/Sdk/Sdk.targets Outdated
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs Outdated
Comment thread test/DacpacTool.Tests/DiagramBuilderTests.cs
Comment thread README.md Outdated
@ErikEJ ErikEJ requested a review from jmezach April 1, 2026 08:47
Comment thread src/DacpacTool/Diagram/Model/SimpleTable.cs
Comment thread src/DacpacTool/Diagram/DatabaseModelToMermaid.cs
@jmezach
Copy link
Copy Markdown
Member

jmezach commented Apr 2, 2026

@ErikEJ I would suggest doing an override here so that we can merge this. My guess is that @jeffrosenberg doesn't currently have the bandwidth to review this (which is totally fine) and we already have two reviewers + copilot feedback anyway.

@ErikEJ
Copy link
Copy Markdown
Collaborator Author

ErikEJ commented Apr 2, 2026

@jmezach sounds good, but only you can override 😳

@jmezach jmezach merged commit c9a5c80 into rr-wfm:master Apr 2, 2026
14 checks passed
@jmezach
Copy link
Copy Markdown
Member

jmezach commented Apr 2, 2026

@ErikEJ Done. Shall we ship this as 4.1?

@ErikEJ
Copy link
Copy Markdown
Collaborator Author

ErikEJ commented Apr 2, 2026

Let's do that!

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.

Create Mermaid ER diagram as part of build

5 participants