public override void Can_Upgrade_From_470_To_600()
        {
            var configuredVersion = new Version("4.11.0");
            var targetVersion = new Version("6.0.0");
            var provider = GetDatabaseProvider();
            var db = GetConfiguredDatabase();

            var fix = new PublishAfterUpgradeToVersionSixth();

            //Setup the MigrationRunner
            var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
            bool upgraded = migrationRunner.Execute(db, provider, true);

            Assert.That(upgraded, Is.True);

            bool hasTabTable = db.TableExist("cmsTab");
            bool hasPropertyTypeGroupTable = db.TableExist("cmsPropertyTypeGroup");
            bool hasAppTreeTable = db.TableExist("umbracoAppTree");

            fix.Unsubscribe();

            Assert.That(hasTabTable, Is.False);
            Assert.That(hasPropertyTypeGroupTable, Is.True);
            Assert.That(hasAppTreeTable, Is.False);
        }
        private static void HandleMigrations()
        {
            const string productName = "Redirects";
            var currentVersion = new SemVersion(0, 0, 0);

            // get all migrations for "Statistics" already executed
            var migrations = ApplicationContext.Current.Services.MigrationEntryService.GetAll(productName);

            // get the latest migration for "Statistics" executed
            var latestMigration = migrations.OrderByDescending(x => x.Version).FirstOrDefault();

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

            var targetVersion = new SemVersion(1, 0, 1);
            if (targetVersion == currentVersion)
                return;

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

            try
            {
                migrationsRunner.Execute(UmbracoContext.Current.Application.DatabaseContext.Database);
            }
            catch (HttpException e){}
            catch (Exception e)
            {
                LogHelper.Error<MigrationRunner>("Error running Redirects migration", e);
            }
        }
예제 #3
0
        public virtual void Can_Upgrade_From_470_To_600()
        {
            var configuredVersion = new Version("4.7.0");
            var targetVersion = new Version("6.0.0");
            var provider = GetDatabaseProvider();
            var db = GetConfiguredDatabase();

            //Create db schema and data from old Total.sql file for Sql Ce
            string statements = GetDatabaseSpecificSqlScript();
            // replace block comments by whitespace
            statements = FindComments.Replace(statements, " ");
            // execute all non-empty statements
            foreach (string statement in statements.Split(";".ToCharArray()))
            {
                string rawStatement = statement.Replace("GO", "").Trim();
                if (rawStatement.Length > 0)
                    db.Execute(new Sql(rawStatement));
            }

            //Setup the MigrationRunner
            var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
            bool upgraded = migrationRunner.Execute(db, provider, true);

            Assert.That(upgraded, Is.True);

            bool hasTabTable = db.TableExist("cmsTab");
            bool hasPropertyTypeGroupTable = db.TableExist("cmsPropertyTypeGroup");
            bool hasAppTreeTable = db.TableExist("umbracoAppTree");

            Assert.That(hasTabTable, Is.False);
            Assert.That(hasPropertyTypeGroupTable, Is.True);
            Assert.That(hasAppTreeTable, Is.False);
        }
