Factory for generating the up/down runners. `up` will update the schema table with its own version, `down` will update it with either the previous version in the migration definition (by numeric comparison).
966892
function runnerFactory(direction, migrations) {
      // Override the `execute` method for the migration helpers with a version
      // that queues the intended query and immediately moves on. in a migration
      // we want to handle the queries in parallel.
      helpers.execute = function execute(sql, callback) {
        function cb(callback) {
          QueryRunner.expecting--;
          return callback;
        }
        QueryRunner.expecting++;
        return QueryRunner.enqueue([sql, cb(callback)]);
      };

      return function runMigration(version, callback) {
        var key = lookup(version, migrations);

        if (!key) {
          var error = new Error('Could not find migration with the following lookup parameter: ' + _.quote(version));
          error.name = 'MigrationNotFound';
          return callback(error);
        }
        
        migrations[key][direction].bind(helpers)(helpers);
        QueryRunner.flush();
        QueryRunner.once('done', function (err) {
          // #TODO: pass back an error saying
          // - the version of the migration
          // - what went wrong
          // - exactly which query failed?
          if (err) return callback(err);
          var ver = (direction === 'up')
            ? key
            : previous(version, migrations);
          this.updateSchemaVersion(ver, callback);
        }.bind(this));

      };
    }
1018413
public function up()
	{
        // Add column "active" if NOT exist
        if (!Schema::hasColumn('pricelists', 'active')) {
            Schema::table('pricelists', function(Blueprint $table)
            {
                $table->boolean('active')->default(true);
            });
        }
	}
879674
def up(self, migration_id=None, fake=False):
        """"""
        if not self.check_directory():
            return

        for migration in self.get_migrations_to_up(migration_id):
            logger.info('Executing migration: %s' % migration.filename)

            migration_module = self.load_migration_file(migration.filename)
            if not fake:
                if hasattr(migration_module, 'up'):
                    migration_module.up(self.db)
                else:
                    logger.error('No up method on migration %s' % migration.filename)

            record = migration.as_dict()
            record['date'] = datetime.utcnow()
            self.collection.insert(record)
346339
def db_downgrade(version):
    """"""
    v1 = get_db_version()
    migrate_api.downgrade(url=db_url, repository=db_repo, version=version)
    v2 = get_db_version()

    if v1 == v2:
        print 'No changes made.'
    else:
        print 'Downgraded: %s ... %s' % (v1, v2)
