Inheritance: DbScriptFolderManager
Exemplo n.º 1
0
        public void CheckMigrationPolicies()
        {
            _dbPath = DisposableDbManager.FindDatabaseScriptsPath(DbName);

            var undocumentedMigrations = new List<string>();
            var migrations = new MigrationManager().GetSqlSriptsIn(_dbPath.FullName);
            foreach (var migration in migrations)
            {
                var migrationContents = File.ReadAllText(migration.FullName).ToLower();

                bool found = false;
                foreach (var migrationPolicyText in _migrationStringContainingPolicies)
                {
                    if (migrationContents.Contains(migrationPolicyText.ToLower()))
                    {
                        found = true;
                    }
                }

                if (!found) {
                    undocumentedMigrations.Add(migration.Name);
                }
            }

            if (undocumentedMigrations.Count > 0)
            {
                throw new InvalidOperationException(
                    String.Format("The following migrations don't comply with the policies: {0}" + Environment.NewLine +
                        "Policies are: {1}",
                    Environment.NewLine + string.Join("," + Environment.NewLine, undocumentedMigrations.ToArray()),
                    Environment.NewLine + string.Join("," + Environment.NewLine, _migrationPolicies.ToArray())));
            }
        }
 private void RunMigrations(string disposableDbName, IEnumerable<string> migrationWhiteList)
 {
     if (migrationWhiteList != null)
         Console.WriteLine("Attempting to run {0} migrations in {1}...", migrationWhiteList.Count(), _dbNameInVcs);
     else
         Console.WriteLine("Attempting to run all migrations in {0}...", _dbNameInVcs);
     int migrationCount = new MigrationManager()
         .RunScripts(_disposableDbServer, _dbScriptsPath, disposableDbName, _dbNameInVcs, migrationWhiteList);
     if (migrationWhiteList != null && migrationCount < migrationWhiteList.Count())
         throw new Exception(String.Format("There was some kind of problem and {0} migrations were applied instead of {1}. First migration requested was {2}.",
                                           migrationCount, migrationWhiteList.Count(), migrationWhiteList.First()));
     Console.WriteLine("Successfully applied {0} migrations", migrationCount);
 }
Exemplo n.º 3
0
        public void CheckStuckMigrations()
        {
            _disposableDbServer = DatabaseCreationTests.GetDisposableDbServer();

            TimeSpan maxPeriod = TimeSpan.FromDays(15);

            DirectoryInfo dbpath = DisposableDbManager.FindDatabaseScriptsPath(DbName);

            var stuckMigrations = new List<MigrationManager.Migration>();
            var migrationManager = new MigrationManager();

            IEnumerable<string> migrationSqlFiles =
                migrationManager.GetSqlSriptsIn(dbpath.FullName).Select(file => Path.GetFileNameWithoutExtension(file.Name));

            foreach (var migration in migrationManager.GetMigrationsRunInDb(dbpath, _disposableDbServer, DbName))
            {
                if (migrationSqlFiles.Contains(migration.FileNameWithoutExtension) &&
                    migration.AppliedDate.Add(maxPeriod) < DateTime.Now)
                    stuckMigrations.Add(migration);
            }
            if (stuckMigrations.Count > 0)
            {
                throw new InvalidOperationException(
                    String.Format(
                        "The following migrations have been more than {0} days in staging phase " +
                        "(they need to be merged to the History/ subforlder to not be considered in 'staging'): {1}",
                        maxPeriod.Days, Environment.NewLine + string.Join("," + Environment.NewLine, stuckMigrations.Select(m => m.FileNameWithoutExtension).ToArray())));
            }
        }
Exemplo n.º 4
0
        public void CheckThatDisposableDbCreationStillWorksAfterApplyingEachMigration()
        {
            _dbCreationPath = ConfigurationManager.AppSettings["DbCreationPath"];
            _disposableDbServer = DatabaseCreationTests.GetDisposableDbServer();

            var creator = new DisposableDbManager(_dbCreationPath, _disposableDbServer, DbName);
            creator.AllowCreatingSameDb = true;

            var baseDbWithNoMigrations = creator.CreateCompleteDisposableDbWithMigrations(new string[0]);

            _dbPath = DisposableDbManager.FindDatabaseScriptsPath(DbName);
            IEnumerable<FileInfo> migrations = new MigrationManager().GetSqlSriptsIn(_dbPath.FullName);

            var migrationsAlreadyTested = new List<string>();

            foreach (var migration in migrations)
            {
                TestMigration(migration, migrationsAlreadyTested, baseDbWithNoMigrations);
                migrationsAlreadyTested.Add(Path.GetFileNameWithoutExtension(migration.FullName));
            }
        }