Пример #1
0
        private static void DoMigration()
        {
            var currentVersion = new SemVersion(0);

            IEnumerable <IMigrationEntry> migrations = ApplicationContext.Current.Services.MigrationEntryService.GetAll(MagicStrings.Name);
            IMigrationEntry latest = migrations.OrderByDescending(x => x.Version).FirstOrDefault();

            if (null != latest)
            {
                currentVersion = latest.Version;
            }

            var targetVersion = new SemVersion(0, 8);

            if (targetVersion == currentVersion)
            {
                return;
            }

            var migrationsRunner = new MigrationRunner(
                ApplicationContext.Current.Services.MigrationEntryService,
                ApplicationContext.Current.ProfilingLogger.Logger,
                currentVersion,
                targetVersion,
                MagicStrings.Name);

            try
            {
                migrationsRunner.Execute(UmbracoContext.Current.Application.DatabaseContext.Database);
            }
            catch (Exception ex)
            {
                LogHelper.Error <Migration>("Error running Plumber migration", ex);
            }
        }
Пример #2
0
        public MigrationDto BuildDto(IMigrationEntry entity)
        {
            var dto = new MigrationDto
            {
                CreateDate = entity.CreateDate,
                Name       = entity.MigrationName,
                Version    = entity.Version.ToString()
            };

            if (entity.HasIdentity)
            {
                dto.Id = entity.Id;
            }

            return(dto);
        }
Пример #3
0
        private static void HandleStatisticsMigration()
        {
            // Declare an initial version (will be used as fallback fro new install)
            SemVersion currentVersion = new SemVersion(0);

            // Get all migrations for "Skybrud.Redirects" already executed
            IEnumerable <IMigrationEntry> migrations = ApplicationContext.Current.Services.MigrationEntryService.GetAll(Package.Alias);

            // Get the latest migration for "Skybrud.Redirects" executed
            IMigrationEntry latestMigration = migrations.OrderByDescending(x => x.Version).FirstOrDefault();

            if (latestMigration != null)
            {
                currentVersion = latestMigration.Version;
            }

            // Get the target version (and return if already up-to-date)
            SemVersion targetVersion = Package.SemVersion;

            if (targetVersion == currentVersion)
            {
                return;
            }

            // Initialize a new migration runner for our package
            MigrationRunner migrationsRunner = new MigrationRunner(
                ApplicationContext.Current.Services.MigrationEntryService,
                ApplicationContext.Current.ProfilingLogger.Logger,
                currentVersion,
                targetVersion,
                Package.Alias
                );

            try {
                migrationsRunner.Execute(UmbracoContext.Current.Application.DatabaseContext.Database);
            } catch (Exception e) {
                LogHelper.Error <MigrationEvents>("Error running " + Package.Alias + " migration", e);
            }
        }