Ejemplo n.º 1
0
        public async Task MigrateIdentityDbAsync()
        {
            try
            {
                if (!_persistedGrantContext.AllMigrationsApplied())
                {
                    _logger.LogInformation("Running PersistedGrantDbContext Migration");
                    await _persistedGrantContext.Database.MigrateAsync();

                    await _persistedGrantContext.SaveChangesAsync();
                }
                if (!_configurationContext.AllMigrationsApplied())
                {
                    _logger.LogInformation("Running ConfigurationDbContext Migration");
                    await _configurationContext.Database.MigrateAsync();

                    await _configurationContext.SaveChangesAsync();
                }
                if (!_identityContext.AllMigrationsApplied())
                {
                    _logger.LogInformation("Running IdentityDbContext Migration");
                    await _identityContext.Database.MigrateAsync();

                    await _identityContext.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                string message = LoggingEvents.MigratingDatabase.Name + " em-identitydb";
                _logger.LogCritical(LoggingEvents.MigratingDatabase, ex, message);
                throw new Exception(message, ex);
            }
        }