예제 #4
0
 private void RunMigrations()
 {
     try
     {
         var runner = new MigrationRunner(this.oldVersion, this.newVersion, "UpdateEventCalendarTables");
         var upgraded = runner.Execute(this._db, true);
         LogHelper.Info<installer>("Done doing migration for version " + this.newVersion.ToString());
     }
     catch (Exception ex) { LogHelper.Error<installer>("Failed to do the migration for a version", ex); }
 }
        void MigrationRunner_Migrated(MigrationRunner sender, Core.Events.MigrationEventArgs e)
        {
            var target = new Version(6, 0, 0);
            if (e.ConfiguredVersion < target)
            {
                var sql = new Sql();
                sql.Select("*")
                    .From<DocumentDto>()
                    .InnerJoin<ContentVersionDto>()
                    .On<DocumentDto, ContentVersionDto>(left => left.VersionId, right => right.VersionId)
                    .InnerJoin<ContentDto>()
                    .On<ContentVersionDto, ContentDto>(left => left.NodeId, right => right.NodeId)
                    .InnerJoin<NodeDto>()
                    .On<ContentDto, NodeDto>(left => left.NodeId, right => right.NodeId)
                    .Where<NodeDto>(x => x.NodeObjectType == new Guid(Constants.ObjectTypes.Document))
                    .Where<NodeDto>(x => x.Path.StartsWith("-1"));

                var uow = PetaPocoUnitOfWorkProvider.CreateUnitOfWork();

                var dtos = uow.Database.Fetch<DocumentDto, ContentVersionDto, ContentDto, NodeDto>(sql);
                var toUpdate = new List<DocumentDto>();
                var versionGroup = dtos.GroupBy(x => x.NodeId);
                foreach (var grp in versionGroup)
                {
                    var published = grp.FirstOrDefault(x => x.Published);
                    var newest = grp.FirstOrDefault(x => x.Newest);

                    if (newest != null)
                    {
                        double timeDiff = new TimeSpan(newest.UpdateDate.Ticks - newest.ContentVersionDto.VersionDate.Ticks).TotalMilliseconds;
                        var hasPendingChanges = timeDiff > 2000;

                        if (hasPendingChanges == false && published != null)
                        {
                            published.Published = false;
                            toUpdate.Add(published);
                            newest.Published = true;
                            toUpdate.Add(newest);
                        }
                    }
                }

                //Commit the updated entries for the cmsDocument table
                using (var transaction = uow.Database.GetTransaction())
                {
                    //Loop through the toUpdate
                    foreach (var dto in toUpdate)
                    {
                        uow.Database.Update(dto);
                    }

                    transaction.Complete();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Determines if the database schema needs to be upgraded with a version update
        /// </summary>
        internal static bool VerifyDatabaseSchema(Database database)
        {
            if (!MerchelloConfiguration.Current.AutoUpdateDbSchema) return true;

            // Check if merchello has been upgraded
            if (MerchelloConfiguration.ConfigurationStatus == MerchelloVersion.Current.ToString()) return true;

            LogHelper.Info<CoreBootManager>("Beginning Merchello DB Schema Upgrade");

            // 1.0.1 was Merchello's first public release
            var configVersion = String.IsNullOrEmpty(MerchelloConfiguration.ConfigurationStatus)
                ? "1.0.1"
                : MerchelloConfiguration.ConfigurationStatus;

            var currentVersion = new Version(configVersion);
            var targetVersion = MerchelloVersion.Current;

            var isUpgrage = IsUpgrade(currentVersion, targetVersion);

            var migration = new MigrationRunner(currentVersion, MerchelloVersion.Current, MerchelloConfiguration.MerchelloMigrationName);

            if (migration.Execute(database, isUpgrage))
            {
                try
                {
                    // update the web.config merchelloConfigurationVersion
                    var config = WebConfigurationManager.OpenWebConfiguration("~");
                    config.AppSettings.Settings["merchelloConfigurationStatus"].Value = MerchelloVersion.Current.ToString();

                    config.Save(ConfigurationSaveMode.Modified);
                }
                catch (Exception ex)
                {
                    LogHelper.Error<CoreBootManager>("Failed to update 'merchelloConfigurationStatus' AppSetting", ex);
                    return false;
                }
            }

            LogHelper.Info<CoreBootManager>("Finished Merchello DB Schema Upgrade");

            return true;
        }
        void MigrationRunner_Migrated(MigrationRunner sender, Core.Events.MigrationEventArgs e)
        {
            var target70 = new Version(7, 0, 0);

            if (e.ConfiguredVersion <= target70)
            {
                

                var sql = @"DELETE FROM cmsContentXml WHERE nodeId IN
    (SELECT DISTINCT cmsContentXml.nodeId FROM cmsContentXml 
        INNER JOIN umbracoNode ON cmsContentXml.nodeId = umbracoNode.id
        WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND " + SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("path") + " like '%-21%')";

                var count = e.MigrationContext.Database.Execute(sql);

                LogHelper.Info<ClearMediaXmlCacheForDeletedItemsAfterUpgrade>("Cleared " + count + " items from the media xml cache that were trashed and not meant to be there");

            }

        }
        public void Can_Find_Targetted_Migrations()
        {
            var configuredVersion = new Version("4.8.0");
            var targetVersion = new Version("6.0.0");
	        var foundMigrations = MigrationResolver.Current.Migrations;

            var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
            var migrations = migrationRunner.OrderedUpgradeMigrations(foundMigrations).ToList();

            var context = new MigrationContext(DatabaseProviders.SqlServerCE, null);
            foreach (MigrationBase migration in migrations)
            {
                migration.GetUpExpressions(context);
            }

            foreach (var expression in context.Expressions)
            {
                Console.WriteLine(expression.ToString());
            }

            Assert.That(migrations.Count(), Is.EqualTo(12));
        }
예제 #9
0
        internal Result CreateDatabaseSchemaAndDataOrUpgrade()
        {
            if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName)))
            {
                return new Result
                           {
                               Message =
                                   "Database configuration is invalid. Please check that the entered database exists and that the provided username and password has write access to the database.",
                               Success = false,
                               Percentage = "10"
                           };
            }

            try
            {
                LogHelper.Info<DatabaseContext>("Database configuration status: Started");

                var message = string.Empty;

                var database = new UmbracoDatabase(_connectionString, ProviderName);
                var supportsCaseInsensitiveQueries = SqlSyntaxContext.SqlSyntaxProvider.SupportsCaseInsensitiveQueries(database);
                if (supportsCaseInsensitiveQueries  == false)
                {
                    message = "<p>&nbsp;</p><p>The database you're trying to use does not support case insensitive queries. <br />We currently do not support these types of databases.</p>" +
                              "<p>You can fix this by changing the following two settings in your my.ini file in your MySQL installation directory:</p>" +
                              "<pre>lower_case_table_names=1\nlower_case_file_system=1</pre><br />" +
                              "<p>Note: Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                              "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                              "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";

                    return new Result { Message = message, Success = false, Percentage = "15" };
                }
                else if (supportsCaseInsensitiveQueries == null)
                {
                    message = "<p>&nbsp;</p><p>Warning! Could not check if your database type supports case insensitive queries. <br />We currently do not support these databases that do not support case insensitive queries.</p>" +
                              "<p>You can check this by looking for the following two settings in your my.ini file in your MySQL installation directory:</p>" +
                              "<pre>lower_case_table_names=1\nlower_case_file_system=1</pre><br />" +
                              "<p>Note: Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                              "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                              "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";
                }
                else
                {
                    if (SqlSyntaxContext.SqlSyntaxProvider.GetType() == typeof(MySqlSyntaxProvider))
                    {
                        message = "<p>&nbsp;</p><p>Congratulations, the database step ran successfully!</p>" +
                                  "<p>Note: You're using MySQL and the database instance you're connecting to seems to support case insensitive queries.</p>" +
                                  "<p>However, your hosting provider may not support this option. Umbraco does not currently support MySQL installs that do not support case insensitive queries</p>" +
                                  "<p>Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                                  "<p>They can check this by looking for the following two settings in the my.ini file in their MySQL installation directory:</p>" +
                                  "<pre>lower_case_table_names=1\nlower_case_file_system=1</pre><br />" +
                                  "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                                  "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";
                    }
                }

                var schemaResult = ValidateDatabaseSchema();
                var installedVersion = schemaResult.DetermineInstalledVersion();
                

                //If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing
                if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedVersion.Equals(new Version(0, 0, 0)))
                {
                    database.CreateDatabaseSchema();
                    message = message + "<p>Installation completed!</p>";
                }
                else
                {
                    var configuredVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus)
                                                ? installedVersion
                                                : new Version(GlobalSettings.ConfigurationStatus);
                    var targetVersion = UmbracoVersion.Current;
                    var runner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
                    var upgraded = runner.Execute(database, true);
                    message = message + "<p>Upgrade completed!</p>";
                }

                LogHelper.Info<DatabaseContext>("Database configuration status: " + message);

                return new Result { Message = message, Success = true, Percentage = "100" };
            }
            catch (Exception ex)
            {
                LogHelper.Info<DatabaseContext>("Database configuration failed with the following error and stack trace: " + ex.Message + "\n" + ex.StackTrace);

                if (_result != null)
                {
                    LogHelper.Info<DatabaseContext>("The database schema validation produced the following summary: \n" + _result.GetSummary());
                }

                return new Result
                           {
                               Message =
                                   "The database configuration failed with the following message: " + ex.Message +
                                   "\n Please check log file for additional information (can be found in '/App_Data/Logs/UmbracoTraceLog.txt')",
                               Success = false,
                               Percentage = "90"
                           };
            }
        }
