Execute and record a migration
978657
def execute_migration(plugin, filename, script, dryrun=False):
    ''''''
    db = get_db()
    js = SCRIPT_WRAPPER.format(script)
    lines = script.splitlines()
    success = True
    if not dryrun:
        try:
            lines = db.eval(js, plugin, filename, script)
        except OperationFailure as e:
            log.error(e.details['errmsg'].replace('\n', '\\n'))
            success = False
        except PyMongoError as e:
            log.error('Unable to apply migration: %s', str(e))
            success = False
    echo('│'.encode('utf8'))
    for line in lines:
        echo('│ {0}'.format(line).encode('utf8'))
    echo('│'.encode('utf8'))
    echo('└──[{0}]'.format(green('OK') if success else red('KO')).encode('utf8'))
    echo('')
    return success
808527
async function migrate (direction) {
  let config = require(path.join(process.cwd(), '.', 'config'))
  let db = require(path.join(process.cwd(), '.', 'db'))

  if (direction === 'up') {
    await db.migrate.latest(config.db)
  } else if (direction === 'down') {
    await db.migrate.rollback(config.db)
  } else {
    cli.showHelp(0)
  }

  process.exit(0)
}
349908
def _pretend_to_run(self, migration, method):
        
        for query in self._get_queries(migration, method):
            name = migration.__class__.__name__

            self._note('<info>%s:</info> <comment>%s</comment>' % (name, query))
401369
def migrate(app_name=None, revision=None):
    ""
    cmd = ['python bin/manage.py syncdb --migrate']
    if app_name:
        cmd.append(app_name)
        if revision:
            cmd.append(revision)
    verun(' '.join(cmd))
488754
public function migrate()
    {
        $fs = new Filesystem;
        $finder = new ClassFinder;
        $path = env('MIGRATIONS_PATH', 'database/migrations');

        if ($fs->exists($path)) {
            foreach ($fs->files($path) as $file) {
                $fs->requireOnce($file);
                $class = $finder->findClass($file);

                (new $class)->up();
            }
        }
    }
118805
function performMigration(direction, migrateTo, next) {
		if (!next &&
	    Object.prototype.toString.call(migrateTo) === '[object Function]') {
	    next = migrateTo;
	    migrateTo = undefined;
	  }

		if (!next) {
			next = function(err) {
				if (err) {
					console.error(err);
					process.exit(1);
				} else {
					process.exit();
				}
			}
		}

		var db = require('./lib/db');
		db.getConnection(dbConfig || require(process.cwd() + path.sep + configFileName)[dbProperty], function (err, db) {
			if (err) {
				return next(new verror.WError(err, 'Error connecting to database'));
			}
			var migrationCollection = db.migrationCollection,
					dbConnection = db.connection;

			migrationCollection.find({}).sort({num: -1}).limit(1).toArray(function (err, migrationsRun) {
				if (err) {
					return next(new verror.WError(err, 'Error querying migration collection'));
				}

				var lastMigration = migrationsRun[0],
					lastMigrationNum = lastMigration ? lastMigration.num : 0;

				migrate({
					migrationTitle: 'migrations/.migrate',
					db: dbConnection,
					migrationCollection: migrationCollection
				});
				migrations(direction, lastMigrationNum, migrateTo).forEach(function(path){
					var mod = require(process.cwd() + '/' + path);
					migrate({
						num: parseInt(path.split('/')[1].match(/^(\d+)/)[0], 10),
						title: path,
						up: mod.up,
						down: mod.down});
				});

				//Revert working directory to previous state
				process.chdir(previousWorkingDirectory);

				var set = migrate();

				set.on('migration', function(migration, direction){
					log(direction, migration.title);
				});

				set.on('save', function(){
					log('migration', 'complete');
					return next();
				});

				set[direction](null, lastMigrationNum);
			});
		});
	}
1187239
public function runMigrations()
	{
		$migrations = Model::where('status', 'pending');

		if ($migrations->get()->size() > 0) {
			foreach($migrations->get()->all() as $migration) {
				$this->runSingleMigration($migration);
			}
		}
	}
1254820
def migrate(ctx, start_version, end_version):
    """"""
    if ctx.type == 'file':
        if ctx.data_file:
            file_path = ctx.data_file
        else:
            file_path = os.path.join(ctx.data_file, ctx.namespace + '.json')

        # todo make this more like alemebic and determine/load versions automatically
        with open(file_path, 'r') as f:
            data = json.loads(f.read())

        data = run_migration(data, start_version, end_version)
        with open(file_path, 'w') as f:
            f.write(json.dumps(data))
867621
def execute_migrations(self, show_traceback=True):
        
        all_migrations = get_pending_migrations(self.path, self.databases)
        
        if not len(all_migrations):
            sys.stdout.write("There are no migrations to apply.\n")
        
        for db, migrations in all_migrations.iteritems():
            connection = connections[db]
            
            # init connection
            cursor = connection.cursor()
            cursor.close()
                        
            for migration in migrations:
                migration_path = self._get_migration_path(db, migration)
                
                with Transactional():
                    sys.stdout.write(
                        "Executing migration %r on %r...." %
                        (migration, db)
                    )
                    created_models = self._execute_migration(
                        db,
                        migration_path,
                        show_traceback=show_traceback
                    )

                    emit_post_sync_signal(
                        created_models=created_models,
                        verbosity=self.verbosity,
                        interactive=self.interactive,
                        db=db,
                    )
            
            if self.load_initial_data:
                sys.stdout.write(
                    "Running loaddata for initial_data fixtures on %r.\n" % db
                )
                call_command(
                    "loaddata",
                    "initial_data",
                    verbosity=self.verbosity,
                    database=db,
                )
