Browse Source

Separate the payment database

pull/74/head
Halil İbrahim Kalkan 5 years ago
parent
commit
c7d1357f7b
  1. 3
      src/EventHub.Admin.HttpApi.Host/appsettings.json
  2. 3
      src/EventHub.BackgroundServices/appsettings.json
  3. 3
      src/EventHub.DbMigrator/appsettings.json
  4. 2
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContext.cs
  5. 20
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubEntityFrameworkCoreModule.cs
  6. 34
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Payment/EventHubDbContextFactory.cs
  7. 27
      src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Payment/EventHubPaymentDbContext.cs
  8. 1
      src/EventHub.EntityFrameworkCore/EventHub.EntityFrameworkCore.csproj
  9. 2643
      src/EventHub.EntityFrameworkCore/Migrations/20211120104244_Remove_Payment_From_Main_Database.Designer.cs
  10. 52
      src/EventHub.EntityFrameworkCore/Migrations/20211120104244_Remove_Payment_From_Main_Database.cs
  11. 66
      src/EventHub.EntityFrameworkCore/Migrations/EventHubDbContextModelSnapshot.cs
  12. 94
      src/EventHub.EntityFrameworkCore/MigrationsPayment/20211120105746_Initial_Payment_Database.Designer.cs
  13. 52
      src/EventHub.EntityFrameworkCore/MigrationsPayment/20211120105746_Initial_Payment_Database.cs
  14. 92
      src/EventHub.EntityFrameworkCore/MigrationsPayment/EventHubPaymentDbContextModelSnapshot.cs
  15. 3
      src/EventHub.HttpApi.Host/appsettings.json

3
src/EventHub.Admin.HttpApi.Host/appsettings.json

@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432"
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432",
"Payment": "Server=(LocalDb)\\MSSQLLocalDB;Database=EventHubPayment;Trusted_Connection=True"
},
"Redis": {
"Configuration": "localhost"

3
src/EventHub.BackgroundServices/appsettings.json

@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432"
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432",
"Payment": "Server=(LocalDb)\\MSSQLLocalDB;Database=EventHubPayment;Trusted_Connection=True"
},
"Redis": {
"Configuration": "127.0.0.1"

3
src/EventHub.DbMigrator/appsettings.json

@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432"
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432",
"Payment": "Server=(LocalDb)\\MSSQLLocalDB;Database=EventHubPayment;Trusted_Connection=True"
},
"IdentityServer": {
"Clients": {

2
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubDbContext.cs

@ -4,7 +4,6 @@ using EventHub.Events.Registrations;
using EventHub.Organizations;
using EventHub.Organizations.Memberships;
using Microsoft.EntityFrameworkCore;
using Payment.EntityFrameworkCore;
using System;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
@ -69,7 +68,6 @@ namespace EventHub.EntityFrameworkCore
builder.ConfigureIdentity();
builder.ConfigureIdentityServer();
builder.ConfigureBlobStoring();
builder.ConfigurePayment();
builder.ConfigureEventHub();
}
}

20
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/EventHubEntityFrameworkCoreModule.cs

@ -10,7 +10,9 @@ using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.BlobStoring.Database.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.PostgreSql;
using System;
using EventHub.EntityFrameworkCore.Payment;
using Payment.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
namespace EventHub.EntityFrameworkCore
{
@ -24,7 +26,8 @@ namespace EventHub.EntityFrameworkCore
typeof(AbpBackgroundJobsEntityFrameworkCoreModule),
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
typeof(BlobStoringDatabaseEntityFrameworkCoreModule),
typeof(PaymentEntityFrameworkCoreModule)
typeof(PaymentEntityFrameworkCoreModule),
typeof(AbpEntityFrameworkCoreSqlServerModule)
)]
public class EventHubEntityFrameworkCoreModule : AbpModule
{
@ -43,10 +46,25 @@ namespace EventHub.EntityFrameworkCore
{
options.AddDefaultRepositories();
});
/* Registering the payment dbcontext and replacing the module's dbcontext */
context.Services.AddAbpDbContext<EventHubPaymentDbContext>(options =>
{
options.ReplaceDbContext<IPaymentDbContext>();
options.AddDefaultRepositories();
});
Configure<AbpDbContextOptions>(options =>
{
options.UseNpgsql();
/* While the default db provider is PostgreSQl (because of `options.UseNpgsql()` above),
* We are configuring to use SQL Server for the payment database
*/
options.Configure<EventHubPaymentDbContext>(opts =>
{
opts.UseSqlServer();
});
});
}
}

