Ejemplo n.º 1
0
        /// <summary>
        /// Rolls back all migrations.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        public void MigrateDown(ICorePlugin plugin)
        {
            Debug.Assert(plugin != null);
            Assembly pluginMigrationsAssembly = plugin.GetPluginMigrationsAssembly();

            if (pluginMigrationsAssembly != null)
            {
                using (ECM7.Migrator.Migrator migrator = GetMigrator(pluginMigrationsAssembly))
                {
                    if (migrator.AvailableMigrations != null && migrator.AvailableMigrations.Count > 0)
                    {
                        var migrationService = ServiceLocator.Current.GetInstance <IMigrationService>();
                        IEnumerable <Migration> pluginInstalledMigrations = FillPluginSchemaInfo(plugin, migrationService);
                        migrator.Migrate(0);
                        IEnumerable <long> pluginMigrations =
                            (from migrationsType in migrator.AvailableMigrations select migrationsType.Version).
                            AsEnumerable
                                ();
                        foreach (var pluginInstalledMigration in pluginInstalledMigrations)
                        {
                            if (pluginMigrations.Contains(pluginInstalledMigration.Version))
                            {
                                migrationService.Delete(pluginInstalledMigration);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies migrations for specified plugin.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        public void MigrateUp(ICorePlugin plugin)
        {
            Debug.Assert(plugin != null);
            Assembly pluginMigrationsAssembly = plugin.GetPluginMigrationsAssembly();

            if (pluginMigrationsAssembly != null)
            {
                var migrationService = ServiceLocator.Current.GetInstance <IMigrationService>();
                IEnumerable <Migration> pluginMigrations = FillPluginSchemaInfo(plugin, migrationService);
                using (ECM7.Migrator.Migrator migrator = GetMigrator(pluginMigrationsAssembly))
                {
                    migrator.Migrate();
                    IList <long> appliedMigrations = migrator.GetAppliedMigrations();
                    if (appliedMigrations != null && appliedMigrations.Count > 0)
                    {
                        IEnumerable <long> pluginMigrationsVersions = (from pluginMigration in pluginMigrations
                                                                       select pluginMigration.Version).AsEnumerable();
                        appliedMigrations.ToList().RemoveAll(
                            migration => pluginMigrationsVersions.Contains(migration));
                        if (appliedMigrations.Count > 0)
                        {
                            var    pluginService = ServiceLocator.Current.GetInstance <IPluginService>();
                            Plugin pluginEntity  = pluginService.FindPluginByIdentifier(plugin.Identifier);
                            foreach (long appliedMigration in appliedMigrations)
                            {
                                Migration migration = new Migration
                                {
                                    Plugin  = pluginEntity,
                                    Version = appliedMigration
                                };
                                migrationService.Save(migration);
                            }
                        }
                    }
                }
            }
        }