Skip to content

Commit

Permalink
feat: DB Agnostic architecture with SqlServer, MySql and PostgreSQL (#…
Browse files Browse the repository at this point in the history
…120)

feat: DB Agnostic architecture with SqlServer, MySql and PostgreSQL
  • Loading branch information
OlegoO committed Jan 9, 2023
1 parent 74b8d25 commit b2f50fe
Show file tree
Hide file tree
Showing 39 changed files with 1,418 additions and 59 deletions.
21 changes: 21 additions & 0 deletions VirtoCommerce.InventoryModule.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{BD6EF1DA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtoCommerce.InventoryModule.Tests", "tests\VirtoCommerce.InventoryModule.Tests\VirtoCommerce.InventoryModule.Tests.csproj", "{CE6513A9-CA03-494E-8998-EADCC27408FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtoCommerce.InventoryModule.Data.SqlServer", "src\VirtoCommerce.InventoryModule.Data.SqlServer\VirtoCommerce.InventoryModule.Data.SqlServer.csproj", "{92DF0B1C-4432-4EDA-8957-AAE118FB95DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtoCommerce.InventoryModule.Data.PostgreSql", "src\VirtoCommerce.InventoryModule.Data.PostgreSql\VirtoCommerce.InventoryModule.Data.PostgreSql.csproj", "{776ACABF-B9BA-4CB9-8E03-32AF7EC33064}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtoCommerce.InventoryModule.Data.MySql", "src\VirtoCommerce.InventoryModule.Data.MySql\VirtoCommerce.InventoryModule.Data.MySql.csproj", "{091E2801-D524-4D87-9E8F-D4F4FA57A86F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -37,6 +43,18 @@ Global
{CE6513A9-CA03-494E-8998-EADCC27408FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE6513A9-CA03-494E-8998-EADCC27408FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE6513A9-CA03-494E-8998-EADCC27408FB}.Release|Any CPU.Build.0 = Release|Any CPU
{92DF0B1C-4432-4EDA-8957-AAE118FB95DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92DF0B1C-4432-4EDA-8957-AAE118FB95DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92DF0B1C-4432-4EDA-8957-AAE118FB95DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92DF0B1C-4432-4EDA-8957-AAE118FB95DB}.Release|Any CPU.Build.0 = Release|Any CPU
{776ACABF-B9BA-4CB9-8E03-32AF7EC33064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{776ACABF-B9BA-4CB9-8E03-32AF7EC33064}.Debug|Any CPU.Build.0 = Debug|Any CPU
{776ACABF-B9BA-4CB9-8E03-32AF7EC33064}.Release|Any CPU.ActiveCfg = Release|Any CPU
{776ACABF-B9BA-4CB9-8E03-32AF7EC33064}.Release|Any CPU.Build.0 = Release|Any CPU
{091E2801-D524-4D87-9E8F-D4F4FA57A86F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{091E2801-D524-4D87-9E8F-D4F4FA57A86F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{091E2801-D524-4D87-9E8F-D4F4FA57A86F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{091E2801-D524-4D87-9E8F-D4F4FA57A86F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -46,6 +64,9 @@ Global
{9C6ED9D2-7B68-45BE-8F2D-B24335F31A52} = {21D7AD7F-5786-46A4-AF0F-BF7C17AC7CCD}
{9F1C3399-B061-4A86-AA21-7B468298193B} = {21D7AD7F-5786-46A4-AF0F-BF7C17AC7CCD}
{CE6513A9-CA03-494E-8998-EADCC27408FB} = {BD6EF1DA-D884-4258-8EFF-1FB8770D908B}
{92DF0B1C-4432-4EDA-8957-AAE118FB95DB} = {21D7AD7F-5786-46A4-AF0F-BF7C17AC7CCD}
{776ACABF-B9BA-4CB9-8E03-32AF7EC33064} = {21D7AD7F-5786-46A4-AF0F-BF7C17AC7CCD}
{091E2801-D524-4D87-9E8F-D4F4FA57A86F} = {21D7AD7F-5786-46A4-AF0F-BF7C17AC7CCD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {039A0599-1FC7-44B8-A9C3-54535F8B9659}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.EntityFrameworkCore;

namespace VirtoCommerce.InventoryModule.Data.MySql
{
public static class DbContextOptionsBuilderExtensions
{
/// <summary>
/// Configures the context to use PostgreSql.
/// </summary>
public static DbContextOptionsBuilder UseMySqlDatabase(this DbContextOptionsBuilder builder, string connectionString) =>
builder.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), db => db
.MigrationsAssembly(typeof(MySqlDbContextFactory).Assembly.GetName().Name));
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VirtoCommerce.InventoryModule.Data.MySql.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "FulfillmentCenter",
columns: table => new
{
Id = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Name = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Description = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ShortDescription = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Line1 = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Line2 = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
City = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CountryCode = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
StateProvince = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CountryName = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
PostalCode = table.Column<string>(type: "varchar(32)", maxLength: 32, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
RegionId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
RegionName = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
DaytimePhoneNumber = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Email = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
OrganizationId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
GeoLocation = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
OuterId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
ModifiedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedBy = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ModifiedBy = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_FulfillmentCenter", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "Inventory",
columns: table => new
{
Id = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
InStockQuantity = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
ReservedQuantity = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
ReorderMinQuantity = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
PreorderQuantity = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
BackorderQuantity = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
AllowBackorder = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowPreorder = table.Column<bool>(type: "tinyint(1)", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
PreorderAvailabilityDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
BackorderAvailabilityDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
Sku = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
OuterId = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
FulfillmentCenterId = table.Column<string>(type: "varchar(128)", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
ModifiedDate = table.Column<DateTime>(type: "datetime(6)", nullable: true),
CreatedBy = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ModifiedBy = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_Inventory", x => x.Id);
table.ForeignKey(
name: "FK_Inventory_FulfillmentCenter_FulfillmentCenterId",
column: x => x.FulfillmentCenterId,
principalTable: "FulfillmentCenter",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateIndex(
name: "IX_Inventory_FulfillmentCenterId",
table: "Inventory",
column: "FulfillmentCenterId");

migrationBuilder.CreateIndex(
name: "IX_Inventory_Sku_ModifiedDate",
table: "Inventory",
columns: new[] { "Sku", "ModifiedDate" });
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Inventory");

migrationBuilder.DropTable(
name: "FulfillmentCenter");
}
}
}

0 comments on commit b2f50fe

Please sign in to comment.