public void UpgradeDataBase() { // start conecxão da db. using (var connection = new NpgsqlConnection(cnn)) { var databaseProvider = new PostgresqlDatabaseProvider(connection); var migrator = new SimpleMigrator(assemblyTo, databaseProvider); // carregar todos os estados de versões da base de dados. migrator.Load(); // quando existir uma versão já ativa, inicie as migrações apratir de uma versão especifica. //migrator.Baseline(10); // verificar se a versão da db atual é diferente da ultima versão dos arquivos de migrações. if (migrator.CurrentMigration.Version != migrator.LatestMigration.Version) { // atualizar db para ultima versão. migrator.MigrateToLatest(); // atualizar db até o arquivo de migração numero 11. //migrator.MigrateTo(11); } Assert.IsTrue(migrator.CurrentMigration.Version == migrator.LatestMigration.Version); } }
/// <summary> /// Inits Event Store /// </summary> public Exercise09Projections() { databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection(); var databaseProvider = new PostgresqlDatabaseProvider(databaseConnection) { SchemaName = typeof(Exercise09Projections).Name }; var migrationsAssembly = typeof(Exercise09Projections).Assembly; var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); // Create Event Store eventStore = new EventStore(databaseConnection); eventStore.AddProjection(new UserDashboardProjection(databaseConnection)); // Initialize Event Store eventStore.Init(); userRepository = new Repository <User>(eventStore); orderRepository = new Repository <Order>(eventStore); }
public static void Initialize(DatabaseConfig config) { s_connectionString = $"SslMode=none;Server={config.Host};Port={config.Port};Database={config.Database};Uid={config.Username};Pwd={config.Password};Pooling=true;"; OrmConfiguration.DefaultDialect = SqlDialect.MySql; using (var con = Open()) { if (con.QueryFirstOrDefault($"SHOW DATABASES LIKE \"{config.Database}\"") == null) { throw new DatabaseNotFoundException(config.Database); } var databaseProvider = new MysqlDatabaseProvider(con) { TableName = "__version" }; var assemblyProvider = new AssemblyMigrationProvider(typeof(Base).Assembly, typeof(Base).Namespace); var migrator = new SimpleMigrator(assemblyProvider, databaseProvider); migrator.Load(); if (migrator.CurrentMigration.Version != migrator.LatestMigration.Version) { if (config.RunMigration) { migrator.MigrateToLatest(); } else { throw new DatabaseVersionMismatchException(migrator.CurrentMigration.Version, migrator.LatestMigration.Version); } } } }
/// <summary> /// Inits Event Store /// </summary> public Exercise08Snapshots() { databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection(); var databaseProvider = new PostgresqlDatabaseProvider(databaseConnection) { SchemaName = typeof(Exercise08Snapshots).Name }; var migrationsAssembly = typeof(Exercise08Snapshots).Assembly; var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); // Create Event Store eventStore = new EventStore(databaseConnection); var userSnapshot = new SnapshotToTable <User>( databaseConnection, @"TODO write upsert here"); eventStore.AddSnapshot(userSnapshot); // Initialize Event Store eventStore.Init(); repository = new Repository <User>(eventStore); }
/// <summary> /// Inits Event Store /// </summary> public Exercise08Snapshots() { databaseConnection = PostgresDbConnectionProvider.GetFreshDbConnection(); var databaseProvider = new PostgresqlDatabaseProvider(databaseConnection) { SchemaName = typeof(Exercise08Snapshots).Name }; var migrationsAssembly = typeof(Exercise08Snapshots).Assembly; var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); // Create Event Store eventStore = new EventStore(databaseConnection); var userSnapshot = new SnapshotToTable <User>( databaseConnection, @"INSERT INTO users (id, name, version) VALUES (@Id, @Name, @Version) ON CONFLICT (id) DO UPDATE SET name = @Name, version = @Version"); eventStore.AddSnapshot(userSnapshot); // Initialize Event Store eventStore.Init(); repository = new Repository <User>(eventStore); }
public MigrateDb(ISession connection) { var migrationsAssembly = Assembly.GetExecutingAssembly(); var migrator = new SimpleMigrator(migrationsAssembly, new SqliteDatabaseProvider(connection.Connection as SQLiteConnection)); migrator.Load(); migrator.MigrateToLatest(); }
public void InitializeDatabase() { var migrator = new SimpleMigrator(typeof(DatabaseInitializer).Assembly, new PostgresqlDatabaseProvider(_con)); migrator.Load(); migrator.MigrateTo(1); migrator.MigrateToLatest(); }
protected SimpleMigrator <SQLiteConnection, SQLiteNetMigration> GetMigrator(SQLiteConnection connection) { var migrationDbProvider = new SQLiteNetDatabaseProvider(connection); var migrator = new SimpleMigrator <SQLiteConnection, SQLiteNetMigration>( typeof(LocalDatabase).GetTypeInfo().Assembly, migrationDbProvider); migrator.Load(); return(migrator); }
public Startup(IConfiguration configuration) { Configuration = configuration; var provider = new PostgresqlDatabaseProvider(new NpgsqlConnection(Configuration.GetConnectionString("DefaultConnection"))); var migrator = new SimpleMigrator(typeof(Database.Migrations._001_Tokens).GetTypeInfo().Assembly, provider); migrator.Load(); migrator.MigrateToLatest(); }
public void Start() { using (var uow = _dbFactory.Create <IUnitOfWork, IFooSession>(IsolationLevel.Serializable)) { var databaseProvider = new SqliteDatabaseProvider(uow.Connection as System.Data.Common.DbConnection); var migrator = new SimpleMigrator(Assembly.GetExecutingAssembly(), databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
public static void MigrateSqlDbData(string sqlConnectionString) { var migrationsAssembly = typeof(Program).Assembly; using (var connection = new MySqlConnection(sqlConnectionString)) { var databaseProvider = new MysqlDatabaseProvider(connection); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateTo(2018_10_18_00_45); } }
public void Migrate(string[] args) { var options = Cli.Parse <MigrateOptions>(args); var connectionString = $"SslMode=none;Server={options.Host};Port={options.Port};Database={options.Database};Uid={options.User};Pwd={options.Password};"; using (var con = new MySqlConnection(connectionString)) { con.Open(); var databaseProvider = new MysqlDatabaseProvider(con) { TableName = "__version" }; AssemblyMigrationProvider assemblyProvider = null; switch (options.Schema.ToLower()) { case "auth": assemblyProvider = new AssemblyMigrationProvider(s_authType.Assembly, s_authType.Namespace); break; case "game": assemblyProvider = new AssemblyMigrationProvider(s_gameType.Assembly, s_gameType.Namespace); break; default: Error("Invalid schema"); break; } try { var migrator = new SimpleMigrator(assemblyProvider, databaseProvider, new ConsoleLogger()); migrator.Load(); if (options.CurrentVersion > 0) { migrator.Baseline(options.CurrentVersion); } if (options.Version == 0) { migrator.MigrateToLatest(); } else { migrator.MigrateTo(options.Version); } } catch (MigrationNotFoundException ex) { Error(ex.Message); } } }
public async Task MigrateToLatestVersionAsync() { using (var connection = new SqlConnection(_sqlConnectionString)) { await connection.OpenAsync(); var migrationsAssembly = typeof(DatabaseManager).Assembly; var databaseProvider = new MssqlDatabaseProvider(connection); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
private void DatabaseMigration() { var migrationsAssembly = typeof(CreateJobsTable001).Assembly; using (var connection = new SqlConnection(Configuration.GetConnectionString("Default"))) { var databaseProvider = new MssqlDatabaseProvider(connection); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
private static SimpleMigrator CreateMigrator(DbConnection connection, Settings settings) { var migrationAssembly = GetMigrationAssembly(settings.MigrationAssemblyPath); var provider = new MssqlDatabaseProvider(connection) { SchemaName = settings.VersionTableSchema }; var migrator = new SimpleMigrator(migrationAssembly, provider); migrator.Load(); return(migrator); }
private static void Migrate() { var migrationsAssembly = typeof(Program).Assembly; using (var connection = new NpgsqlConnection(StoreFactory.ConnectionString)) { var databaseProvider = new PostgresqlDatabaseProvider(connection); //new SimpleMigrator<X, B>(migrationsAssembly, null); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
public static void Main(string[] args) { var migrationsAssembly = Assembly.GetEntryAssembly(); using (var connection = new NpgsqlConnection("Host=127.0.0.1;Username=doublemazeuser;Password=mycoolpass;Database=doublemaze")) { var databaseProvider = new PostgresqlDatabaseProvider(connection); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
protected SimpleMigrator CreateMigrator(string name, params Type[] migrationTypes) { foreach (var migrationType in migrationTypes) { var setupMethod = migrationType.GetMethod("Setup", BindingFlags.Static | BindingFlags.Public); setupMethod.Invoke(null, new object[] { this.MigrationStringsProvider }); } var migrationProvider = new CustomMigrationProvider(migrationTypes); var migrator = new SimpleMigrator(migrationProvider, this.CreateDatabaseProvider(), new NUnitLogger(name)); migrator.Load(); return(migrator); }
public IActionResult Migrate() { var migrationsAssembly = typeof(Migrations.Program).Assembly; using (var db = new SqlConnection(_configuration.GetValue <string>("CONNECTION_STRING"))) { var databaseProvider = new MssqlDatabaseProvider(db); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } return(NoContent()); }
public MigrateDb() { var migrationsAssembly = Assembly.GetExecutingAssembly(); var versionProvider = new SqliteVersionProvider(); var factory = A.Fake <IDbFactory>(); Connection = new TestSession(factory, "Data Source=:memory:;Version=3;New=True;"); A.CallTo(() => factory.Create <IUnitOfWork>(A <IDbFactory> ._, A <ISession> ._)) .ReturnsLazily(CreateUnitOrWork); var migrator = new SimpleMigrator(migrationsAssembly, Connection, versionProvider); migrator.Load(); migrator.MigrateToLatest(); }
public void ApplyMigrations() { var config = LoadConfiguration(); var connString = config.GetConnectionString("Kiukie"); LoadServices(connString); using (var connection = new SqlConnection(connString)) { var databaseProvider = new MssqlDatabaseProvider(connection); var migrator = new SimpleMigrator(typeof(TestFixtureContext).Assembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); } }
public void TestSetup() { if (TestSession != null) { return; } if (!File.Exists(DbName)) { using (File.Create(DbName)) { } } TestSession = new TestSqlForGuid(A.Fake <IDbFactory>()); var migrator = new SimpleMigrator(Assembly.GetExecutingAssembly(), new MssqlDatabaseProvider(TestSession.Connection as SqlConnection)); migrator.Load(); migrator.MigrateToLatest(); }
static void Main(string[] args) { var migrationsAssembly = typeof(Program).Assembly; var connectionString = new SqlConnectionStringBuilder { DataSource = ".", InitialCatalog = "SMP", IntegratedSecurity = true }.ConnectionString; using var connection = new SqlConnection(connectionString); var databaseProvider = new MssqlDatabaseProvider(connection); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); migrator.MigrateToLatest(); }
private static void DoMigration(string connectionString, Action <SimpleMigrator> act) { // Connection to database using var db = new MySqlConnection(connectionString); // Get migration objects var provider = new MysqlDatabaseProvider(db) { TableName = $"`{AuthDb.Schema}.version_info`" }; var migrator = new SimpleMigrator(typeof(MySqlDbClient).Assembly, provider, new ConsoleLogger()); // Get all the migrations migrator.Load(); // Perform the migration act(migrator); }
/// <summary> /// Migrates the database up to the latest version. /// </summary> /// <param name="dbConnectionFactory">Factory to create a <see cref="IDbConnection"/> instance.</param> public static void Migrate(IDbConnectionFactory dbConnectionFactory) { var migrationsAssembly = typeof(DatabaseMigrator).Assembly; using (var connection = dbConnectionFactory.Create()) { EnsureDatabaseDirectoryExists(connection.ConnectionString); var databaseProvider = new SQLiteNetDatabaseProvider((SQLiteConnection)connection); var migrator = new SimpleMigrator <SQLiteConnection, SQLiteNetMigration>(migrationsAssembly, databaseProvider); migrator.Load(); if (migrator.CurrentMigration.Version != migrator.LatestMigration.Version) { migrator.MigrateToLatest(); } } }
/// <summary> /// Run migrator /// </summary> /// <param name="args"> /// up: Migrate to the latest version (default) /// to <n>: Migrate up/down to the version n (0 for reset) /// reapply: Re-apply the current migration /// list: List all available migrations /// baseline <n>: Move the database to version n, without apply migrations /// </param> static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); string connectionString = builder.GetConnectionString("DefaultConnection"); var migrationsAssembly = typeof(Program).Assembly; using (var db = new SqlConnection(connectionString)) { var databaseProvider = new MssqlDatabaseProvider(db); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); var consoleRunner = new ConsoleRunner(migrator); consoleRunner.Run(args); } }
public void DowngradeDataBase() { int versionTo = 0; using (var connection = new NpgsqlConnection(cnn)) { var databaseProvider = new PostgresqlDatabaseProvider(connection); var migrator = new SimpleMigrator(assemblyTo, databaseProvider); // carregar todos os estados de versões da base de dados. migrator.Load(); // a versão da db atual deve ser maior que a versão versionTo. if (migrator.CurrentMigration.Version > versionTo) { // versão da db para qual deseja voltar. migrator.MigrateTo(versionTo); } Assert.IsTrue(migrator.CurrentMigration.Version == migrator.LatestMigration.Version); } }
private static void ExecuteMigrations(IDbConnection connection, string[] args) { if (connection == null) { return; } using (var conn = connection) { var databaseProvider = new SqlDatabaseProvider(conn); var migrator = new SimpleMigrator <IDbConnection, BaseMigration>(Assembly.GetCallingAssembly(), databaseProvider); try { if (args == null || args.Length == 0) { migrator.Load(); if (RollbackVersion.HasValue && RollbackVersion > 0) { migrator.MigrateTo(RollbackVersion.Value); } if (MigrateToLatest) { migrator.MigrateToLatest(); } } else { var console = new ConsoleRunner(migrator); console.Run(args); } } catch { throw; } } }
public void RunMigrations(DbService db) { var migrationsAssembly = typeof(Startup).Assembly; using (var pg = db.CreateConnection(longTimeout: true)) { var databaseProvider = new PostgresqlDatabaseProvider(pg); var migrator = new SimpleMigrator(migrationsAssembly, databaseProvider); migrator.Load(); if (migrator.CurrentMigration == null || migrator.CurrentMigration.Version == 0) { migrator.Baseline(2); } migrator.MigrateTo(5); if (migrator.LatestMigration.Version != migrator.CurrentMigration.Version) { throw new Exception($"The newest available migration ({migrator.LatestMigration.Version}) != The current database migration ({migrator.CurrentMigration.Version}). You probably need to add a call to run the migration."); } } }
public async Task <ISimpleMigrator> CreateAsync(MigrationOptions options) { var projectInfo = await _projectInfoDiscoverer.DiscoverAsync( !options.NoBuild, options.Configuration, options.Framework, options.Project, options.Assembly, options.ConnectionString, options.ConnectionStringName); using (var loader = new DependencyAwareAssemblyLoader(projectInfo.ProjectAssembly)) { var migrationProvider = new AssemblyMigrationProvider(projectInfo.ProjectAssembly); var connection = new SqlConnection(projectInfo.ConnectionString); var dbProvider = new MssqlDatabaseProvider(connection) { SchemaName = "dbo" }; var migrator = new SimpleMigrator(migrationProvider, dbProvider, _migrationLogger); migrator.Load(); return(migrator); } }
protected SimpleMigrator CreateMigrator(string name, params Type[] migrationTypes) { foreach (var migrationType in migrationTypes) { var setupMethod = migrationType.GetMethod("Setup", BindingFlags.Static | BindingFlags.Public); setupMethod.Invoke(null, new object[] { this.MigrationStringsProvider }); } var migrationProvider = new CustomMigrationProvider(migrationTypes); var migrator = new SimpleMigrator(migrationProvider, this.CreateDatabaseProvider(), new NUnitLogger(name)); migrator.Load(); return migrator; }