84957
def upgrade():
    """"""
    op.create_table(
        'records_metadata',
        sa.Column('created', sa.DateTime(), nullable=False),
        sa.Column('updated', sa.DateTime(), nullable=False),
        sa.Column(
            'id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
        sa.Column('json', sqlalchemy_utils.JSONType().with_variant(
            sa.dialects.postgresql.JSON(
                none_as_null=True), 'postgresql',
        ), nullable=True),
        sa.Column('version_id', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_table(
        'records_metadata_version',
        sa.Column('created', sa.DateTime(),
                  autoincrement=False, nullable=True),
        sa.Column('updated', sa.DateTime(),
                  autoincrement=False, nullable=True),
        sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(),
                  autoincrement=False, nullable=False),
        sa.Column('json', sqlalchemy_utils.JSONType().with_variant(
            sa.dialects.postgresql.JSON(
                none_as_null=True), 'postgresql',
        ), autoincrement=False, nullable=True),
        sa.Column('version_id', sa.Integer(),
                  autoincrement=False, nullable=True),
        sa.Column('transaction_id', sa.BigInteger(),
                  autoincrement=False, nullable=False),
        sa.Column('end_transaction_id',
                  sa.BigInteger(), nullable=True),
        sa.Column('operation_type',
                  sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id')
    )
    op.create_index(
        op.f('ix_records_metadata_version_end_transaction_id'),
        'records_metadata_version', ['end_transaction_id'], unique=False
    )
    op.create_index(
        op.f('ix_records_metadata_version_operation_type'),
        'records_metadata_version', ['operation_type'], unique=False
    )
    op.create_index(
        op.f('ix_records_metadata_version_transaction_id'),
        'records_metadata_version', ['transaction_id'], unique=False
    )
553043
def _downgrade_v3(op):
    
    op.create_table(
        '_new_equities',
        sa.Column(
            'sid',
            sa.Integer,
            unique=True,
            nullable=False,
            primary_key=True,
        ),
        sa.Column('symbol', sa.Text),
        sa.Column('company_symbol', sa.Text),
        sa.Column('share_class_symbol', sa.Text),
        sa.Column('fuzzy_symbol', sa.Text),
        sa.Column('asset_name', sa.Text),
        sa.Column('start_date', sa.Integer, default=0, nullable=False),
        sa.Column('end_date', sa.Integer, nullable=False),
        sa.Column('first_traded', sa.Integer, nullable=False),
        sa.Column('auto_close_date', sa.Integer),
        sa.Column('exchange', sa.Text),
    )
    op.execute(
        """
        insert into _new_equities
        select * from equities
        where equities.first_traded is not null
        """,
    )
    op.drop_table('equities')
    op.rename_table('_new_equities', 'equities')
    # we need to make sure the indices have the proper names after the rename
    op.create_index(
        'ix_equities_company_symbol',
        'equities',
        ['company_symbol'],
    )
    op.create_index(
        'ix_equities_fuzzy_symbol',
        'equities',
        ['fuzzy_symbol'],
    )
1182817
public function up()
    {
        $this->down();
        Schema::create('tbl_defered_events', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('value')->nullable();
        });
    }
937968
public function migrateUp()
    {
        Schema::table('tddd_testers', function (Blueprint $table) {
            $table->dropColumn('require_tee');

            $table->dropColumn('require_script');

            $table->text('pipers');
        });
    }
702590
def db_upgrade(version=None):
    """"""
    v1 = get_db_version()
    migrate_api.upgrade(url=db_url, repository=db_repo, version=version)
    v2 = get_db_version()

    if v1 == v2:
        print 'Database already up-to-date.'
    else:
        print 'Upgraded: %s ... %s' % (v1, v2)
289756
def update_migration_info(direction)
      save, @verbose = @verbose, false

      create_migration_info_table_if_needed

      if direction.to_sym == :up
        execute("INSERT INTO #{migration_info_table} (#{migration_name_column}) VALUES (#{quoted_name})")
      elsif direction.to_sym == :down
        execute("DELETE FROM #{migration_info_table} WHERE #{migration_name_column} = #{quoted_name}")
      end
      @verbose = save
    end
154371
function runMigrations(db, currentVersion) {
  return new Promise((resolve, reject) => {
    const nextVersion = currentVersion + 1;

    if (!migrations[nextVersion]) {
      return resolve();
    }

    if (debug) {
      console.log('Migrating schema to v%d', nextVersion);
    }
    migrations[nextVersion](db)
      .then(() => {
        // write new schemaVersion file
        const json = JSON.stringify({ schemaVersion: nextVersion });
        fs.writeFile(schemaVersionFilePath, json, err => {
          if (err) {
            return reject(err);
          }
          resolve(runMigrations(db, nextVersion));
        });
      })
      .catch(reject);
  });
}
537493
public function migrateUp()
    {
        try {
            $this->builder->table(
                $this->table,
                function ($table) {
                    $table->string('value')->nullable()->change();
                }
            );
        } catch (\Exception $e) {
            dd($e->getMessage());
        }
    }
1324209
function(db, schema, is_version_change) {

    var action = is_version_change ? 'changing version' : 'setting version';

    var current_version = db.version ? parseInt(db.version, 10) : 0;
    var new_version = schema.isAutoVersion() ?
        is_version_change ? isNaN(current_version) ?
            1 : (current_version + 1) : current_version : schema.version;
    goog.log.fine(me.logger, dbname + ': ' + action + ' from ' +
        db.version + ' to ' + new_version);

    var executed = false;
    var updated_count = 0;

    /**
     * SQLTransactionCallback
     * @param {!SQLTransaction} tx transaction object.
     */
    var transaction_callback = function(tx) {
      // sniff current table info in the database.
      me.getSchema(function(existing_schema) {
        executed = true;
        for (var i = 0; i < schema.count(); i++) {
          var counter = function(ok) {
            if (ok) {
              updated_count++;
            }
          };
          var table_info = existing_schema.getStore(schema.store(i).getName());
          // hint to sniffed schema, so that some lost info are recovered.
          var hinted_store_schema = table_info ?
              table_info.hintForWebSql(schema.store(i)) : null;

          me.update_store_with_info_(tx, schema.store(i), counter,
              hinted_store_schema);
        }

        for (var j = 0; j < existing_schema.count(); j++) {
          var info_store = existing_schema.store(j);
          if (!schema.hasStore(info_store.getName())) {
            if (schema instanceof ydn.db.schema.EditableDatabase) {
              var edited_schema = schema;
              edited_schema.addStore(info_store);
            } else {
              var sqls = me.prepareDropTable_(info_store);
              for (var i = 0; i < sqls.length; i++) {
                var sql = sqls[i];
                goog.log.finer(me.logger, sql);
                tx.executeSql(sql, [],
                    function(tr) {
                      // ok
                    }, function(tx, e) {
                      throw e;
                    });
              }
            }
          }
        }

      }, tx, db);
    };

    /**
     * SQLVoidCallback
     */
    var success_callback = function() {
      var has_created = updated_count == schema.stores.length;
      if (!executed) {
        // success callback without actually executing
        goog.log.warning(me.logger, dbname + ': ' + action + ' voided.');
        //if (!me.df_sql_db_.hasFired()) { // FIXME: why need to check ?
        // this checking is necessary when browser prompt user,
        // this migration function run two times: one creating table
        // and one without creating table. How annoying ?
        // testing is in /test/test_multi_storage.html page.
      } else {
        var msg = '.';
        if (updated_count != schema.stores.length) {
          msg = ' but unexpected stores exists.';
        }
        goog.log.finest(me.logger, dbname + ':' + db.version + ' ready' + msg);
        setDb(db);
      }
    };

    /**
     * SQLTransactionErrorCallback
     * @param {SQLError} e error.
     */
    var error_callback = function(e) {
      goog.log.error(me.logger, 'SQLError ' + e + ' ' + e.code + '(' + e.message + ') ' +
          'while changing version from ' + db.version + ' to ' + new_version +
          ' on ' + dbname);
      if (ydn.db.con.WebSql.DEBUG) {
        goog.global.console.log(e);
      }
      throw e;
    };

    // db.transaction(transaction_callback, error_callback, success_callback);
    db.changeVersion(db.version, new_version + '', transaction_callback,
        error_callback, success_callback);

  }
676207
public function migrateUp()
    {
        Schema::create('tddd_projects', function (Blueprint $table) {
            $table->increments('id');

            $table->string('name');

            $table->string('path');

            $table->string('tests_path');

            $table->timestamps();
        });
    }
346806
def run_on_changes(paths)
      if paths.any? { |path| path.match(%r{^db/migrate/(\d+).+\.rb}) } || reset?
        migrations = paths.map { |path| Migration.new(path) }
        migrate(migrations)
      elsif paths.any? { |path| path.match(%r{^db/seeds\.rb$}) }
        seed_only
      end
    end
817349
def upgrade():
    """"""
    # Variant types:
    def created():
        """Return instance of a column."""
        return sa.Column(
            'created',
            sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
            nullable=False
        )

    def updated():
        """Return instance of a column."""
        return sa.Column(
            'updated',
            sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
            nullable=False
        )

    def uri():
        """Return instance of a column."""
        return sa.Column(
            'uri',
            sa.Text().with_variant(mysql.VARCHAR(255), 'mysql'),
            nullable=True
        )

    def key(nullable=True):
        """Return instance of a column."""
        return sa.Column(
            'key',
            sa.Text().with_variant(mysql.VARCHAR(255), 'mysql'),
            nullable=nullable
        )

    op.create_table(
        'files_files',
        created(),
        updated(),
        sa.Column(
            'id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        uri(),
        sa.Column('storage_class', sa.String(length=1), nullable=True),
        sa.Column('size', sa.BigInteger(), nullable=True),
        sa.Column('checksum', sa.String(length=255), nullable=True),
        sa.Column('readable', sa.Boolean(name='readable'), nullable=False),
        sa.Column('writable', sa.Boolean(name='writable'), nullable=False),
        sa.Column('last_check_at', sa.DateTime(), nullable=True),
        sa.Column('last_check', sa.Boolean(name='last_check'), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('uri')
    )
    op.create_table(
        'files_location',
        created(),
        updated(),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=20), nullable=False),
        sa.Column('uri', sa.String(length=255), nullable=False),
        sa.Column('default', sa.Boolean(name='default'), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('name')
    )
    op.create_table(
        'files_bucket',
        created(),
        updated(),
        sa.Column(
            'id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column('default_location', sa.Integer(), nullable=False),
        sa.Column(
            'default_storage_class',
            sa.String(length=1),
            nullable=False
        ),
        sa.Column('size', sa.BigInteger(), nullable=False),
        sa.Column('quota_size', sa.BigInteger(), nullable=True),
        sa.Column('max_file_size', sa.BigInteger(), nullable=True),
        sa.Column('locked', sa.Boolean(name='locked'), nullable=False),
        sa.Column('deleted', sa.Boolean(name='deleted'), nullable=False),
        sa.ForeignKeyConstraint(
            ['default_location'],
            [u'files_location.id'],
            ondelete='RESTRICT'),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_table(
        'files_buckettags',
        sa.Column(
            'bucket_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column('key', sa.String(length=255), nullable=False),
        sa.Column('value', sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(
            ['bucket_id'],
            [u'files_bucket.id'],
            ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('bucket_id', 'key')
    )
    op.create_table(
        'files_multipartobject',
        created(),
        updated(),
        sa.Column(
            'upload_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column(
            'bucket_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=True),
        key(),
        sa.Column(
            'file_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column('chunk_size', sa.Integer(), nullable=True),
        sa.Column('size', sa.BigInteger(), nullable=True),
        sa.Column('completed', sa.Boolean(name='completed'), nullable=False),
        sa.ForeignKeyConstraint(
            ['bucket_id'],
            [u'files_bucket.id'],
            ondelete='RESTRICT'),
        sa.ForeignKeyConstraint(
            ['file_id'],
            [u'files_files.id'],
            ondelete='RESTRICT'),
        sa.PrimaryKeyConstraint('upload_id'),
        sa.UniqueConstraint('upload_id', 'bucket_id', 'key', name='uix_item')
    )
    op.create_table(
        'files_object',
        created(),
        updated(),
        sa.Column(
            'bucket_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        key(nullable=False),
        sa.Column(
            'version_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column(
            'file_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=True),
        sa.Column(
            '_mimetype', sa.String(
                length=255), nullable=True),
        sa.Column('is_head', sa.Boolean(name='is_head'), nullable=False),
        sa.ForeignKeyConstraint(
            ['bucket_id'],
            [u'files_bucket.id'],
            ondelete='RESTRICT'),
        sa.ForeignKeyConstraint(
            ['file_id'],
            [u'files_files.id'],
            ondelete='RESTRICT'),
        sa.PrimaryKeyConstraint('bucket_id', 'key', 'version_id')
    )
    op.create_index(
        op.f('ix_files_object__mimetype'),
        'files_object',
        ['_mimetype'],
        unique=False
    )
    op.create_table(
        'files_multipartobject_part',
        created(),
        updated(),
        sa.Column(
            'upload_id',
            sqlalchemy_utils.types.uuid.UUIDType(),
            nullable=False),
        sa.Column(
            'part_number',
            sa.Integer(),
            autoincrement=False,
            nullable=False),
        sa.Column('checksum', sa.String(length=255), nullable=True),
        sa.ForeignKeyConstraint(
            ['upload_id'],
            [u'files_multipartobject.upload_id'],
            ondelete='RESTRICT'),
        sa.PrimaryKeyConstraint('upload_id', 'part_number')
    )
984783
def migrate_down!(level = nil)
      migrations.sort.reverse.each do |migration|
        if level.nil?
          migration.perform_down()
        else
          migration.perform_down() if migration.position > level.to_i
        end
      end
    end