public void ItShouldNotApplyMigrationsSinceLastVersionWhenVersionBiggerThanMigration() { var database = new DatabaseStub(3); var logger = new LoggerStub(); var schema = new Schema(database, logger); var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger); migrator.MigrateToLatest(); Assert.That(database.Statements.Any(x => x.Contains("FirstMigration")), Is.False); }
public void ItShouldInformIfNoMigrationsFoundInAssembly() { var database = new DatabaseStub(); var logger = new LoggerStub(); var schema = new Schema(database, logger); var migrator = new Migrator(schema, typeof (Schema).Assembly, logger); migrator.MigrateToLatest(); Assert.That(logger.Logs.Any(x=>x.Contains(@"No Migrations Found"))); }
public void ItShouldFindFirstMigrationInAssembly() { var database = new DatabaseStub(); var logger = new LoggerStub(); var schema = new Schema(database, logger); var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger); migrator.MigrateToLatest(); Assert.That(logger.Logs.Any(x => x.Contains(@"Found 1 Migrations"))); }
public void ItShouldApplyMigrationsSinceLastVersionAndUpdateSchemaTable() { var database = new DatabaseStub(); var logger = new LoggerStub(); var schema = new Schema(database, logger); var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger); migrator.MigrateToLatest(); Assert.That(database.Statements.Any(x => x.Contains("FirstMigration"))); }
public void ItShouldNotUpdateSchemaVersionTo1IfMigrationNotApplicable() { var database = new DatabaseStub(3); var logger = new LoggerStub(); var schema = new Schema(database, logger); var migrator = new Migrator(schema, typeof(FirstMigration).Assembly, logger); migrator.MigrateToLatest(); Assert.That(database.Statements.Any(x => x.Contains(@"INSERT INTO [dbo].[SchemaInfo] ([Version]) VALUES (1)")), Is.False); }
public static int Main(string[] args) { var logger = new ConsoleLogger(); try { IDatabase database = CreateDatabaseFromArgs(args, logger); if (database != null) { var migrator = new Migrator(new Schema(database, logger), Assembly.LoadFrom(args[0]), logger); migrator.MigrateToLatest(); } else { throw new ArgumentException("Invalid Arguments"); } } catch (Exception ex) { logger.WriteToLog("An error occurred while trying to migrate. \nUsage: Nomad ':assemblyfile' [:connectionstring]\nNomad ':assemblyfile' ':server' ':db' [':user' ':password']"); logger.WriteToLog("Error Details: {0}", ex); return -1; } return 0; }