private void MigrateDatabase() { string filter = Env.IsProduction() || Env.IsStaging() // exclude db/datasets from production environment ? "AspNetCoreSample3.db.migrations" : "AspNetCoreSample3.db"; try { var cnx = new SqliteConnection(Configuration.GetConnectionString("MyDatabase")); var evolve = new Evolve.Evolve(cnx, msg => _logger.LogInformation(msg)) { EmbeddedResourceAssemblies = new[] { typeof(Startup).Assembly }, EmbeddedResourceFilters = new[] { filter }, IsEraseDisabled = true, Placeholders = new Dictionary <string, string> { ["${table4}"] = "table4" } }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } }
private void ExecuteMigrations(string connectionString) { if (_environment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Iconfiguration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connectionString)); if (iEnvironment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve(evolveConnection, msg => iLogger.LogInformation(msg)) { Locations = new List <string> { "db/migrations", "db/dataset" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { iLogger.LogCritical("Banco de Dados migration failed.", ex); throw; } } services.AddMvc(); services.AddApiVersioning(option => option.ReportApiVersions = true); services.AddScoped <IPersonBusiness, PersonBusinessImpl>(); services.AddScoped <IPersonRepository, PersonRepositoryImpl>(); services.AddScoped(typeof(IRepository <>), typeof(GenericRepository <>)); }
private void MigrateDatabase(string connectionString) { try { /* * No VS2019 * ---------- * O cara do vídeo usou o pomelo para conectar ao mysql porque no início do asp.net core não tinha * um driver para mysql nem da M$ nem da oracle (agora tem mas não suporta asp.net core 2.0). * Dessa forma, dá erro nesta linha pois o compilador identifica tanto o MySqlConnection, * quanto o MySqlConnector do pomelo. * Com isso, foi acrescentado ao csproj um alias para resolver as referencias usando o MySqlConnector. * Obs.: isso vai ferrar com as demais referências do projeto, * fechando e abrindo novamente o VS2019, ou ou mudar para o modo pasta e depois retornar para o modo solution, * recarregando o projeto. :-S */ var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve(evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new[] { "db/migrations" }, IsEraseDisabled = true }; evolve.Migrate(); } catch (System.Exception ex) { _logger.LogCritical("Database migration failed", ex); throw; } }
private void MigrateDatabase() { //Verificando se o ambiente e de desenvolvimento if (_environment.IsDevelopment()) { try { //Criação do objeto de conexão var evolveConnections = new SqlConnection(_configuration.GetValue <string>("ConnectionString")); //Cria um objeto do tipo evolve baseado no objeto de conexão var evolve = new Evolve.Evolve(evolveConnections, msg => Trace.TraceInformation(msg)) { //Local onde estão os arquivos do migration Locations = new List <string> { "Data/Migrations" }, //Quando hablitada essa opção os dados sao apagados IsEraseDisabled = false, }; //Rodando o Migrate evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed." + ex.Message); throw; } } }
private void ExecuteMigrations(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(_connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => _logger.LogInformation(msg) ) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migation failed.", ex); throw; } } else { app.UseHsts(); } }
private void ExecuteMigrations(IServiceCollection services) { var connectionString = _configuration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connectionString)); if (_environment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("Evolve.json", evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } }
public override void Migrate() { Log.Information($"DBMigration.Service Migrate of {MigrationDBName} is starting its execution."); InitDatabase(); try { using var connection = new SqlConnection(_configuration["DBConfiguration:GraphDataConnectionString"]); var evolve = new Evolve.Evolve(connection, msg => Log.Information(msg)) { Locations = GetMigrationLocations(_currentEnvironment), IsEraseDisabled = true, EnableClusterMode = true, OutOfOrder = true, }; Log.Information($"DBMigration.Service is now starting the migration process for {MigrationDBName}."); evolve.Migrate(); Log.Information($"DBMigration.Service has completed the migration process for {MigrationDBName}."); } catch (Exception ex) { Log.Fatal("DBMigration.Service has failed to migrate with exception {ex}.", ex); } Log.Information($"DBMigration.Service Migrate of {MigrationDBName} has completed its execution."); }
public async Task Migrate(string environmentName) { string location = GetLocation(environmentName); var connection = new SqlConnection(_config.GetConnectionString(DbConstants.SocialEventManager)); connection.Open(); try { await new EnumLookupTableCreator(_logger, connection).Run(); var evolve = new Evolve.Evolve(connection, msg => Log.Information(msg)) { Locations = new[] { location }, IsEraseDisabled = true, MetadataTableSchema = SchemaConstants.Migration, MetadataTableName = TableNameConstants.Changelog, }; evolve.Migrate(); connection.Close(); } catch (Exception ex) { _logger.Error(ExceptionConstants.DatabaseMigrationFailed, ex); throw; } }
private void ExecuteMigration(string connectionString) { if (_hostingEnvironment.IsDevelopment()) { try { var mySqlConnection = new MySqlConnection(connectionString); var evolve = new Evolve.Evolve(mySqlConnection, message => _logger.LogInformation(message)) { Locations = new List <string> { "db/scripts", "db/dataset" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Migration failed", ex); throw; } } }
static void Main(string[] args) { const string dbName = "appdb.db"; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .CreateLogger(); SQLiteConnection.CreateFile(dbName); try { var cnx = new SQLiteConnection(@$ "Data Source=.\{dbName};"); var evolve = new Evolve.Evolve(cnx, msg => Log.Logger.Information(msg)) { Locations = new[] { "migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); File.Copy(dbName, $"../../../../Infrastructure/{dbName}", true); File.Copy(dbName, $"../../../../Infrastructure.Tests/test{dbName}", true); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <ApplicationDBContext>(options => options.UseMySQL(connectionString)); if (this.environment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true }; evolve.Migrate(); } catch (Exception ex) { this.logger.LogCritical("Database migration failed.", ex); throw; } } services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //Dependency injector services.AddScoped <IPersonService, PersonServiceImplementation>(); }
public void Migrate() { var retryCount = 1; var allowedRetry = 5; var db = _configProvider.GetDbConnectionString(); do { try { using (var cnx = new NpgsqlConnection(db)) { var evolve = new Evolve.Evolve(cnx, x => Console.WriteLine(x)) { Locations = new[] { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); break; }; } catch (Exception ex) { retryCount++; Console.WriteLine($"DB Migrations Failed. {Environment.NewLine}{ex}"); } Thread.Sleep(5000); Console.WriteLine($"Retrying migration - Attempt number {retryCount}"); }while (retryCount <= allowedRetry); }
private void ExeculteMigrations(string connection) { if (_environment.IsDevelopment()) { try { // configurações do Evolve para rodar migrations SqlConnection cnx = new SqlConnection(connection); var evolve = new Evolve.Evolve("Evolve.json", cnx, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } }
static void Main(string[] args) { try { Log.Logger = new LoggerConfiguration() .WriteTo.ColoredConsole(Serilog.Events.LogEventLevel.Debug) .MinimumLevel.Debug() .Enrich.FromLogContext() .CreateLogger(); string dbConnectionString = "Server=MAUMAU-LENOVOZ4;Database=EVOLVE_DB;Trusted_Connection=True;"; IDbConnection dbConnection = new SqlConnectionFactory() .CreateConnection(dbConnectionString); Evolve.Evolve evolve = new Evolve.Evolve(dbConnection, msg => Log.Information(msg)) { MetadataTableSchema = "dbo", MetadataTableName = "changelog", Locations = new[] { "db/datasets", "db/migrations/versioned", "db/migrations/repeatable" }, IsEraseDisabled = true }; evolve.Migrate(); } catch (Exception ex) { Log.Fatal("Database migration failed.", ex); } }
private void ExecuteMigrations(string strconn) { //if (this.environment.IsDevelopment()) //{ try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(strconn); var evolve = new Evolve.Evolve(evolveConnection, msg => this.logger.LogInformation(msg)) { ///Locations = new List<string> { "db/migrations", "db/dataset" }, Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, Encoding = Encoding.UTF8, MetadataTableSchema = "webapi" }; evolve.Migrate(); } catch (Exception ex) { this.logger.LogCritical("Database migration failed.", ex); throw; } //} }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySqlContext>(options => options.UseMySql(connectionString)); if (this.environment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => logger.LogInformation(msg)) { Locations = new List <String>() { "db/migrations" }, IsEraseDisabled = true, }; evolve.Migrate(); } catch (Exception ex) { this.logger.LogCritical("Database Migration failed", ex); throw; } } services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddApiVersioning(); //Injeção de dependencia services.AddScoped <IPersonBusiness, PersonBusiness>(); services.AddScoped <IPersonRepository, PersonRepository>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = _configuration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connectionString)); if (_enviroment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve(evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } //Add Framework services services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddApiVersioning(); //Dependency Injection services.AddScoped <IPersonBusiness, PersonBusinessImpl>(); services.AddScoped <IPersonRepository, PersonRepositoryImpl>(); }
private void MigrateDatabase(ILogger <Startup> logger) { string location = Env.IsProduction() || Env.IsStaging() // exclude db/datasets from production environment ? "Db/Migration" : "db"; try { NpgsqlConnection cnx = new NpgsqlConnection(Configuration.GetConnectionString("MyDatabase")); var evolve = new Evolve.Evolve(cnx, msg => logger.LogInformation(msg)) { Locations = new[] { location }, IsEraseDisabled = true, Placeholders = new Dictionary <string, string> { ["${table4}"] = "table4" } }; evolve.Migrate(); } catch (Exception ex) { logger.LogCritical("Database migration failed.", ex); throw; } }
private void ExecuteMigrations(string connectionString) { if (this.environment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => logger.LogInformation(msg)) { // Where are the magrations: Locations = new List <string> { "Database/migrations" }, // Does not clean database IsEraseDisabled = true }; evolve.Migrate(); } catch (Exception exception) { this.logger.LogCritical("Database migration failed: ", exception); throw; } } }
private static void MigrateDatabase() { string filter = "ConsoleApp1.db.migrations"; var connectionString = "Server=DESKTOP-FFHEA6P;Database=TourManagementDB;Trusted_Connection=True;"; try { var cn = new SqlConnection(connectionString); var evolve = new Evolve.Evolve(cn, msg => Log(msg)) { EmbeddedResourceAssemblies = new[] { typeof(Program).Assembly }, EmbeddedResourceFilters = new[] { filter }, IsEraseDisabled = true, Placeholders = new Dictionary <string, string> { ["${Employee}"] = "Employee" } }; evolve.Migrate(); } catch (Exception ex) { throw; } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = _configuration["MySqlConnection:MySqlConnectionString"]; services.AddDbContext <MySqlContext>(options => options.UseMySql(connectionString)); services.AddScoped <IPersonService, PersonService>(); services.AddScoped <IPersonRepository, PersonRepository>(); services.AddApiVersioning(); if (_hostingEnvironment.IsDevelopment()) { try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve(evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations", "db/dataset" }, IsEraseDisabled = true }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } services.AddMvc(); }
private void ExecutarMigration(string connectionString) { // Verifica em qual ambiente está executando: produção, desenvolvimento, etc. if (Environment.IsDevelopment()) { try { // Foi necessário criar um alias no arquivo csproj para resolver o conflito de versões entre o MySql.Data e o Pomelo. var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("Evolve.json", evolveConnection, mensagem => _logger.LogInformation(mensagem)) { Locations = new List <string>() { "Db/Migrations", "Db/Dataset" }, // Nomes das migrations. IsEraseDisabled = true // Para não apagar os dados toda vez que rodar. }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database Migration falhou.", ex); throw ex; } } }
public void ConfigureServices(IServiceCollection services) { if (Environment.IsProduction()) { try { var cnx = new SqliteConnection(Configuration.GetConnectionString("MyDatabase")); var evolve = new Evolve.Evolve("evolve.json", cnx, msg => _logger.LogInformation(msg)) // retrieve the MSBuild configuration { Locations = new List <string> { "db/migrations" }, // exclude db/datasets from production environment IsEraseDisabled = true, // ensure erase command is disabled in production }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } } services.AddMvc(); }
private static void MigrateDatabase() { // exclude db/datasets from production and staging environments string location = EnvironmentName == Environments.Production || EnvironmentName == Environments.Staging ? "db/migrations" : "db"; try { var cnx = new SqliteConnection(Configuration.GetConnectionString("MyDatabase")); var evolve = new Evolve.Evolve(cnx, msg => Log.Information(msg)) { Locations = new[] { location }, IsEraseDisabled = true, Placeholders = new Dictionary <string, string> { ["${table4}"] = "table4" } }; evolve.Migrate(); } catch (Exception ex) { Log.Error("Database migration failed.", ex); throw; } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = _configuration["MysqlConnection:MySqlConnectionString"]; services.AddDbContext <MySQLContext>(options => options.UseMySql(connectionString)); try { var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); var evolve = new Evolve.Evolve("evolve.json", evolveConnection, msg => _logger.LogInformation(msg)) { Locations = new List <string> { "db/migrations" } }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed", ex); throw; } services.AddMvc(); services.AddApiVersioning(); services.AddScoped <IPersonBusiness, PersonBusinessImpl>(); services.AddScoped <IPersonRepository, PersonRepositoryImpl>(); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { try { var cnx = new System.Data.SqlClient.SqlConnection(_connectionString); var evolve = new Evolve.Evolve(cnx, msg => _logger.LogInformation(msg)) { Locations = new[] { "migrations", "views" }, IsEraseDisabled = true, Placeholders = new Dictionary <string, string> { ["${orderTable}"] = "OrderTable1" } }; evolve.Migrate(); } catch (Exception ex) { _logger.LogCritical("Database migration failed.", ex); throw; } while (!stoppingToken.IsCancellationRequested) { await Task.Delay(1000, stoppingToken); } }
/// <summary> /// Initialize SQLite Database. /// </summary> public Task DoInitialize() { return(Task.Run(() => { // Get assemblies and filters from MigrationsNamespaces var embeddedMigrationAssemblies = new List <Assembly>(); var embeddedMigrationsFilters = new List <string>(); foreach (var migrationsNamespace in MigrationsNamespaces) { embeddedMigrationAssemblies.Add(Assembly.Load(migrationsNamespace)); embeddedMigrationsFilters.Add($"{migrationsNamespace}.db"); } // Build connection string. var dbFilePath = LocalDbManager.DatabaseFile; var msConnString = $"Data Source={dbFilePath};"; var sqliteConnection = new SqliteConnection(msConnString); // Apply Migrations. var evolve = new Evolve.Evolve(sqliteConnection, LoggerManager.MainLogger.ForContext <SqLiteBootstrapInitializer>().Information) { EmbeddedResourceAssemblies = embeddedMigrationAssemblies.ToArray(), EmbeddedResourceFilters = embeddedMigrationsFilters.ToArray(), MustEraseOnValidationError = LocalDbManager.EraseSchemaIfValidationFails, IsEraseDisabled = !LocalDbManager.EraseSchemaIfValidationFails }; evolve.Migrate(); // Initialize LocalDB LocalDbManager.DbConnection = new SQLiteAsyncConnection(dbFilePath); })); }
static int Main(string[] args) { try { var connectionString = System.Configuration.ConfigurationManager.AppSettings["Evolve.ConnectionString"]; _logger.Debug(connectionString); var cnx = new MySqlConnection(connectionString); cnx.Open(); var evolve = new Evolve.Evolve(cnx, msg => _logger.Info(msg)) { Locations = new List <string> { System.Configuration.ConfigurationManager.AppSettings["Evolve.Locations"] }, IsEraseDisabled = true }; evolve.Migrate(); // All ok return(0); } catch (Exception ex) { _logger.Fatal($@"Database migration failed. {ex.Message}", ex.Message); return(1); } }
private void ExecuteMigrations(string strconn) { //if (this.environment.IsDevelopment()) //{ try { using (var evolveConnection = new MySql.Data.MySqlClient.MySqlConnection(strconn)) { var evolve = new Evolve.Evolve(evolveConnection, msg => this.logger.LogInformation(msg)) { //Locations = new List<string> { "db/migrations", "db/dataset" }, Locations = new List <string> { "db/migrations" }, IsEraseDisabled = true, Encoding = Encoding.UTF8, MetadataTableSchema = "movie" //todo: Encoding not working for inserts //ALTER TABLE database.table MODIFY COLUMN col VARCHAR(255) //CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; }; evolve.Migrate(); }; } catch (Exception ex) { this.logger.LogCritical("Database migration failed.", ex); throw; } //} }