migrations example

'Laminas\Escaper',
        'Psr\Log',
    ];

    /** * Displays a list of all migrations and whether they've been run or not. * * @param array<string, mixed> $params */
    public function run(array $params)
    {
        $runner     = Services::migrations();
        $paramGroup = $params['g'] ?? CLI::getOption('g');

        // Get all namespaces         $namespaces = Services::autoloader()->getNamespace();

        // Collection of migration status         $status = [];

        foreach (array_keys($namespaces) as $namespace) {
            if (ENVIRONMENT !== 'testing') {
                // Make Tests\\Support discoverable for testing

        if ($this->db === null) {
            $this->db = Database::connect($this->DBGroup);
            $this->db->initialize();
        }

        if ($this->migrations === null) {
            // Ensure that we can run migrations             $config          = new Migrations();
            $config->enabled = true;

            $this->migrations = Services::migrations($config$this->db);
            $this->migrations->setSilent(false);
        }

        if ($this->seeder === null) {
            $this->seeder = Database::seeder($this->DBGroup);
            $this->seeder->setSilent(true);
        }
    }

    // --------------------------------------------------------------------     // Migrations

        if (ENVIRONMENT === 'production') {
            // @codeCoverageIgnoreStart             $force = array_key_exists('f', $params) || CLI::getOption('f');

            if ($force && CLI::prompt(lang('Migrations.rollBackConfirm')['y', 'n']) === 'n') {
                return;
            }
            // @codeCoverageIgnoreEnd         }

        $runner = Services::migrations();
        $group  = $params['g'] ?? CLI::getOption('g');

        if (is_string($group)) {
            $runner->setGroup($group);
        }

        try {
            $batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
            CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

            if ($runner->regress($batch)) {
                
protected $options = [
        '-n'    => 'Set migration namespace',
        '-g'    => 'Set database group',
        '--all' => 'Set for all namespaces, will ignore (-n) option',
    ];

    /** * Ensures that all migrations have been run. */
    public function run(array $params)
    {
        $runner = Services::migrations();
        $runner->clearCliMessages();

        CLI::write(lang('Migrations.latest'), 'yellow');

        $namespace = $params['n'] ?? CLI::getOption('n');
        $group     = $params['g'] ?? CLI::getOption('g');

        try {
            if (array_key_exists('all', $params) || CLI::getOption('all')) {
                $runner->setNamespace(null);
            } elseif ($namespace) {
                
Home | Imprint | This part of the site doesn't use cookies.