Repository navigation
Feature/database schema diagram - #56
Open
MarcAntoineGmd wants to merge 2 commits into
Open
MarcAntoineGmd wants to merge 2 commits into
MarcAntoineGmd wants to merge 2 commits into
Conversation
MarcAntoineGmd
requested review from
anis022 and
lauriechammah
and removed request for
lauriechammah
November 8, 2026 03:53
lauriechammah
requested changes
Nov 8, 2026
lauriechammah
left a comment
Collaborator
There was a problem hiding this comment.
See requested changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17
Overview
The goal of this ticket is to produce a clear diagram and short documentation of the full database schema, ready to present to Nafissa at the end of the sprint.
Diagram:
docs/database/schema.dbmldescribes all 6 tables (roles, users, donors, food_items, receipts, receipt_items) with every column, key, index, check and link, plus the four roles. The tables are grouped into Accounts, Donations and Tax receipts, so the dbdiagram.io export reads by part.Documentation:
docs/database/schema.mdis written for non-developers. It covers:A "For developers" section at the end lists the migrations, SQL scripts and detailed pages.
The diagram is tested against the migrations. New tests build an empty PostgreSQL 17 database from the migrations, read its real structure and compare it with every
.dbmlfile indocs/database/. The comparison covers:Any difference fails the test with a readable message, so the diagram cannot drift from the migrations unnoticed.
Changes:
docs/database/schema.dbml,docs/database/schema.md,docs/database/images/schema.pngtests/MoissonMontreal.Tests/Docs/:SchemaDiagramTests: every diagram against the migrated databaseSchemaDriftTests: 18 kinds of drift must be reported, the reader rejects DBML it cannot check, and Windows line endings give the same resultDatabaseDocsTests:schema.md;Review feedback from #14 and #16, applied to the older tables:
UtcDateTimeOffsetConverteris now registered once inMoissonDbContextfor everyDateTimeOffsetcolumn. This coversusers.created_at,users.updated_at,donors.created_atandfood_items.created_at. Before, writingDateTimeOffset.Nowtousers.updated_atthrew. The per-property conversion added toReceiptConfigurationin [Issue]: Database schema: receipts with price #16 is replaced by this convention. No migration is needed.0001_create_users_and_roles.sql, like0002and0003in [Issue]: Database schema: receipts with price #16.Review feedback addressed
schema.dbmlandschema.md. The full suite also passes on a copy of the repo where every.md,.dbml,.sqland.csfile was converted to CRLF.indpred, and usespg_get_indexdeffor every key column, so expression columns are no longer dropped. A partial or expression index that the diagram cannot show is reported as a difference. Integration tests create both kinds in a rolled-back transaction.pg_get_exprandpg_get_constraintdef. Both sides are then in PostgreSQL's own spelling and are compared exactly. A test checks that(total_amount + 1) * 2andtotal_amount + 1 * 2stay different.MigrateAsync()helper now runs the migrations, andReadDatabaseAsync()uses it.Testing
Unit and integration tests:
dotnet test(Docker must be running). All 141 tests pass.dotnet test --filter "FullyQualifiedName~MoissonMontreal.Tests.Docs|FullyQualifiedName~UtcDateTimeTests"dotnet test --filter "FullyQualifiedName~Diagram_ReportsADifference_WhenAnExpressionDiffers|FullyQualifiedName~Diagram_KeepsParenthesesThatChangeTheMeaning|FullyQualifiedName~Diagram_ReportsAPartialOrExpressionIndex|FullyQualifiedName~Read_GivesTheSameSchema_WithWindowsLineEndings|FullyQualifiedName~Read_KeepsTheDefaultAndCheckExactlyAsWritten"What the tests check:
schema.dbml,users-roles.dbmlandreceipts.dbmlall match the migrated database exactly, including every check expression and default.IN ('A', 'B'),>= 0,BETWEEN 0 AND 75), an invalid one, a changed time zone default and a changed boolean default are each reported.WHERE quantity > 0) and an expression index (lower(email)) are each reported.schema.dbmllists every table and every foreign key of the database.UtcDateTimeTests:updated_atstays empty;DateTimeOffsetcolumn misses the conversion.Screenshots / Screencasts
No frontend changes. Full schema diagram from dbdiagram.io:
Checklist
Notes
docs/.docs/database/still has no separate page for donors and food items.schema.mddescribes both tables, and the "For developers" table points there.