Skip to content

Add MSSQL (SQL Server) provider support #4

@dimminbox

Description

@dimminbox

Description

The application currently supports MySQL and PostgreSQL as sync source and target providers. This issue tracks the work needed to add Microsoft SQL Server (MSSQL) support.

The architecture already follows a clean provider pattern — each new database requires implementing a set of standard interfaces and wiring them into the existing factories and DI container, exactly as done for MySQL and PostgreSQL.


Tasks

  1. Add constant to DbProviders

Add public const string MsSql = "MSSQL"; to align with the existing naming convention used as keys in config and factories.


  1. Add NuGet package Microsoft.Data.SqlClient

Add the official Microsoft SQL Server client library to DbSyncEngine.Infrastructure.csproj.


  1. Extend DbConnectionFactory

Add a branch for DbProviders.MsSql that returns a SqlConnection.


  1. Implement MsSqlTableDataRepository

Implement ITableDataRepository with ReadChunkAsync and WriteChunkAsync using SqlConnection. Identifiers should be quoted with [square brackets] per T-SQL convention.

Register in TableDataRepositoryFactory and DependencyInjection.AddTableData().


  1. Implement MsSqlValueNormalizer

Implement IValueNormalizer to normalize raw values returned by the SQL Server ADO.NET driver to the application's internal format (e.g. proper bool, int, DateTime handling).

Register in ValueNormalizerFactory._map and DependencyInjection.AddNormalization().


  1. Implement MsSqlSchemaReader

Implement ISchemaReader.ReadAsync(SyncContext ctx) to read table metadata (column names, types, nullability, primary key) from information_schema.columns or sys.columns / sys.types and return a TableDefinition.

Register in SchemaReaderFactory._map and DependencyInjection.AddSchema().


  1. Implement MsSqlSchemaNormalizer

Implement ISchemaNormalizer.Normalize(TableDefinition, NormalizerContext) to map source column types to their SQL Server equivalents (e.g. text → nvarchar(MAX), tinyint(1) → bit).

Register in SchemaNormalizerFactory._map and DependencyInjection.AddNormalization().


  1. Implement MsSqlDdlGenerator

Implement ITargetDdlGenerator to produce T-SQL DDL statements for schema management: CREATE TABLE, DROP TABLE, table existence check, temp table naming, data copy, atomic table swap via sp_rename, post-swap cleanup, and identity
sequence sync.

Register in TargetDdlGeneratorFactory._map.


  1. Register all new types in DI

Add MsSqlSchemaReader, MsSqlSchemaNormalizer, MsSqlValueNormalizer, and MsSqlTableDataRepository to the appropriate extension methods in DependencyInjection.cs.


Acceptance Criteria

  • "Provider": "MSSQL" is accepted in config.json for both Source and Target
  • Full sync MySQL → MSSQL completes without errors
  • Schema is correctly created on the SQL Server side with proper column type mapping
  • Atomic table swap works correctly on SQL Server
  • All existing tests continue to pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions