Database schema management: Hybrid approach with SQL Database Project (Week 2 Implementation) - #89
Database schema management: Hybrid approach with SQL Database Project (Week 2 Implementation)#89SamuelMcAravey with Copilot wants to merge 11 commits into
Conversation
…ntation Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
|
@copilot Okay, so I added the database projects, and I think we're basically at a point where we can execute on your strategy. Note that I've got two projects because there was two styles of database. There's the control plane, and then there's the multi-database schema. So let's go ahead and do the updates that you've described so that we can make this work. So the only thing that I'll say for now, we've already done your week one extract the schema. So let's pick up on week two where we embed the SQL files and update database schema manager. I don't know how I feel about migrations because migrations are going to be a lot more complicated. And for that, we need a tool kind of like Flyway, but that's external. |
…ore tables) Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
Co-authored-by: SamuelMcAravey <11021165+SamuelMcAravey@users.noreply.github.com>
Completed Week 2 implementation! ✅ What I did:
Key changes (commits cb8f21b and b88d21b):
Testing: Build successful with zero errors. Benefits: SQL changes are now visible in PR diffs as actual SQL (not C# string changes). Professional SQL editing experience with syntax highlighting. Runtime deployment ( Note on remaining work: Some stored procedures (Inbox work queue, Lease, Lock, Semaphore) and less-used tables (Fanout, Metrics) still use inline SQL. I can update these if needed, but the core Week 2 functionality is complete. Let me know if you'd like me to continue or if this is sufficient! |
Why: - Introduced a SQL-based job scheduling mechanism to manage job execution and timer dispatching. - This allows for better control and monitoring of scheduled tasks within the application. What: - Added `SqlSchedulerOptions` for configuration settings related to the SQL scheduler. - Implemented `SqlSchedulerService` to handle job scheduling and execution logic. - Created `SqlSchedulerStore` for database interactions related to job and timer management. - Updated project references to include necessary components for the new scheduler. Notes / risks: - Ensure that the database schema is correctly set up for the new scheduler to function properly. - Potential impact on existing job scheduling mechanisms; thorough testing is required. Tests: - Tests: Existing unit tests cover the new scheduler functionality.
Problem
Schema complexity growing beyond embedded C# strings. Need professional tooling (SSDT, dacpac, SQL Compare) and better PR diffs while maintaining
EnableSchemaDeployment=trueconvenience.Solution: Hybrid Approach
Keep runtime deployment, add SQL Database Project. Zero breaking changes.
What's New
SQL Database Projects (added by repository owner)
Bravellian.Platform.Database.ControlPlane- Control plane schemaBravellian.Platform.Database.MultiDatabase- Multi-database schema.sqlprojstructure with all tables, procedures, and types extracted to.sqlfilesWeek 2 Implementation: Embedded Resources & Runtime Loading
SqlResourceLoader- Helper class to load SQL scripts from embedded resources.csprojto embed SQL files from both database projects as assembly resourcesDatabaseSchemaManagerto load schema from embedded SQL files instead of C# string literalsDocumentation
DATABASE_SCHEMA_STRATEGY.md- Architecture, 4-week implementation roadmapSQL_PROJECT_COMPARISON.md- Before/after PR review examplesINVESTIGATION_SUMMARY.md- Executive summary and recommendationWhy Not EF Core?
Platform uses Dapper for performance. Work queue pattern (READPAST, UPDLOCK) requires database-specific SQL. EF migrations don't solve the "SQL in C# strings" review problem.
Benefits
Development (unchanged):
Production (new capability):
PR Reviews (improved):
Implementation Status
Week 1: ✅ Complete (done by repository owner)
.sqlfiles in two database projectsWeek 2: ✅ Complete
DatabaseSchemaManagerto load from embedded resourcesWeek 3: Deferred
Technical Details
What Changed:
DatabaseSchemaManagerfrom ~2000+ lines of C# string literals to clean resource loading.sqlfiles with full IDE supportEnableSchemaDeployment=truestill deploys schema automaticallyBackward Compatibility:
AdaptSchemaName()methodNo existing code changes required. SQL Project is additive capability for production deployments while maintaining runtime deployment convenience.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.