feat(database): add PostgreSQL database support #5112
Draft
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.
Summary
This PR migrates the CSET backend from SQL Server to PostgreSQL, enabling cross-platform database compatibility and improving deployment flexibility. The migration includes comprehensive updates to the data layer, business logic, and database I/O components while maintaining backward compatibility with existing functionality.
Changes Made
Backend (.NET Core API)
NuGet Package Migration:
Microsoft.Data.SqlClientand all SQL Server-specific EF Core packagesSnickler.EFCore(deprecated stored procedure library)Npgsql.EntityFrameworkCore.PostgreSQLv8.0.11 across all backend projectsData Layer (Entity Framework Core):
UseSqlServertoUseNpgsqlDatabase I/O Layer (DBIO.cs):
SqlConnection,SqlCommand,SqlDataAdapterwithNpgsqlConnection,NpgsqlCommand,NpgsqlDataAdapterCOPYcommand for bulk inserts (replacingSqlBulkCopy)SCOPE_IDENTITY()toLASTVAL()Business Layer:
Interfaces:
Task<T>async return typesControllers:
Database Migration Scripts
Configuration
Files Modified
Testing Notes
Prerequisites
DatabaseScripts/Migration/convert-mssql-bak-to-postgres.shTesting Checklist
make build-backendordotnet build)Database Connection
Default PostgreSQL connection (from appsettings.json):
Update this connection string to match your PostgreSQL instance.
Technical Notes
Async/Await Pattern
All stored procedure calls now use async/await for improved scalability:
Bulk Insert Implementation
PostgreSQL COPY command provides better performance than row-by-row inserts:
Breaking Changes
Server=...;Database=...;User Id=...;Password=...Host=...;Database=...;Username=...;Password=...;Port=5432Update your deployment configuration files accordingly.
Checklist
Next Steps
After merging this PR: