Exemplo n.º 1
0
        private MigrationDefinition[] CalculateMigrationsToExecute()
        {
            ExistMigrations existMigrations = LoadExistMigrations();

            var requiredMigrationNames = new HashSet <string>(
                requiredMigrations.Select(x => x.Name));

            ExistMigrationInfo[] divergedMigrations =
                existMigrations
                .Where(x => !requiredMigrationNames.Contains(x.Name))
                .ToArray();

            if (divergedMigrations.Length > 0)
            {
                string errMsg = "The database has applied migrations that do not exist in the required migrations.";
                throw new MigrationDivergedException(errMsg, divergedMigrations);
            }

            var existMigrationNames = new HashSet <string>(
                existMigrations.Select(x => x.Name));

            MigrationDefinition[] migrationsToExecute =
                requiredMigrations
                .Where(x => !existMigrationNames.Contains(x.Name))
                .ToArray();

            return(migrationsToExecute);
        }
Exemplo n.º 2
0
 public MigratorUnderTest(
     CouchDBContextImpl context,
     RequiredMigrations requiredMigrations,
     ExistMigrations existMigrations)
     : base(context, requiredMigrations)
 {
     this.existMigrations = existMigrations;
 }
Exemplo n.º 3
0
        public void NoMigrationToExecute()
        {
            var requiredMigrations = new RequiredMigrations();

            requiredMigrations.Add(new MigrationMock("001Migration", MigrationExcpectation.NotToRun));

            var existMigrations = new ExistMigrations();

            existMigrations.Add(new ExistMigrationInfo("001Migration"));

            var context = new CouchDBContextImpl(null);
            var subject = new MigratorUnderTest(context, requiredMigrations, existMigrations);

            subject.Migrate();

            EnsureExpectedMigrationRan(requiredMigrations);
        }
Exemplo n.º 4
0
        protected virtual ExistMigrations LoadExistMigrations()
        {
            ExistMigrations existMigrations = new ExistMigrations();

            migrationsDoc = context.ClientAdaper.GetDocument(MigrationsDocumentId);
            if (migrationsDoc == null)
            {
                migrationsDoc = CreateEmptyMigrationsDoc();
            }

            JArray appliedArray = migrationsDoc.Value <JArray>(AppliedMigrationField);

            foreach (JToken appliedMigrationObj in appliedArray)
            {
                string migrationName = appliedMigrationObj.Value <string>(MigrationInfoNameField);
                existMigrations.Add(new ExistMigrationInfo(migrationName));
            }

            return(existMigrations);
        }