34
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Payment/EventHubDbContextFactory.cs

@ -0,0 +1,34 @@
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Payment;
namespace EventHub.EntityFrameworkCore.Payment
{
/* This class is needed for EF Core console commands
* (like Add-Migration and Update-Database commands) */
public class EventHubPaymentDbContextFactory : IDesignTimeDbContextFactory<EventHubPaymentDbContext>
{
public EventHubPaymentDbContext CreateDbContext(string[] args)
{
EventHubEfCoreEntityExtensionMappings.Configure();
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<EventHubPaymentDbContext>()
.UseSqlServer(configuration.GetConnectionString(PaymentDbProperties.ConnectionStringName));
return new EventHubPaymentDbContext(builder.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../EventHub.DbMigrator/"))
.AddJsonFile("appsettings.json", optional: false);
return builder.Build();
}
}
}

27
src/EventHub.EntityFrameworkCore/EntityFrameworkCore/Payment/EventHubPaymentDbContext.cs

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using Payment;
using Payment.EntityFrameworkCore;
using Payment.PaymentRequests;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace EventHub.EntityFrameworkCore.Payment
{
[ConnectionStringName(PaymentDbProperties.ConnectionStringName)]
public class EventHubPaymentDbContext : AbpDbContext<EventHubPaymentDbContext>, IPaymentDbContext
{
public DbSet<PaymentRequest> PaymentRequests { get; set; }
public EventHubPaymentDbContext(
DbContextOptions<EventHubPaymentDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigurePayment();
}
}
}

1
src/EventHub.EntityFrameworkCore/EventHub.EntityFrameworkCore.csproj

@ -20,6 +20,7 @@
<PackageReference Include="Volo.Abp.BlobStoring.Database.EntityFrameworkCore" Version="5.0.0-rc.1" />
<ProjectReference Include="..\EventHub.Domain\EventHub.Domain.csproj" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="5.0.0-rc.1" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="5.0.0-rc.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.*" />
<PackageReference Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" Version="5.0.0-rc.1" />
<PackageReference Include="Volo.Abp.SettingManagement.EntityFrameworkCore" Version="5.0.0-rc.1" />

2643
src/EventHub.EntityFrameworkCore/Migrations/20211120104244_Remove_Payment_From_Main_Database.Designer.cs

File diff suppressed because it is too large

52
src/EventHub.EntityFrameworkCore/Migrations/20211120104244_Remove_Payment_From_Main_Database.cs

@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EventHub.Migrations
{
public partial class Remove_Payment_From_Main_Database : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PayPaymentRequests");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PayPaymentRequests",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
Currency = table.Column<string>(type: "text", nullable: true),
CustomerId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
ExtraProperties = table.Column<string>(type: "text", nullable: true),
FailReason = table.Column<string>(type: "text", nullable: true),
IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
Price = table.Column<decimal>(type: "numeric", nullable: false),
ProductId = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
ProductName = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
State = table.Column<byte>(type: "smallint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PayPaymentRequests", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_PayPaymentRequests_CustomerId",
table: "PayPaymentRequests",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_PayPaymentRequests_State",
table: "PayPaymentRequests",
column: "State");
}
}
}

66
src/EventHub.EntityFrameworkCore/Migrations/EventHubDbContextModelSnapshot.cs

