Beispiel #1
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            var serviceContext = (ServiceContext)MerchelloContext.Current.Services;
            _resolver = new MigrationResolver(
                Logger.CreateWithDefaultLog4NetConfiguration(),
                PluginManager.Current.ResolveMerchelloMigrations());
        }
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info<CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current);

                    bool upgraded;
                    try
                    {
                        foreach (var m in migrations)
                        {
                            m.Up();
                        }

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error<CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }

                    //var entryService = ApplicationContext.Current.Services.MigrationEntryService;

                    //var runner = new MigrationRunner(
                    //    entryService,
                    //    _logger,
                    //    new SemVersion(MerchelloConfiguration.ConfigurationStatusVersion),
                    //    new SemVersion(MerchelloVersion.Current),
                    //    MerchelloConfiguration.MerchelloMigrationName);

                    //var upgraded = runner.Execute(database);

                    if (upgraded)
                    {
                        var migrationKey = this.EnsureMigrationKey(schemaResult);

                        var record = new MigrationRecord()
                                         {
                                             MigrationKey = migrationKey,
                                             CurrentVersion = dbVersion.ToString(),
                                             TargetVersion = MerchelloVersion.Current.ToString(),
                                             DbProvider = database.GetDatabaseProvider().ToString(),
                                             InstallDate = DateTime.Now,
                                             IsUpgrade = true
                                         };

                        this.OnUpgraded(record);

                        _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully");
                    }

                    _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }
            else
            {
                    // this is a new install
                    var migrationKey = this.EnsureMigrationKey(schemaResult);

                    var record = new MigrationRecord()
                                     {
                                         MigrationKey = migrationKey,
                                         CurrentVersion = MerchelloConfiguration.ConfigurationStatus,
                                         TargetVersion = MerchelloVersion.Current.ToString(),
                                         DbProvider = database.GetDatabaseProvider().ToString(),
                                         InstallDate = DateTime.Now,
                                         IsUpgrade = !MerchelloConfiguration.ConfigurationStatus.Equals("0.0.0")
                                     };
                    this.OnUpgraded(record);
            }

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return true;
        }
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult           = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            var upgraded = false;

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info <CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current).ToList();

                    var context = InitializeMigrations(migrations, _database, _database.GetDatabaseProvider());

                    try
                    {
                        ExecuteMigrations(context, _database);

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error <CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }


                    _logger.Debug <CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error <CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }

            var currentVersion = dbVersion.ToString();

            if (!upgraded)
            {
                currentVersion = MerchelloConfiguration.ConfigurationStatusVersion.ToString();
            }

            var migrationKey = this.EnsureMigrationKey(schemaResult);

            var record = new MigrationRecord()
            {
                MigrationKey   = migrationKey,
                CurrentVersion = currentVersion,
                TargetVersion  = MerchelloVersion.Current.ToString(),
                DbProvider     = database.GetDatabaseProvider().ToString(),
                InstallDate    = DateTime.Now,
                IsUpgrade      = currentVersion != "0.0.0"
            };

            this.OnUpgraded(record);

            _logger.Info <CoreMigrationManager>("Merchello Schema Migration completed successfully");

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return(true);
        }
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            var upgraded = false;

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info<CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current).ToList();

                    var context = InitializeMigrations(migrations, _database, _database.GetDatabaseProvider());

                    try
                    {
                        ExecuteMigrations(context, _database);

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error<CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }

                    _logger.Debug<CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error<CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }

            var currentVersion = dbVersion.ToString();

            if (!upgraded)
            {
                currentVersion = MerchelloConfiguration.ConfigurationStatusVersion.ToString();
            }

            var migrationKey = this.EnsureMigrationKey(schemaResult);

            var record = new MigrationRecord()
            {
                MigrationKey = migrationKey,
                CurrentVersion = currentVersion,
                TargetVersion = MerchelloVersion.Current.ToString(),
                DbProvider = database.GetDatabaseProvider().ToString(),
                InstallDate = DateTime.Now,
                IsUpgrade = currentVersion != "0.0.0"
            };

            this.OnUpgraded(record);

            _logger.Info<CoreMigrationManager>("Merchello Schema Migration completed successfully");

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return true;
        }
Beispiel #5
0
        /// <summary>
        /// Executes the Migration runner.
        /// </summary>
        /// <param name="database">
        /// The database.
        /// </param>
        /// <returns>
        /// A value indicating whether or not the migration was successful.
        /// </returns>
        private bool UpgradeMerchello(Database database)
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult           = databaseSchemaCreation.ValidateSchema();
            var dbVersion = schemaResult.DetermineInstalledVersion();

            if (dbVersion != MerchelloVersion.Current)
            {
                try
                {
                    _logger.Info <CoreMigrationManager>("Merchello database upgraded required.  Initializing Upgrade.");

                    var resolver = new MigrationResolver(_logger, PluginManager.Current.ResolveMerchelloMigrations());

                    var migrations = resolver.OrderedUpgradeMigrations(
                        MerchelloConfiguration.ConfigurationStatusVersion,
                        MerchelloVersion.Current);

                    bool upgraded;
                    try
                    {
                        foreach (var m in migrations)
                        {
                            m.Up();
                        }

                        upgraded = true;
                    }
                    catch (Exception ex)
                    {
                        _logger.Error <CoreMigrationManager>("Merchello migration failed", ex);
                        upgraded = false;
                    }


                    //var entryService = ApplicationContext.Current.Services.MigrationEntryService;


                    //var runner = new MigrationRunner(
                    //    entryService,
                    //    _logger,
                    //    new SemVersion(MerchelloConfiguration.ConfigurationStatusVersion),
                    //    new SemVersion(MerchelloVersion.Current),
                    //    MerchelloConfiguration.MerchelloMigrationName);

                    //var upgraded = runner.Execute(database);

                    if (upgraded)
                    {
                        var migrationKey = this.EnsureMigrationKey(schemaResult);

                        var record = new MigrationRecord()
                        {
                            MigrationKey   = migrationKey,
                            CurrentVersion = dbVersion.ToString(),
                            TargetVersion  = MerchelloVersion.Current.ToString(),
                            DbProvider     = database.GetDatabaseProvider().ToString(),
                            InstallDate    = DateTime.Now,
                            IsUpgrade      = true
                        };

                        this.OnUpgraded(record);

                        _logger.Info <CoreMigrationManager>("Merchello Schema Migration completed successfully");
                    }

                    _logger.Debug <CoreMigrationManager>("Merchello migration runner returned false.");
                }
                catch (Exception ex)
                {
                    _logger.Error <CoreMigrationManager>("Merchello Database Schema Upgrade Failed", ex);
                    throw;
                }
            }
            else
            {
                // this is a new install
                var migrationKey = this.EnsureMigrationKey(schemaResult);

                var record = new MigrationRecord()
                {
                    MigrationKey   = migrationKey,
                    CurrentVersion = MerchelloConfiguration.ConfigurationStatus,
                    TargetVersion  = MerchelloVersion.Current.ToString(),
                    DbProvider     = database.GetDatabaseProvider().ToString(),
                    InstallDate    = DateTime.Now,
                    IsUpgrade      = !MerchelloConfiguration.ConfigurationStatus.Equals("0.0.0")
                };
                this.OnUpgraded(record);
            }

            MerchelloConfiguration.ConfigurationStatus = MerchelloVersion.Current.ToString();

            return(true);
        }