2020-02-17 08:58:14 +00:00
|
|
|
|
using ASC.Common;
|
|
|
|
|
using ASC.Core.Common.EF.Model;
|
2019-12-10 14:47:48 +00:00
|
|
|
|
|
2019-12-03 15:20:21 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Core.Common.EF.Context
|
|
|
|
|
{
|
2020-08-21 02:34:37 +00:00
|
|
|
|
public partial class TenantDbContext : BaseDbContext
|
2019-12-03 15:20:21 +00:00
|
|
|
|
{
|
|
|
|
|
public DbSet<DbTenant> Tenants { get; set; }
|
|
|
|
|
public DbSet<User> Users { get; set; }
|
|
|
|
|
public DbSet<UserSecurity> UserSecurity { get; set; }
|
|
|
|
|
public DbSet<DbTenantVersion> TenantVersion { get; set; }
|
|
|
|
|
public DbSet<DbTenantPartner> TenantPartner { get; set; }
|
|
|
|
|
public DbSet<DbTenantForbiden> TenantForbiden { get; set; }
|
2019-12-10 14:47:48 +00:00
|
|
|
|
public DbSet<TenantIpRestrictions> TenantIpRestrictions { get; set; }
|
2019-12-03 15:20:21 +00:00
|
|
|
|
public DbSet<DbCoreSettings> CoreSettings { get; set; }
|
|
|
|
|
|
2019-12-17 08:27:38 +00:00
|
|
|
|
public TenantDbContext() { }
|
|
|
|
|
public TenantDbContext(DbContextOptions<TenantDbContext> options)
|
|
|
|
|
: base(options)
|
|
|
|
|
{
|
2020-08-21 02:34:37 +00:00
|
|
|
|
Database.EnsureCreated();
|
2019-12-17 08:27:38 +00:00
|
|
|
|
}
|
2019-12-03 15:20:21 +00:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2020-08-21 02:34:37 +00:00
|
|
|
|
modelBuilder.MySqlAddUser();
|
|
|
|
|
modelBuilder.MySqlAddCoreSettings();
|
|
|
|
|
modelBuilder.MySqlAddDbTenant();
|
|
|
|
|
modelBuilder.MySqlAddUserSecurity();
|
|
|
|
|
modelBuilder.MySqlAddDbTenantForbiden();
|
|
|
|
|
modelBuilder.MySqlAddTenantIpRestrictions();
|
|
|
|
|
modelBuilder.MySqlAddDbTenantPartner();
|
|
|
|
|
modelBuilder.MySqlAddDbTenantVersion();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
|
2020-08-21 02:34:37 +00:00
|
|
|
|
modelBuilder.PgSqlAddUser();
|
|
|
|
|
modelBuilder.PgSqlAddCoreSettings();
|
|
|
|
|
modelBuilder.PgSqlAddDbTenant();
|
|
|
|
|
modelBuilder.PgSqlAddUserSecurity();
|
|
|
|
|
modelBuilder.PgSqlAddDbTenantForbiden();
|
|
|
|
|
modelBuilder.PgSqlAddTenantIpRestrictions();
|
|
|
|
|
modelBuilder.PgSqlAddDbTenantPartner();
|
|
|
|
|
modelBuilder.PgSqlAddDbTenantVersion();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
|
2020-08-21 02:34:37 +00:00
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
2020-08-21 02:34:37 +00:00
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TenantDbExtension
|
|
|
|
|
{
|
2020-02-17 08:58:14 +00:00
|
|
|
|
public static DIHelper AddTenantDbContextService(this DIHelper services)
|
2019-12-03 15:20:21 +00:00
|
|
|
|
{
|
2019-12-10 15:06:51 +00:00
|
|
|
|
return services.AddDbContextManagerService<TenantDbContext>();
|
2019-12-03 15:20:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|