public void Run(ISimpleMigrator migrator, long targetVersion)
        {
            var currentVersion = migrator.CurrentMigration.Version;

            var migrationsToApply = migrator.Migrations.VersionsToBeApplied(currentVersion, targetVersion);

            var action = migrator.IsRollBack(targetVersion) ? "Down" : "Up";

            foreach (var migration in migrationsToApply)
            {
                if (migrator.IsRollBack(targetVersion) && migration == migrationsToApply.Last())
                {
                    migrator.MigrateTo(migration.Version);
                }
                else
                {
                    _outputWriter.Write($"Applying version {migration.Version} ({action}) - {migration.Description}...");
                    migrator.MigrateTo(migration.Version);
                    _outputWriter.WriteLine("Done");
                }
            }
        }
        private void WriteVersionsToBeApplied(ISimpleMigrator migrator, long targetVersion)
        {
            var versionsToBeApplied = migrator.Migrations.VersionsToBeAppliedNoop(migrator.CurrentMigration.Version, targetVersion);

            _outputWriter.WriteLine("The following migrations will be applied:");

            var action = migrator.IsRollBack(targetVersion) ? "Down" : "Up";

            foreach (var versionToApply in versionsToBeApplied)
            {
                _outputWriter.WriteLine($"\t{versionToApply.Version} ({action}) - {versionToApply.Description}");
            }

            _outputWriter.WriteLine();
        }
Пример #3
0
        public void WriteVersionSection(ISimpleMigrator migrator, Settings settings)
        {
            _outputWriter.WriteLine($"Current database version is {migrator.CurrentMigration.Version}");
            _outputWriter.WriteLine();

            var migrationAction = migrator.IsRollBack(settings.TargetVersion) ? "Rolling back" : "Updating";
            var targetMigration = migrator.Migrations.Single(m => m.Version == settings.TargetVersion);

            if (targetMigration == null)
            {
                return;
            }

            _outputWriter.WriteLine($"{migrationAction} database");
            _outputWriter.WriteLine($"\tfrom:\t{migrator.CurrentMigration.Version} - {migrator.CurrentMigration.Description}");
            _outputWriter.WriteLine($"\tto:\t{targetMigration.Version} - {targetMigration.Description}");
            _outputWriter.WriteLine();
        }