Beispiel #1
0
        public void GivenNoRegisteredMigrations_ThenPlanIsReturned()
        {
            PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
            var registeredMigrations       = new Dictionary <string, string>();
            IReadOnlyList <string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);

            Assert.AreEqual(1, pending.Count);
        }
Beispiel #2
0
        public void GivenRegisteredMigration_WhenStepIsDifferentCase_ThenPlanIsReturned()
        {
            PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
            var registeredMigrations = new Dictionary <string, string>
            {
                [Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step1.ToString().ToUpper()
            };
            IReadOnlyList <string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);

            Assert.AreEqual(1, pending.Count);
        }
Beispiel #3
0
        public void GivenRegisteredMigration_WhenFinalStepMatched_ThenNoneAreReturned()
        {
            PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
            var registeredMigrations = new Dictionary <string, string>
            {
                [Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step2.ToString()
            };
            IReadOnlyList <string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);

            Assert.AreEqual(0, pending.Count);
        }
Beispiel #4
0
        /// <summary>
        /// Runs all migration plans for a package name if any are pending.
        /// </summary>
        /// <param name="packageName"></param>
        /// <returns></returns>
        public IEnumerable <ExecutedMigrationPlan> RunPackageMigrationsIfPending(string packageName)
        {
            IReadOnlyDictionary <string, string?>?keyValues = _keyValueService.FindByKeyPrefix(Constants.Conventions.Migrations.KeyValuePrefix);
            IReadOnlyList <string> pendingMigrations        = _pendingPackageMigrations.GetPendingPackageMigrations(keyValues);

            IEnumerable <string> packagePlans = _packageMigrationPlans.Values
                                                .Where(x => x.PackageName.InvariantEquals(packageName))
                                                .Where(x => pendingMigrations.Contains(x.Name))
                                                .Select(x => x.Name);

            return(RunPackagePlans(packagePlans));
        }
        private UmbracoDatabaseState GetUmbracoDatabaseState(IUmbracoDatabaseFactory databaseFactory)
        {
            try
            {
                if (!TryDbConnect(databaseFactory))
                {
                    return(UmbracoDatabaseState.CannotConnect);
                }

                // no scope, no service - just directly accessing the database
                using (var database = databaseFactory.CreateDatabase())
                {
                    if (!database.IsUmbracoInstalled())
                    {
                        return(UmbracoDatabaseState.NotInstalled);
                    }

                    // Make ONE SQL call to determine Umbraco upgrade vs package migrations state.
                    // All will be prefixed with the same key.
                    IReadOnlyDictionary <string, string> keyValues = database.GetFromKeyValueTable(Constants.Conventions.Migrations.KeyValuePrefix);

                    // This could need both an upgrade AND package migrations to execute but
                    // we will process them one at a time, first the upgrade, then the package migrations.
                    if (DoesUmbracoRequireUpgrade(keyValues))
                    {
                        return(UmbracoDatabaseState.NeedsUpgrade);
                    }

                    IReadOnlyList <string> packagesRequiringMigration = _packageMigrationState.GetPendingPackageMigrations(keyValues);
                    if (packagesRequiringMigration.Count > 0)
                    {
                        _startupState[PendingPacakgeMigrationsStateKey] = packagesRequiringMigration;

                        return(UmbracoDatabaseState.NeedsPackageMigration);
                    }
                }

                return(UmbracoDatabaseState.Ok);
            }
            catch (Exception e)
            {
                // can connect to the database so cannot check the upgrade state... oops
                _logger.LogWarning(e, "Could not check the upgrade state.");

                // else it is bad enough that we want to throw
                Reason = RuntimeLevelReason.BootFailedCannotCheckUpgradeState;
                BootFailedException = new BootFailedException("Could not check the upgrade state.", e);
                throw BootFailedException;
            }
        }