@ -19,7 +19,7 @@ namespace EventHub.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql)
.HasAnnotation("ProductVersion", "6.0.0-rc.2.21480.5")
.HasAnnotation("ProductVersion", "6.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -350,70 +350,6 @@ namespace EventHub.Migrations
b.ToTable("EhOrganizations", (string)null);
});
modelBuilder.Entity("Payment.PaymentRequests.PaymentRequest", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("character varying(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("uuid")
.HasColumnName("CreatorId");
b.Property<string>("Currency")
.HasColumnType("text");
b.Property<string>("CustomerId")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ExtraProperties")
.HasColumnType("text")
.HasColumnName("ExtraProperties");
b.Property<string>("FailReason")
.HasColumnType("text");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<decimal>("Price")
.HasColumnType("numeric");
b.Property<string>("ProductId")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("ProductName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<byte>("State")
.HasColumnType("smallint");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("State");
b.ToTable("PayPaymentRequests", (string)null);
});
modelBuilder.Entity("Volo.Abp.AuditLogging.AuditLog", b =>
{
b.Property<Guid>("Id")

94
src/EventHub.EntityFrameworkCore/MigrationsPayment/20211120105746_Initial_Payment_Database.Designer.cs

@ -0,0 +1,94 @@
// <auto-generated />
using System;
using EventHub.EntityFrameworkCore.Payment;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace EventHub.MigrationsPayment
{
[DbContext(typeof(EventHubPaymentDbContext))]
[Migration("20211120105746_Initial_Payment_Database")]
partial class Initial_Payment_Database
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "6.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("Payment.PaymentRequests.PaymentRequest", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("uniqueidentifier")
.HasColumnName("CreatorId");
b.Property<string>("Currency")
.HasColumnType("nvarchar(max)");
b.Property<string>("CustomerId")
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<string>("FailReason")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<string>("ProductId")
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("ProductName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<byte>("State")
.HasColumnType("tinyint");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("State");
b.ToTable("PayPaymentRequests", (string)null);
});
#pragma warning restore 612, 618
}
}
}

52
src/EventHub.EntityFrameworkCore/MigrationsPayment/20211120105746_Initial_Payment_Database.cs

@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EventHub.MigrationsPayment
{
public partial class Initial_Payment_Database : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PayPaymentRequests",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CustomerId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
ProductId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
ProductName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Currency = table.Column<string>(type: "nvarchar(max)", nullable: true),
State = table.Column<byte>(type: "tinyint", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
FailReason = table.Column<string>(type: "nvarchar(max)", nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PayPaymentRequests", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_PayPaymentRequests_CustomerId",
table: "PayPaymentRequests",
column: "CustomerId");
migrationBuilder.CreateIndex(
name: "IX_PayPaymentRequests_State",
table: "PayPaymentRequests",
column: "State");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PayPaymentRequests");
}
}
}

92
src/EventHub.EntityFrameworkCore/MigrationsPayment/EventHubPaymentDbContextModelSnapshot.cs

@ -0,0 +1,92 @@
// <auto-generated />
using System;
using EventHub.EntityFrameworkCore.Payment;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace EventHub.MigrationsPayment
{
[DbContext(typeof(EventHubPaymentDbContext))]
partial class EventHubPaymentDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.SqlServer)
.HasAnnotation("ProductVersion", "6.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("Payment.PaymentRequests.PaymentRequest", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime2")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("uniqueidentifier")
.HasColumnName("CreatorId");
b.Property<string>("Currency")
.HasColumnType("nvarchar(max)");
b.Property<string>("CustomerId")
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<string>("FailReason")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<string>("ProductId")
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<string>("ProductName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("nvarchar(200)");
b.Property<byte>("State")
.HasColumnType("tinyint");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.HasIndex("State");
b.ToTable("PayPaymentRequests", (string)null);
});
#pragma warning restore 612, 618
}
}
}

3
src/EventHub.HttpApi.Host/appsettings.json

@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432"
"Default": "Host=localhost;Database=EventHub;Username=root;Password=root;Port=5432",
"Payment": "Server=(LocalDb)\\MSSQLLocalDB;Database=EventHubPayment;Trusted_Connection=True"
},
"Redis": {
"Configuration": "localhost"

Loading…
Cancel
Save