Добавление миграции в лог БД после выполнения
@param MigrationInterface $migration
8515
public function completeUp(MigrationInterface $migration)
    {
        $query = (new InsertQueryBuilder())->into(static::tableName())->set([
            'id' => $migration->getTime(),
            'comment' => $migration->comment(),
        ]);

        $parsed = $query->parse($this->connection->getDialect());
        $this->connection->prepare($parsed->getSql())->execute($parsed->getArguments());
    }
1367146
public function down(Migration $migration, $loadFromFile = false)
    {
        if ($loadFromFile) {
            $this->fileRepository->loadSql($migration);
        } else {
            $this->dbRepository->loadSql($migration);
        }

        $func = function () use ($migration) {
            $this->_processMigrationSql($migration->getDown());
            $this->dbRepository->delete($migration);
        };

        $this->_processMigration($migration, $func);
    }
1227716
public function up(Migration $migration)
    {
        if (!$migration->isNew()) {
            throw new \InvalidArgumentException(__METHOD__.": Expected NEW migration");
        }

        // Загрузить SQL
        $this->fileRepository->loadSql($migration);

        $func = function () use ($migration) {
            $this->_processMigrationSql($migration->getUp());
            $this->getDbRepository()->insert($migration);
        };

        $this->_processMigration($migration, $func);
    }
1006020
protected function runClosureMigration($migration, $direction = 'up')
    {
        if (is_array($migration) && array_key_exists($direction, $migration)) {
            call_user_func($migration[$direction], $this->schemaBuilder);
        } else {
            throw new Exception('Migration file should contain an array with up/down.');
        }
    }
1321267
protected function saveMigrationFile(string $filePath, string $migration): void
    {
        $this->output->writeln(sprintf('Generate migration file: %s', $filePath));
        file_put_contents($filePath, $migration);
    }
886958
private function removeMigration(Connection $connection, int $index): void
    {
        $connection->delete(static::MIGRATIONS_TABLE, [static::MIGRATIONS_COLUMN_ID => $index]);
    }
1107415
public function migrates($migrate)
    {
        $token = $this->addTokenCallback($migrate['callback']);
        sd_call_user_func($migrate['callback'], new CoroutineChangeToken($token));
        unset($migrate['callback']);
        $migrate['token'] = $token;
        $this->execute($migrate);
    }
817864
public function run($migration_file, MigrationContext $context)
	{
		$closure = require $migration_file;

		if ( !is_callable($closure) ) {
			throw new \LogicException('The "' . basename($migration_file) . '" migration doesn\'t return a closure.');
		}

		call_user_func($closure, $context);
	}
1227280
private function createMigration($migration, $manifest = array(), $migrationName = '')
    {
        $empty = is_null($migration);
        $date = new DateTime();
        $name = 'm%s_migration';
        $description = [];

        if ($migrationName == '') {

            foreach ($manifest as $key => $value) {
                $description[] = $key;
                foreach ($value as $item) {
                    $description[] = $item;
                }
            }
        } else {
            $description[] = $migrationName;
        }

        if (!$empty || count($description)>0) {
            $description = implode('_', $description);
            $name .= '_' . MigrationManagerHelper::slugify($description);
        }

        $filename = sprintf($name, $date->format('ymd_His'));
        $filename = substr($filename, 0, 250);
        $filename = str_replace('-', '_', $filename);

        $migrator = Craft::$app->getContentMigrator();
        $migrationPath = $migrator->migrationPath;

        $path = sprintf($migrationPath . '/%s.php', $filename);

        $pathLen = strlen($path);
        if ($pathLen > 255) {
            $migrationPathLen = strlen($migrationPath);
            $filename = substr($filename, 0, 250 - $migrationPathLen);
            $path = sprintf($migrationPath . '/%s.php', $filename);
        }

        $migration = json_encode($migration, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        //escape backslashes
        //$migration = str_replace('\\', '\\\\', $migration);

        $content = Craft::$app->view->renderTemplate('migrationmanager/_migration', array('empty' => $empty, 'migration' => $migration, 'className' => $filename, 'manifest' => $manifest, true));

        FileHelper::writeToFile($path, $content);

        // mark the migration as completed if it's not a blank one
        if (!$empty) {
            $migrator->addMigrationHistory($filename);
        }
    }
175929
protected function loadLaravelMigrations($database = []): void
    {
        $options = \is_array($database) ? $database : ['--database' => $database];

        $options['--path'] = 'migrations';

        $migrator = new MigrateProcessor($this, $options);

        $migrator->up();

        $this->app[ConsoleKernel::class]->setArtisan(null);

        $this->beforeApplicationDestroyed(function () use ($migrator) {
            $migrator->rollback();
        });
    }
970830
public function rollback(ContainerInterface $container): void
    {
        foreach ($this->getRollbacks($container) as $class) {
            assert(is_string($class));
            $this->getIO()->writeInfo("Starting rollback for `$class`..." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
            if (($migration = $this->createMigration($class, $container)) !== null) {
                $migration->init($container)->rollback();
                $this->getIO()->writeInfo("Rollback finished for `$class`." . PHP_EOL, IoInterface::VERBOSITY_NORMAL);
            }
        }

        $manager = $this->getConnection($container)->getSchemaManager();
        if ($manager->tablesExist([static::MIGRATIONS_TABLE]) === true) {
            $manager->dropTable(static::MIGRATIONS_TABLE);
        }
        if ($manager->tablesExist([static::SEEDS_TABLE]) === true) {
            $manager->dropTable(static::SEEDS_TABLE);
        }
    }
1162709
public function addMigration(string $path, Migration $migrations): void{
        $name = basename($path);
        $this->migrations[$name] = $migrations;
    }
616445
private function _processMigration(Migration $migration, callable $command)
    {
        if ($migration->isTransaction()) {
            $this->getDbRepository()->getAdapter()->transaction($command);
        } else {
            if ($this->logger) {
                $this->logger->alert('NO TRANSACTION!');
            }
            $command();
        }
    }
10913
public function migrate($migrationName) {
		$this->createTable();
		$this->db->dal()->into('_migrations')->insert(['name'=>$migrationName, 'migrated'=>date('Y-m-d H:i:s')]);
	}
932165
public function write(string $identifier, MigrationList $executedMigrations): void
    {
        $exchange = $this->settings['exchange'];
        $client = $this->connector->getConnection();
        $uri = sprintf('/api/bindings/%1$s/e/%2$s/e/%2$s', $this->getVhost(), $exchange);

        // delete existing migration list entries before rewriting
        foreach ($this->loadMigrations() as $migration) {
            $client->delete($uri.'/'.$migration['properties_key']);
        }

        foreach ($executedMigrations as $migration) {
            $client->post($uri, [
                'body' => json_encode([
                    'routing_key' => $identifier,
                    'arguments' => $migration->toNative()
                ])
            ]);
        }
    }
515033
public function loadMigrationsFrom($paths, Model $entity): void
    {
        $id = $entity->getKey();

        if (! isset($this->migrationPaths[$id])) {
            $this->migrationPaths[$id] = $this->getDefaultMigrationPaths();
        }

        $this->migrationPaths[$id] = \array_merge($this->migrationPaths[$id], Arr::wrap($paths));
        $this->migrationPaths[$id] = \array_unique($this->migrationPaths[$id]);
    }
502893
protected function runMigration($migration, $method)
    {
        $callback = function () use ($migration, $method) {
            if (method_exists($migration, $method)) {
                $migration->{$method}();
            }
        };

        $callback();
    }