-
-
Notifications
You must be signed in to change notification settings - Fork 95
feat: SQL Server database project, with tsqlt tests #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
- new database projects
- src/SqlServer/src/Eventuous.SqlServer.Database/Eventuous.SqlServer.Database.csproj
- store database definition
- static code analysis
- no relevance to how the database is deployed, other than for tSQLt testing purposes
- Dockerfile.db-from-dacpac deploys the database to a containerized database with sqlpackage. This is used for tSQLt testing.
- src/SqlServer/test/Eventuous.Tests.SqlServer.Database/Eventuous.Tests.SqlServer.Database.csproj
- store database tSQLt tests
- Dockerfile.eventuous-db-tsqlt-runner deploys and runs the database tests
- minor SQL Server procedure formatting
- check_stream add semicolon
- read_stream_sub remove indenty
|
How would it interact with the primary project? Those script are included in the database project but remained in the main project? |
There was a problem hiding this 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 introduces SQL Server database projects to enable static code analysis and automated testing using the tSQLt framework. The implementation includes database schema definitions via DACPAC deployment and a Docker-based testing infrastructure for running unit tests against SQL Server stored procedures and database objects.
- Creates database project structure with schema definitions matching existing migration scripts
- Implements tSQLt-based unit tests for database procedures and constraints
- Establishes Docker infrastructure for ephemeral database testing environments
Reviewed Changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/SqlServer/src/Eventuous.SqlServer.Database/* | Database schema definitions (tables, procedures, types) mirroring existing migration scripts |
| src/SqlServer/src/Eventuous.SqlServer.Database/docker/* | Docker configuration for deploying database from DACPAC |
| src/SqlServer/test/Eventuous.Tests.SqlServer.Database/* | tSQLt test suite covering database procedures and constraints |
| src/SqlServer/test/Eventuous.Tests.SqlServer.Database/docker/* | Docker test runner infrastructure for automated tSQLt execution |
| Directory.Packages.props | Package references for database project tooling |
| nuget.config | NuGet configuration for package restoration |
| .gitattributes | Ensures shell scripts use LF line endings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SQL="EXEC tSQLt.Run '$1'" | ||
| ;; | ||
| *) | ||
|
|
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extra blank line 43 between the case pattern and the heredoc statement should be removed to improve code readability.
|
|
||
| USER root | ||
|
|
||
| ADD https://aka.ms/sqlpackage-linux /tmp/sqlpackage.zip |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sqlpackage zip is downloaded twice (lines 30 and 43). The first ADD instruction appears to be unused and should be removed to avoid unnecessary downloads and confusion.
| ADD https://aka.ms/sqlpackage-linux /tmp/sqlpackage.zip |
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Messages.[Test StreamPosition is invalid json ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Messages.[Test CK_eventuous_Messages_JsonData violation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Messages.[Test CK_eventuous_Messages_JsonMetadata violation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Messages.[Test UQ_eventuous_Messages_StreamId_StreamPosition violoation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'violoation' to 'violation' and 'ExpectExcepton' to 'ExpectException'.
| CREATE PROCEDURE Messages.[Test UQ_eventuous_Messages_StreamId_StreamPosition violoation ExpectExcepton] | |
| CREATE PROCEDURE Messages.[Test UQ_eventuous_Messages_StreamId_StreamPosition violation ExpectException] |
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Messages.[Test UQ_eventuous_Messages_StreamId_MessageId violation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Checkpoints.[Test UQ_eventuous_Checkpoints_Id violation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| CREATE PROCEDURE Checkpoints.[Test UQ_eventuous_Checkpoints_Id violation ExpectExcepton] | |
| CREATE PROCEDURE Checkpoints.[Test UQ_eventuous_Checkpoints_Id violation ExpectException] |
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE Streams.[Test CK_eventuous_Streams_Version violation ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| CREATE PROCEDURE Streams.[Test CK_eventuous_Streams_Version violation ExpectExcepton] | |
| CREATE PROCEDURE Streams.[Test CK_eventuous_Streams_Version violation ExpectException] |
| END; | ||
| GO | ||
|
|
||
| CREATE PROCEDURE check_stream.[Test stream exists wrong version ExpectExcepton] |
Copilot
AI
Oct 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'ExpectExcepton' to 'ExpectException'.
| CREATE PROCEDURE check_stream.[Test stream exists wrong version ExpectExcepton] | |
| CREATE PROCEDURE check_stream.[Test stream exists wrong version ExpectException] |
There is no formal interaction between the main project and this new database project. If scripts are changed, we'd need to change them in both places for accuracy. The main project holds the scripts needed for migrating the database. |
|
Maybe use project file links to share the scripts between those two projects? |
Purpose
The purpose of this PR is to enrich the SQL Server support.
Here is a video that walks through the changes and does a demo: https://youtu.be/PJV-JueZUmk
Overview
Each of these database projects have 0 impact on code that Eventuous deploys.
Eventuous.SqlServer.Database.csproj
full path:
src/SqlServer/src/Eventuous.SqlServer.Database/Eventuous.SqlServer.Database.csprojDockerfile.db-from-dacpacdeploys the database to a containerized database with the DACPAC using sqlpackage. This allows to initialize a ephemeral SQL Server database for automated testingStatic code analysis
This is a mechanism that allows us to identify code smells and other possible issues with the SQL definitions. Some of those are too opinionated for Eventuous, such as the need for a transaction. Those false positive things can be suppressed in the
StaticCodeAnalysis.SuppressMessages.xmlfile. Right now there are 4 things being suppressed. As a follow-up PR to this one, I'll create Issues to address those.DACPAC
If you are not familiar, a
.dacpacfile is a build artifact as a result of building a database project. That.dacpacfile can then be used to "Publish" to a database. Pairing this with docker allows to create temporary containerized databases for various purposes, but what I'm adding here is focused on tSQLt testing.Eventuous.Tests.SqlServer.Database.csproj
full path:
src/SqlServer/test/Eventuous.Tests.SqlServer.Database/Eventuous.Tests.SqlServer.Database.csprojDockerfile.eventuous-db-tsqlt-runnercreates and runs the database tests on the ephemeral SQL Server database I mentioned above.