public bool Execute()
        {
            var configurations = AubergineMigrationResolver.Current.Configurations;
            var pendingConfigs = GetRequiredConfigurations(configurations);

            // now run any of the migrations that haven't already been ran.
            foreach (var item in pendingConfigs)
            {
                try
                {
                    _logger.Info <AubergineInstallManager>("Running Config: {0} {1}",
                                                           () => item.Name, () => item.SortOrder);

                    item.Configuration.Add();
                    _configService.Add(item.Name, item.Key);
                }
                catch (Exception ex)
                {
                    _logger.Warn <AubergineInstallManager>("Migration Failed: {0} {1}",
                                                           () => item.Configuration.GetType().Name, () => ex.Message);
                }
            }

            // we fire a raise event, this is what something can safely use
            // to know all the aubergine bits are in place...
            Migrated.RaiseEvent(new EventArgs(), this);

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Executes the migrations against the database.
        /// </summary>
        /// <param name="database">The PetaPoco Database, which the migrations will be run against</param>
        /// <param name="databaseProvider"></param>
        /// <param name="isUpgrade">Boolean indicating whether this is an upgrade or downgrade</param>
        /// <returns><c>True</c> if migrations were applied, otherwise <c>False</c></returns>
        public bool Execute(Database database, DatabaseProviders databaseProvider, bool isUpgrade = true)
        {
            LogHelper.Info <MigrationRunner>("Initializing database migrations");

            var foundMigrations = MigrationResolver.Current.Migrations;

            var migrations = isUpgrade
                                 ? OrderedUpgradeMigrations(foundMigrations).ToList()
                                 : OrderedDowngradeMigrations(foundMigrations).ToList();

            if (Migrating.IsRaisedEventCancelled(new MigrationEventArgs(migrations, _configuredVersion, _targetVersion, true), this))
            {
                return(false);
            }

            //Loop through migrations to generate sql
            var context = new MigrationContext(databaseProvider, database);

            foreach (MigrationBase migration in migrations)
            {
                if (isUpgrade)
                {
                    migration.GetUpExpressions(context);
                    LogHelper.Info <MigrationRunner>(string.Format("Added UPGRADE migration '{0}' to context", migration.GetType().Name));
                }
                else
                {
                    migration.GetDownExpressions(context);
                    LogHelper.Info <MigrationRunner>(string.Format("Added DOWNGRADE migration '{0}' to context", migration.GetType().Name));
                }
            }

            //Transactional execution of the sql that was generated from the found migrations
            using (Transaction transaction = database.GetTransaction())
            {
                int i = 1;
                foreach (var expression in context.Expressions)
                {
                    var sql = expression.Process(database);
                    if (string.IsNullOrEmpty(sql))
                    {
                        i++;
                        continue;
                    }

                    LogHelper.Info <MigrationRunner>("Executing sql statement " + i + ": " + sql);
                    database.Execute(sql);
                    i++;
                }

                transaction.Complete();
            }

            Migrated.RaiseEvent(new MigrationEventArgs(migrations, context, _configuredVersion, _targetVersion, false), this);

            return(true);
        }
Beispiel #3
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Agent != null)
         {
             hashCode = hashCode * 59 + Agent.GetHashCode();
         }
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (UserId != null)
         {
             hashCode = hashCode * 59 + UserId.GetHashCode();
         }
         if (CreatedAt != null)
         {
             hashCode = hashCode * 59 + CreatedAt.GetHashCode();
         }
         if (LegacyProfile != null)
         {
             hashCode = hashCode * 59 + LegacyProfile.GetHashCode();
         }
         if (Suspended != null)
         {
             hashCode = hashCode * 59 + Suspended.GetHashCode();
         }
         if (Paid != null)
         {
             hashCode = hashCode * 59 + Paid.GetHashCode();
         }
         if (Migrated != null)
         {
             hashCode = hashCode * 59 + Migrated.GetHashCode();
         }
         if (Legacy != null)
         {
             hashCode = hashCode * 59 + Legacy.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Executes the migrations against the database.
        /// </summary>
        /// <param name="database">The PetaPoco Database, which the migrations will be run against</param>
        /// <param name="databaseProvider"></param>
        /// <param name="isUpgrade">Boolean indicating whether this is an upgrade or downgrade</param>
        /// <returns><c>True</c> if migrations were applied, otherwise <c>False</c></returns>
        public virtual bool Execute(Database database, DatabaseProviders databaseProvider, bool isUpgrade = true)
        {
            _logger.Info <MigrationRunner>("Initializing database migrations");

            var foundMigrations = FindMigrations();

            //filter all non-schema migrations
            var migrations = isUpgrade
                                 ? OrderedUpgradeMigrations(foundMigrations).ToList()
                                 : OrderedDowngradeMigrations(foundMigrations).ToList();


            if (Migrating.IsRaisedEventCancelled(new MigrationEventArgs(migrations, _currentVersion, _targetVersion, _productName, true), this))
            {
                _logger.Warn <MigrationRunner>("Migration was cancelled by an event");
                return(false);
            }

            //Loop through migrations to generate sql
            var migrationContext = InitializeMigrations(migrations, database, databaseProvider, isUpgrade);

            try
            {
                ExecuteMigrations(migrationContext, database);
            }
            catch (Exception ex)
            {
                //if this fails then the transaction will be rolled back, BUT if we are using MySql this is not the case,
                //since it does not support schema changes in a transaction, see: http://dev.mysql.com/doc/refman/5.0/en/implicit-commit.html
                //so in that case we have to downgrade
                if (databaseProvider == DatabaseProviders.MySql)
                {
                    throw new DataLossException(
                              "An error occurred running a schema migration but the changes could not be rolled back. Error: " + ex.Message + ". In some cases, it may be required that the database be restored to it's original state before running this upgrade process again.",
                              ex);
                }

                //continue throwing the exception
                throw;
            }

            Migrated.RaiseEvent(new MigrationEventArgs(migrations, migrationContext, _currentVersion, _targetVersion, _productName, false), this);

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Returns true if GameProfile instances are equal
        /// </summary>
        /// <param name="other">Instance of GameProfile to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(GameProfile other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Agent == other.Agent ||
                     Agent != null &&
                     Agent.Equals(other.Agent)
                     ) &&
                 (
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     UserId == other.UserId ||
                     UserId != null &&
                     UserId.Equals(other.UserId)
                 ) &&
                 (
                     CreatedAt == other.CreatedAt ||
                     CreatedAt != null &&
                     CreatedAt.Equals(other.CreatedAt)
                 ) &&
                 (
                     LegacyProfile == other.LegacyProfile ||
                     LegacyProfile != null &&
                     LegacyProfile.Equals(other.LegacyProfile)
                 ) &&
                 (
                     Suspended == other.Suspended ||
                     Suspended != null &&
                     Suspended.Equals(other.Suspended)
                 ) &&
                 (
                     Paid == other.Paid ||
                     Paid != null &&
                     Paid.Equals(other.Paid)
                 ) &&
                 (
                     Migrated == other.Migrated ||
                     Migrated != null &&
                     Migrated.Equals(other.Migrated)
                 ) &&
                 (
                     Legacy == other.Legacy ||
                     Legacy != null &&
                     Legacy.Equals(other.Legacy)
                 ));
        }