Skip to content

Commit

Permalink
added MSSQL Provider (#939)
Browse files Browse the repository at this point in the history
* add sql server

* add migrations for MSSQL Provider

---------

Co-authored-by: Mukesh Murugan <31455818+iammukeshm@users.noreply.github.com>
  • Loading branch information
wtmaxim and iammukeshm committed Jun 6, 2024
1 parent 7f35d36 commit 6fa4abd
Show file tree
Hide file tree
Showing 21 changed files with 1,581 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.6" />
<PackageVersion Include="Microsoft.NET.Build.Containers" Version="8.0.100" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
Expand Down
15 changes: 15 additions & 0 deletions api/FSH.WebApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostgreSQL", "migrations\Po
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "modules\Shared\Shared.csproj", "{87D0AB12-A19D-42B3-928C-C60AFA698952}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSSQL", "migrations\MSSQL\MSSQL.csproj", "{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -159,6 +161,18 @@ Global
{87D0AB12-A19D-42B3-928C-C60AFA698952}.Release|x64.Build.0 = Release|Any CPU
{87D0AB12-A19D-42B3-928C-C60AFA698952}.Release|x86.ActiveCfg = Release|Any CPU
{87D0AB12-A19D-42B3-928C-C60AFA698952}.Release|x86.Build.0 = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|x64.ActiveCfg = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|x64.Build.0 = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|x86.ActiveCfg = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Debug|x86.Build.0 = Debug|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|Any CPU.Build.0 = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|x64.ActiveCfg = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|x64.Build.0 = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|x86.ActiveCfg = Release|Any CPU
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -175,6 +189,7 @@ Global
{32F5383E-4201-4527-98DB-40715BB9F574} = {F3DF5AC5-8CDC-46D4-969D-1245A6880215}
{6EB9D713-B3F6-495A-AF78-8DF2234B758C} = {12F8343D-20A6-4E24-B0F5-3A66F2228CF6}
{87D0AB12-A19D-42B3-928C-C60AFA698952} = {32F5383E-4201-4527-98DB-40715BB9F574}
{F99FF9C4-C19D-47A7-BF07-687EB39B2EBC} = {12F8343D-20A6-4E24-B0F5-3A66F2228CF6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EA8248C2-3877-4AF7-8777-A17E7881E030}
Expand Down
1 change: 1 addition & 0 deletions api/framework/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageReference Include="Hangfire.PostgreSql" />
<PackageReference Include="MailKit" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" />
<PackageReference Include="MimeKit" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
Expand Down
3 changes: 3 additions & 0 deletions api/framework/Infrastructure/Jobs/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ internal static IServiceCollection ConfigureJobs(this IServiceCollection service
o.UseNpgsqlConnection(dbOptions.ConnectionString);
});
break;
case DbProviders.MSSQL:
config.UseSqlServerStorage(dbOptions.ConnectionString);
break;
default:
throw new FshException($"hangfire storage provider {dbOptions.Provider} is not supported");
}
Expand Down
1 change: 1 addition & 0 deletions api/framework/Infrastructure/Persistence/DbProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
internal static class DbProviders
{
public const string PostgreSQL = "POSTGRESQL";
public const string MSSQL = "MSSQL";
}
2 changes: 2 additions & 0 deletions api/framework/Infrastructure/Persistence/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal static DbContextOptionsBuilder ConfigureDatabase(this DbContextOptionsB
{
DbProviders.PostgreSQL => builder.UseNpgsql(connectionString, e =>
e.MigrationsAssembly("FSH.WebApi.Migrations.PostgreSQL")),
DbProviders.MSSQL => builder.UseSqlServer(connectionString, e =>
e.MigrationsAssembly("FSH.WebApi.Migrations.MSSQL")),
_ => throw new InvalidOperationException($"DB Provider {dbProvider} is not supported."),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FSH.Framework.Core.Persistence;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Npgsql;
Expand All @@ -23,6 +24,9 @@ public bool TryValidate(string connectionString, string? dbProvider = null)
case DbProviders.PostgreSQL:
_ = new NpgsqlConnectionStringBuilder(connectionString);
break;
case DbProviders.MSSQL:
_ = new SqlConnectionStringBuilder(connectionString);
break;
default:
break;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions api/migrations/MSSQL/Catalog/20240605195930_Add Catalog Schema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace FSH.WebApi.Migrations.MSSQL.Catalog
{
/// <inheritdoc />
public partial class AddCatalogSchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "catalog");

migrationBuilder.CreateTable(
name: "Products",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
TenantId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
LastModified = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
LastModifiedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Products",
schema: "catalog");
}
}
}
70 changes: 70 additions & 0 deletions api/migrations/MSSQL/Catalog/CatalogDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// <auto-generated />
using System;
using FSH.WebApi.Catalog.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace FSH.WebApi.Migrations.MSSQL.Catalog
{
[DbContext(typeof(CatalogDbContext))]
partial class CatalogDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("catalog")
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

modelBuilder.Entity("FSH.WebApi.Catalog.Domain.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTimeOffset>("Created")
.HasColumnType("datetimeoffset");
b.Property<Guid>("CreatedBy")
.HasColumnType("uniqueidentifier");
b.Property<string>("Description")
.HasMaxLength(1000)
.HasColumnType("nvarchar(1000)");
b.Property<DateTimeOffset>("LastModified")
.HasColumnType("datetimeoffset");
b.Property<Guid?>("LastModifiedBy")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<string>("TenantId")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("nvarchar(64)");
b.HasKey("Id");
b.ToTable("Products", "catalog");
b.HasAnnotation("Finbuckle:MultiTenant", true);
});
#pragma warning restore 612, 618
}
}
}
Loading

0 comments on commit 6fa4abd

Please sign in to comment.