예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="versionManager"></param>
        /// <param name="options"></param>
        public static void Migrate(ICodeMigrationVersionManager versionManager, ICodeMigrationOptions options)
        {
            var actualVersion = versionManager.GetVersion();

            options.Logger.Log($"Code migration begin with actualVersion: {actualVersion}");

            var migrators = GetMigrators();

            options.Logger.Log($"Find {migrators.Count} migrations");

            var notMigratedMigrators = migrators
                                       .Where(w => w.MigratorVersion > actualVersion)
                                       .OrderBy(o => o.MigratorVersion)
                                       .ToList();

            options.Logger.Log($"Find {notMigratedMigrators.Count} not migrated migrations");
            notMigratedMigrators.ForEach(f => Migrate(f, versionManager, options));

            options.Logger.Log($"Code migration finished with actualVersion: {actualVersion}");
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="info"></param>
        /// <param name="versionManager"></param>
        /// <param name="options"></param>
        private static void Migrate(CodeMigratorInfo info, ICodeMigrationVersionManager versionManager, ICodeMigrationOptions options)
        {
            options.Logger.Log($"Code migrator type {info.MigratorType} activate begin, with version {info.MigratorVersion}");
            var migrator = options.Activator.Activate(info.MigratorType);

            options.Logger.Log($"Code migrator type {info.MigratorType} activate end, with version {info.MigratorVersion}");

            options.Logger.Log($"Code migrator type {info.MigratorType} migrate begin, with version {info.MigratorVersion}");
            migrator.Migrate();
            options.Logger.Log($"Code migrator type {info.MigratorType} migrate end, with version {info.MigratorVersion}");

            versionManager.SetVersion(info.MigratorVersion);
        }