예제 #10
0
        /// <summary>
        /// This assumes all of the previous checks are done!
        /// </summary>
        /// <returns></returns>
        internal Result UpgradeSchemaAndData()
        {
            var readyForInstall = CheckReadyForInstall();
            if (readyForInstall.Success == false)
            {
                return readyForInstall.Result;
            }

            try
            {
                LogHelper.Info<DatabaseContext>("Database upgrade started");

                var database = new UmbracoDatabase(_connectionString, ProviderName);
                var supportsCaseInsensitiveQueries = SqlSyntaxContext.SqlSyntaxProvider.SupportsCaseInsensitiveQueries(database);                

                var message = GetResultMessageForMySql(supportsCaseInsensitiveQueries);

                var schemaResult = ValidateDatabaseSchema();
                var installedVersion = schemaResult.DetermineInstalledVersion();
                
                //DO the upgrade!

                var configuredVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus)
                                                ? installedVersion
                                                : new Version(GlobalSettings.ConfigurationStatus);
                var targetVersion = UmbracoVersion.Current;
                var runner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
                var upgraded = runner.Execute(database, true);
                message = message + "<p>Upgrade completed!</p>";

                //now that everything is done, we need to determine the version of SQL server that is executing

                LogHelper.Info<DatabaseContext>("Database configuration status: " + message);

                return new Result { Message = message, Success = true, Percentage = "100" };
            }
            catch (Exception ex)
            {
                return HandleInstallException(ex);
            }
        }