1226887
protected function recordMigration(AbstractMigration $migration)
    {
        $query = 'INSERT INTO `app_migrations` (`timestamp`, `description`) VALUES ("%s", "%s")';
        $query = sprintf($query, $migration->getTimestamp(), $migration->getDescription());

        $this->db->query($query, DbAdapter::QUERY_MODE_EXECUTE);
    }
416719
def setup_migrate(app):
    """"""
    directory = path.join(path.dirname(__file__), 'migrations')
    migrate.init_app(app, db, directory=directory)
1335057
public function migrateUp()
    {
        $this->builder->create(
            $this->table,
            function ($table) {
                $table->bigIncrements('id');

                $table->string('sha1', 40)->index();
                $table->text('statement');
                $table->double('time')->index();
                $table->integer('connection_id')->unsigned();

                $table->timestamps();
                $table->index('created_at');
                $table->index('updated_at');
            }
        );
    }
530522
def migrate(self, conn):
        
        while self.should_migrate(conn):
            current_version = get_user_version(conn)
            migration = self._get_migration(current_version)
            assert migration.from_ver == current_version
            logger.info(f'Migrating database from {migration.from_ver}'
                        f' to {migration.to_ver}')
            self._migrate_single(conn, migration)
            set_user_version(conn, migration.to_ver)
            logger.info(f'Migrated database to {migration.to_ver}')
945587
public function migrate()
	{
		$table = 'fe_users';
		$column = 'siteid';

		$this->msg( sprintf( 'Adding "%1$s" column to "%2$s" table', $column, $table ), 0 );

		$schema = $this->getSchema( 'db-customer' );

		if( isset( $this->migrate[$schema->getName()] )
			&& $schema->tableExists( $table ) === true
			&& $schema->columnExists( $table, $column ) === false )
		{
			foreach ( $this->migrate[$schema->getName()] as $stmt )
			{
				$this->execute( $stmt );
			}
			$this->status( 'done' );
		}
		else
		{
			$this->status( 'OK' );
		}
	}
1227253
public function perform()
    {
        if (!$this->verifyConfigured() || !$this->verifyEnvironment()) {
            return;
        }

        $found = false;
        $count = $this->option('one') ? 1 : PHP_INT_MAX;

        while ($count > 0 && ($migration = $this->migrator->run())) {
            $found = true;
            $count--;

            $this->sprintf(
                "<info>Migration <comment>%s</comment> was successfully executed.</info>",
                $migration->getState()->getName()
            );
        }

        if (!$found) {
            $this->writeln("<fg=red>No outstanding migrations were found.</fg=red>");
        }
    }
1113414
def execute(self, conn, daoinput, transaction = False):
        
        #print daoinput['migration_block_id']
        if not conn:
	    dbsExceptionHandler("dbsException-failed-connect2host", "Oracle/MigrationBlock/Update. Expects db connection from upper layer." ,self.logger.exception)
        if daoinput['migration_status'] == 1:
           sql = self.sql + "  (MIGRATION_STATUS = 0  or MIGRATION_STATUS = 3)" 
        elif daoinput['migration_status'] == 2 or daoinput['migration_status'] == 3 or daoinput['migration_status'] == 9:
            sql = self.sql + " MIGRATION_STATUS = 1 "
        else: 
            dbsExceptionHandler("dbsException-conflict-data", "Oracle/MigrationBlock/Update. Expected migration status to be 1, 2, 3, 0r 9" ,self.logger.exception ) 
        #print sql
        if 'migration_request_id' in daoinput:
            sql3 = sql + "and MIGRATION_REQUEST_ID =:migration_request_id"
            result = self.dbi.processData(sql3, daoinput, conn, transaction)
        elif 'migration_block_id' in daoinput:
            if type(daoinput['migration_block_id']) is not list:
                sql2 = sql+ " and MIGRATION_BLOCK_ID =:migration_block_id"
                result = self.dbi.processData(sql2, daoinput, conn, transaction)
            else:
                bk_id_generator, binds2 =  create_token_generator(daoinput['migration_block_id']) 
                newdaoinput = {}
                newdaoinput.update({"migration_status":daoinput["migration_status"],
                    "last_modification_date":daoinput["last_modification_date"]})
                newdaoinput.update(binds2)
                sql2 = sql+ """ and MIGRATION_BLOCK_ID in ({bk_id_generator} SELECT TOKEN FROM TOKEN_GENERATOR)
                            """.format(bk_id_generator=bk_id_generator)
                result = self.dbi.processData(sql2, newdaoinput, conn, transaction)
        else:
            dbsExceptionHandler("dbsException-conflict-data", "Oracle/MigrationBlock/Update. Required IDs not in the input", self.logger.exception)
125842
protected function migrate()
    {
        if (! $this->container['migrator']->repositoryExists()) {
            throw new Exception('Migration table not found.');
        }

        $this->container['migrator']->run($this->getAttribute('path').'/database/migrations');
    }