feat(database): add PostgreSQL database support#5112
Draft
itsmostafa wants to merge 1 commit intodevelopfrom
Draft
feat(database): add PostgreSQL database support#5112itsmostafa wants to merge 1 commit intodevelopfrom
itsmostafa wants to merge 1 commit intodevelopfrom
Conversation
Migrate the CSET backend from SQL Server to PostgreSQL to enable cross-platform database compatibility and improve deployment flexibility. Changes include: **NuGet Packages:** - Remove Microsoft.Data.SqlClient and SQL Server EF Core packages - Remove Snickler.EFCore (deprecated stored procedure library) - Add Npgsql.EntityFrameworkCore.PostgreSQL v8.0.11 **Data Layer (CSETContext.cs):** - Switch EF Core provider from UseSqlServer to UseNpgsql - Convert computed column syntax for SHA1 hashing to PostgreSQL format - Migrate stored procedure calls to async using EF Core scaffolded procedures **Database I/O (DBIO.cs):** - Replace SqlConnection/SqlCommand with NpgsqlConnection/NpgsqlCommand - Implement PostgreSQL COPY command for bulk inserts (replacing SqlBulkCopy) - Update identity retrieval from SCOPE_IDENTITY() to LASTVAL() **Business Layer:** - Convert stored procedure calls to async/await pattern across all business classes - Update interfaces to support Task-based async operations **Configuration:** - Update default connection string to PostgreSQL format - Fix PostgreSQL port configuration in migration scripts (5432) This migration maintains backward compatibility with existing functionality while enabling PostgreSQL as the primary database platform.
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.
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: