protected virtual void CreateOrMigrate(AbpTenantBase tenant) { var args = new DbPerTenantConnectionStringResolveArgs( tenant == null ? (int?)null : (int?)tenant.Id, tenant == null ? MultiTenancySides.Host : MultiTenancySides.Tenant ); args["DbContextType"] = typeof(TDbContext); args["DbContextConcreteType"] = typeof(TDbContext); var nameOrConnectionString = ConnectionStringHelper.GetConnectionString(_connectionStringResolver.GetNameOrConnectionString(args)); using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) { using (var dbContext = _iocResolver.ResolveAsDisposable <TDbContext>(new { nameOrConnectionString = nameOrConnectionString })) { //TODO: Please comple the logic of migrations dbContext.Object.Database.Migrate(); _unitOfWorkManager.Current.SaveChanges(); uow.Complete(); } } }
protected virtual void CreateOrMigrate(AbpTenantBase tenant) { var args = new DbPerTenantConnectionStringResolveArgs( tenant == null ? (int?)null : (int?)tenant.Id, tenant == null ? MultiTenancySides.Host : MultiTenancySides.Tenant ); args["DbContextType"] = typeof(TDbContext); args["DbContextConcreteType"] = typeof(TDbContext); var nameOrConnectionString = ConnectionStringHelper.GetConnectionString( _connectionStringResolver.GetNameOrConnectionString(args) ); using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) { using (var dbContext = _iocResolver.ResolveAsDisposable <TDbContext>(new { nameOrConnectionString = nameOrConnectionString })) { var dbInitializer = new MigrateDatabaseToLatestVersion <TDbContext, TConfiguration>( true, new TConfiguration { Tenant = tenant }); dbInitializer.InitializeDatabase(dbContext.Object); _unitOfWorkManager.Current.SaveChanges(); uow.Complete(); } } }
protected virtual void CreateOrMigrate(AbpTenantBase tenant, Action <TDbContext> seedAction) { var args = new DbPerTenantConnectionStringResolveArgs( tenant == null ? (int?)null : (int?)tenant.Id, tenant == null ? MultiTenancySides.Host : MultiTenancySides.Tenant ); args["DbContextType"] = typeof(TDbContext); args["DbContextConcreteType"] = typeof(TDbContext); var nameOrConnectionString = ConnectionStringHelper.GetConnectionString( _connectionStringResolver.GetNameOrConnectionString(args) ); using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)) { using (var dbContext = _dbContextResolver.Resolve <TDbContext>(nameOrConnectionString, null)) { dbContext.Database.Migrate(); seedAction?.Invoke(dbContext); _unitOfWorkManager.Current.SaveChanges(); uow.Complete(); } } }
/// <summary> /// Update the database /// </summary> private void CreateOrMigrate(AbpTenantBase tenant, Action seedAction) { var args = new DbPerTenantConnectionStringResolveArgs( tenant == null ? (int?)null : (int?)tenant.Id, tenant == null ? MultiTenancySides.Host : MultiTenancySides.Tenant ); //args["DbContextType"] = typeof(TDbContext); //args["DbContextConcreteType"] = typeof(TDbContext); var connectionString = GetConnectionString( _connectionStringResolver.GetNameOrConnectionString(args) ); // Put the database update into a scope to ensure // that all resources will be disposed. using var scope = CreateServices(connectionString).CreateScope(); // Instantiate the runner var runner = scope.ServiceProvider.GetRequiredService <IMigrationRunner>(); try { // Execute the migrations runner.MigrateUp(); } catch (Exception e) { throw; } }
public virtual void CreateOrMigrateForTenant(AbpTenantBase tenant) { if (tenant.ConnectionString.IsNullOrEmpty()) { return; } CreateOrMigrate(tenant); }
public virtual void CreateOrMigrateForTenant(AbpTenantBase tenant, Action <TDbContext> seedAction) { if (tenant.ConnectionString.IsNullOrEmpty()) { return; } CreateOrMigrate(tenant, seedAction); }
public void CreateOrMigrateForTenant(AbpTenantBase tenant) { CreateOrMigrateForTenant(tenant, null); }