Ejemplo n.º 1
0
        /// <summary>
        /// Performs the migrations from after the start version up to and
        /// including the end version.  Updates the stored version
        /// number to the end version number specified.
        /// </summary>
        /// <param name="startAfterVersion">The start version (exclusive)</param>
        /// <param name="endVersion">The end version (inclusive)</param>
        public void Migrate(int startAfterVersion, int endVersion)
        {
            //Each migration should be done separately because changes to DDL does not support rollback.
            var stepsToRun = endVersion - startAfterVersion;

            startAfterVersion++;
            if (stepsToRun > 0 && this.OnDbMigrationStarted != null)
            {
                this.OnDbMigrationStarted(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)startAfterVersion, (uint)endVersion));
            }
            for (int i = startAfterVersion; i <= endVersion; i++)
            {
                try
                {
                    _connection.ExecuteSql(GetMigrationSql(i - 1, i).ToArray());
                }
                catch (Exception ex)
                {
                    if (this.OnDbMigrationException != null)
                    {
                        this.OnDbMigrationException(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)i, (uint)endVersion));
                    }
                    throw ex;
                }
                SetCurrentVersion(i);
                if (this.OnDbMigrationProgress != null)
                {
                    this.OnDbMigrationProgress(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)i, (uint)endVersion));
                }
            }
            if (stepsToRun > 0 && this.OnDbMigrationCompleted != null)
            {
                this.OnDbMigrationCompleted(this, new DBMigratorEventArgs((uint)startAfterVersion, (uint)endVersion, (uint)endVersion));
            }
        }
Ejemplo n.º 2
0
 private void Apply()
 {
     _databaseConnection.ExecuteSql(
         from statement in _statements
         select new SqlStatement(_databaseConnection, statement)
         );
 }
Ejemplo n.º 3
0
        public void DoWork()
        {
            // note that the connection oject is
            // whatever the factory provides
            IDatabaseConnection dbConnection = this.dbConnectionFactory.GetDatabaseConnection();

            // format the sql
            string sql = "UPDATE something";

            // execute it
            dbConnection.ExecuteSql(sql);
        }