Exemple #1
0
        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);
        }
Exemple #2
0
        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")));
        }
Exemple #3
0
        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")));
        }
Exemple #4
0
        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")));
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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;
        }