first commit
This commit is contained in:
		| @ -0,0 +1,34 @@ | ||||
| using System; | ||||
| using System.Threading.Tasks; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using KonSoft.Payment.Data; | ||||
| using Volo.Abp.DependencyInjection; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| public class EntityFrameworkCorePaymentDbSchemaMigrator | ||||
|     : IPaymentDbSchemaMigrator, ITransientDependency | ||||
| { | ||||
|     private readonly IServiceProvider _serviceProvider; | ||||
|  | ||||
|     public EntityFrameworkCorePaymentDbSchemaMigrator( | ||||
|         IServiceProvider serviceProvider) | ||||
|     { | ||||
|         _serviceProvider = serviceProvider; | ||||
|     } | ||||
|  | ||||
|     public async Task MigrateAsync() | ||||
|     { | ||||
|         /* We intentionally resolve the PaymentDbContext | ||||
|          * from IServiceProvider (instead of directly injecting it) | ||||
|          * to properly get the connection string of the current tenant in the | ||||
|          * current scope. | ||||
|          */ | ||||
|  | ||||
|         await _serviceProvider | ||||
|             .GetRequiredService<PaymentDbContext>() | ||||
|             .Database | ||||
|             .MigrateAsync(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,86 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Volo.Abp.AuditLogging.EntityFrameworkCore; | ||||
| using Volo.Abp.BackgroundJobs.EntityFrameworkCore; | ||||
| using Volo.Abp.Data; | ||||
| using Volo.Abp.DependencyInjection; | ||||
| using Volo.Abp.EntityFrameworkCore; | ||||
| using Volo.Abp.FeatureManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.Identity; | ||||
| using Volo.Abp.Identity.EntityFrameworkCore; | ||||
| using Volo.Abp.OpenIddict.EntityFrameworkCore; | ||||
| using Volo.Abp.PermissionManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.SettingManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.TenantManagement; | ||||
| using Volo.Abp.TenantManagement.EntityFrameworkCore; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| [ReplaceDbContext(typeof(IIdentityDbContext))] | ||||
| [ReplaceDbContext(typeof(ITenantManagementDbContext))] | ||||
| [ConnectionStringName("Default")] | ||||
| public class PaymentDbContext : | ||||
|     AbpDbContext<PaymentDbContext>, | ||||
|     IIdentityDbContext, | ||||
|     ITenantManagementDbContext | ||||
| { | ||||
|     /* Add DbSet properties for your Aggregate Roots / Entities here. */ | ||||
|  | ||||
|     #region Entities from the modules | ||||
|  | ||||
|     /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext | ||||
|      * and replaced them for this DbContext. This allows you to perform JOIN | ||||
|      * queries for the entities of these modules over the repositories easily. You | ||||
|      * typically don't need that for other modules. But, if you need, you can | ||||
|      * implement the DbContext interface of the needed module and use ReplaceDbContext | ||||
|      * attribute just like IIdentityDbContext and ITenantManagementDbContext. | ||||
|      * | ||||
|      * More info: Replacing a DbContext of a module ensures that the related module | ||||
|      * uses this DbContext on runtime. Otherwise, it will use its own DbContext class. | ||||
|      */ | ||||
|  | ||||
|     //Identity | ||||
|     public DbSet<IdentityUser> Users { get; set; } | ||||
|     public DbSet<IdentityRole> Roles { get; set; } | ||||
|     public DbSet<IdentityClaimType> ClaimTypes { get; set; } | ||||
|     public DbSet<OrganizationUnit> OrganizationUnits { get; set; } | ||||
|     public DbSet<IdentitySecurityLog> SecurityLogs { get; set; } | ||||
|     public DbSet<IdentityLinkUser> LinkUsers { get; set; } | ||||
|     public DbSet<IdentityUserDelegation> UserDelegations { get; set; } | ||||
|     public DbSet<IdentitySession> Sessions { get; set; } | ||||
|     // Tenant Management | ||||
|     public DbSet<Tenant> Tenants { get; set; } | ||||
|     public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; } | ||||
|  | ||||
|     #endregion | ||||
|  | ||||
|     public PaymentDbContext(DbContextOptions<PaymentDbContext> options) | ||||
|         : base(options) | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected override void OnModelCreating(ModelBuilder builder) | ||||
|     { | ||||
|         base.OnModelCreating(builder); | ||||
|  | ||||
|         /* Include modules to your migration db context */ | ||||
|  | ||||
|         builder.ConfigurePermissionManagement(); | ||||
|         builder.ConfigureSettingManagement(); | ||||
|         builder.ConfigureBackgroundJobs(); | ||||
|         builder.ConfigureAuditLogging(); | ||||
|         builder.ConfigureIdentity(); | ||||
|         builder.ConfigureOpenIddict(); | ||||
|         builder.ConfigureFeatureManagement(); | ||||
|         builder.ConfigureTenantManagement(); | ||||
|  | ||||
|         /* Configure your own tables/entities inside here */ | ||||
|  | ||||
|         //builder.Entity<YourEntity>(b => | ||||
|         //{ | ||||
|         //    b.ToTable(PaymentConsts.DbTablePrefix + "YourEntities", PaymentConsts.DbSchema); | ||||
|         //    b.ConfigureByConvention(); //auto configure for the base class props | ||||
|         //    //... | ||||
|         //}); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,36 @@ | ||||
| using System; | ||||
| using System.IO; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Design; | ||||
| using Microsoft.Extensions.Configuration; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| /* This class is needed for EF Core console commands | ||||
|  * (like Add-Migration and Update-Database commands) */ | ||||
| public class PaymentDbContextFactory : IDesignTimeDbContextFactory<PaymentDbContext> | ||||
| { | ||||
|     public PaymentDbContext CreateDbContext(string[] args) | ||||
|     { | ||||
|         // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic | ||||
|         AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||||
|  | ||||
|         PaymentEfCoreEntityExtensionMappings.Configure(); | ||||
|  | ||||
|         var configuration = BuildConfiguration(); | ||||
|  | ||||
|         var builder = new DbContextOptionsBuilder<PaymentDbContext>() | ||||
|             .UseNpgsql(configuration.GetConnectionString("Default")); | ||||
|  | ||||
|         return new PaymentDbContext(builder.Options); | ||||
|     } | ||||
|  | ||||
|     private static IConfigurationRoot BuildConfiguration() | ||||
|     { | ||||
|         var builder = new ConfigurationBuilder() | ||||
|             .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../KonSoft.Payment.DbMigrator/")) | ||||
|             .AddJsonFile("appsettings.json", optional: false); | ||||
|  | ||||
|         return builder.Build(); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,44 @@ | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Volo.Abp.Identity; | ||||
| using Volo.Abp.ObjectExtending; | ||||
| using Volo.Abp.Threading; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| public static class PaymentEfCoreEntityExtensionMappings | ||||
| { | ||||
|     private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); | ||||
|  | ||||
|     public static void Configure() | ||||
|     { | ||||
|         PaymentGlobalFeatureConfigurator.Configure(); | ||||
|         PaymentModuleExtensionConfigurator.Configure(); | ||||
|  | ||||
|         OneTimeRunner.Run(() => | ||||
|         { | ||||
|                 /* You can configure extra properties for the | ||||
|                  * entities defined in the modules used by your application. | ||||
|                  * | ||||
|                  * This class can be used to map these extra properties to table fields in the database. | ||||
|                  * | ||||
|                  * USE THIS CLASS ONLY TO CONFIGURE EF CORE RELATED MAPPING. | ||||
|                  * USE PaymentModuleExtensionConfigurator CLASS (in the Domain.Shared project) | ||||
|                  * FOR A HIGH LEVEL API TO DEFINE EXTRA PROPERTIES TO ENTITIES OF THE USED MODULES | ||||
|                  * | ||||
|                  * Example: Map a property to a table field: | ||||
|  | ||||
|                      ObjectExtensionManager.Instance | ||||
|                          .MapEfCoreProperty<IdentityUser, string>( | ||||
|                              "MyProperty", | ||||
|                              (entityBuilder, propertyBuilder) => | ||||
|                              { | ||||
|                                  propertyBuilder.HasMaxLength(128); | ||||
|                              } | ||||
|                          ); | ||||
|  | ||||
|                  * See the documentation for more: | ||||
|                  * https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities | ||||
|                  */ | ||||
|         }); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,57 @@ | ||||
| using System; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Volo.Abp.Uow; | ||||
| using Volo.Abp.AuditLogging.EntityFrameworkCore; | ||||
| using Volo.Abp.BackgroundJobs.EntityFrameworkCore; | ||||
| using Volo.Abp.EntityFrameworkCore; | ||||
| using Volo.Abp.EntityFrameworkCore.PostgreSql; | ||||
| using Volo.Abp.FeatureManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.Identity.EntityFrameworkCore; | ||||
| using Volo.Abp.Modularity; | ||||
| using Volo.Abp.OpenIddict.EntityFrameworkCore; | ||||
| using Volo.Abp.PermissionManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.SettingManagement.EntityFrameworkCore; | ||||
| using Volo.Abp.TenantManagement.EntityFrameworkCore; | ||||
|  | ||||
| namespace KonSoft.Payment.EntityFrameworkCore; | ||||
|  | ||||
| [DependsOn( | ||||
|     typeof(PaymentDomainModule), | ||||
|     typeof(AbpIdentityEntityFrameworkCoreModule), | ||||
|     typeof(AbpOpenIddictEntityFrameworkCoreModule), | ||||
|     typeof(AbpPermissionManagementEntityFrameworkCoreModule), | ||||
|     typeof(AbpSettingManagementEntityFrameworkCoreModule), | ||||
|     typeof(AbpEntityFrameworkCorePostgreSqlModule), | ||||
|     typeof(AbpBackgroundJobsEntityFrameworkCoreModule), | ||||
|     typeof(AbpAuditLoggingEntityFrameworkCoreModule), | ||||
|     typeof(AbpTenantManagementEntityFrameworkCoreModule), | ||||
|     typeof(AbpFeatureManagementEntityFrameworkCoreModule) | ||||
|     )] | ||||
| public class PaymentEntityFrameworkCoreModule : AbpModule | ||||
| { | ||||
|     public override void PreConfigureServices(ServiceConfigurationContext context) | ||||
|     { | ||||
|         // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic | ||||
|         AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); | ||||
|  | ||||
|         PaymentEfCoreEntityExtensionMappings.Configure(); | ||||
|     } | ||||
|  | ||||
|     public override void ConfigureServices(ServiceConfigurationContext context) | ||||
|     { | ||||
|         context.Services.AddAbpDbContext<PaymentDbContext>(options => | ||||
|         { | ||||
|                 /* Remove "includeAllEntities: true" to create | ||||
|                  * default repositories only for aggregate roots */ | ||||
|             options.AddDefaultRepositories(includeAllEntities: true); | ||||
|         }); | ||||
|  | ||||
|         Configure<AbpDbContextOptions>(options => | ||||
|         { | ||||
|                 /* The main point to change your DBMS. | ||||
|                  * See also PaymentMigrationsDbContextFactory for EF Core tooling. */ | ||||
|             options.UseNpgsql(); | ||||
|         }); | ||||
|  | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,31 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <Import Project="..\..\common.props" /> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <Nullable>enable</Nullable> | ||||
|     <RootNamespace>KonSoft.Payment</RootNamespace> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\KonSoft.Payment.Domain\KonSoft.Payment.Domain.csproj" /> | ||||
|     <PackageReference Include="Volo.Abp.EntityFrameworkCore.PostgreSql" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.SettingManagement.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.Identity.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.BackgroundJobs.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.AuditLogging.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.TenantManagement.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.FeatureManagement.EntityFrameworkCore" Version="8.3.4" /> | ||||
|     <PackageReference Include="Volo.Abp.OpenIddict.EntityFrameworkCore" Version="8.3.4" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4"> | ||||
|       <PrivateAssets>all</PrivateAssets> | ||||
|       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||||
|     </PackageReference> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
							
								
								
									
										2006
									
								
								modules/payment/src/KonSoft.Payment.EntityFrameworkCore/Migrations/20250908052440_Initial.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										2006
									
								
								modules/payment/src/KonSoft.Payment.EntityFrameworkCore/Migrations/20250908052440_Initial.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -0,0 +1,2 @@ | ||||
| using System.Runtime.CompilerServices; | ||||
| [assembly:InternalsVisibleToAttribute("KonSoft.Payment.EntityFrameworkCore.Tests")] | ||||
		Reference in New Issue
	
	Block a user