src/Phinx/Console/Command/Migrate.php
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);

        $version = $input->getOption('target');
        $environment = $input->getOption('environment');
        $date = $input->getOption('date');
        $fake = (bool)$input->getOption('fake');

        if ($environment === null) {
            $environment = $this->getConfig()->getDefaultEnvironment();
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
        } else {
            $output->writeln('<info>using environment</info> ' . $environment);
        }

        $envOptions = $this->getConfig()->getEnvironment($environment);
        if (isset($envOptions['adapter'])) {
            $output->writeln('<info>using adapter</info> ' . $envOptions['adapter']);
        }

        if (isset($envOptions['wrapper'])) {
            $output->writeln('<info>using wrapper</info> ' . $envOptions['wrapper']);
        }

        if (isset($envOptions['name'])) {
            $output->writeln('<info>using database</info> ' . $envOptions['name']);
        } else {
            $output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>');

            return 1;
        }

        if (isset($envOptions['table_prefix'])) {
            $output->writeln('<info>using table prefix</info> ' . $envOptions['table_prefix']);
        }
        if (isset($envOptions['table_suffix'])) {
            $output->writeln('<info>using table suffix</info> ' . $envOptions['table_suffix']);
        }

        if ($fake) {
            $output->writeln('<comment>warning</comment> performing fake migrations');
        }

        try {
            // run the migrations
            $start = microtime(true);
            if ($date !== null) {
                $this->getManager()->migrateToDateTime($environment, new \DateTime($date), $fake);
            } else {
                $this->getManager()->migrate($environment, $version, $fake);
            }
            $end = microtime(true);
        } catch (\Exception $e) {
            $output->writeln('<error>' . $e->__toString() . '</error>');
            return 1;
        } catch (\Throwable $e) {
            $output->writeln('<error>' . $e->__toString() . '</error>');
            return 1;
        }

        $output->writeln('');
        $output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');

        return 0;
    }
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->bootstrap($input, $output);

        $version = $input->getOption('target');
        $environment = $input->getOption('environment');
        $date = $input->getOption('date');
        $fake = (bool)$input->getOption('fake');

        if ($environment === null) {
            $environment = $this->getConfig()->getDefaultEnvironment();
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
        } else {
            $output->writeln('<info>using environment</info> ' . $environment);
        }

        $envOptions = $this->getConfig()->getEnvironment($environment);
        if (isset($envOptions['adapter'])) {
            $output->writeln('<info>using adapter</info> ' . $envOptions['adapter']);
        }

        if (isset($envOptions['wrapper'])) {
            $output->writeln('<info>using wrapper</info> ' . $envOptions['wrapper']);
        }

        if (isset($envOptions['name'])) {
            $output->writeln('<info>using database</info> ' . $envOptions['name']);
        } else {
            $output->writeln('<error>Could not determine database name! Please specify a database name in your config file.</error>');

            return 1;
        }

        if (isset($envOptions['table_prefix'])) {
            $output->writeln('<info>using table prefix</info> ' . $envOptions['table_prefix']);
        }
        if (isset($envOptions['table_suffix'])) {
            $output->writeln('<info>using table suffix</info> ' . $envOptions['table_suffix']);
        }

        if ($fake) {
            $output->writeln('<comment>warning</comment> performing fake migrations');
        }

        try {
            // run the migrations
            $start = microtime(true);
            if ($date !== null) {
                $this->getManager()->migrateToDateTime($environment, new \DateTime($date), $fake);
            } else {
                $this->getManager()->migrate($environment, $version, $fake);
            }
            $end = microtime(true);
        } catch (\Exception $e) {
            $output->writeln('<error>' . $e->__toString() . '</error>');
            return 1;
        } catch (\Throwable $e) {
            $output->writeln('<error>' . $e->__toString() . '</error>');
            return 1;
        }

        $output->writeln('');
        $output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');

        return 0;
    }
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> bootstrap ( $ input , $ output ) ; $ version = $ input -> getOption ( 'target' ) ; $ environment = $ input -> getOption ( 'environment' ) ; $ date = $ input -> getOption ( 'date' ) ; $ fake = ( bool ) $ input -> getOption ( 'fake' ) ; if ( $ environment === null ) { $ environment = $ this -> getConfig ( ) -> getDefaultEnvironment ( ) ; $ output -> writeln ( '<comment>warning</comment> no environment specified, defaulting to: ' . $ environment ) ; } else { $ output -> writeln ( '<info>using environment</info> ' . $ environment ) ; } $ envOptions = $ this -> getConfig ( ) -> getEnvironment ( $ environment ) ; if ( isset ( $ envOptions [ 'adapter' ] ) ) { $ output -> writeln ( '<info>using adapter</info> ' . $ envOptions [ 'adapter' ] ) ; } if ( isset ( $ envOptions [ 'wrapper' ] ) ) { $ output -> writeln ( '<info>using wrapper</info> ' . $ envOptions [ 'wrapper' ] ) ; } if ( isset ( $ envOptions [ 'name' ] ) ) { $ output -> writeln ( '<info>using database</info> ' . $ envOptions [ 'name' ] ) ; } else { $ output -> writeln ( '<error>Could not determine database name! Please specify a database name in your config file.</error>' ) ; return 1 ; } if ( isset ( $ envOptions [ 'table_prefix' ] ) ) { $ output -> writeln ( '<info>using table prefix</info> ' . $ envOptions [ 'table_prefix' ] ) ; } if ( isset ( $ envOptions [ 'table_suffix' ] ) ) { $ output -> writeln ( '<info>using table suffix</info> ' . $ envOptions [ 'table_suffix' ] ) ; } if ( $ fake ) { $ output -> writeln ( '<comment>warning</comment> performing fake migrations' ) ; } try { // run the migrations $ start = microtime ( true ) ; if ( $ date !== null ) { $ this -> getManager ( ) -> migrateToDateTime ( $ environment , new \ DateTime ( $ date ) , $ fake ) ; } else { $ this -> getManager ( ) -> migrate ( $ environment , $ version , $ fake ) ; } $ end = microtime ( true ) ; } catch ( \ Exception $ e ) { $ output -> writeln ( '<error>' . $ e -> __toString ( ) . '</error>' ) ; return 1 ; } catch ( \ Throwable $ e ) { $ output -> writeln ( '<error>' . $ e -> __toString ( ) . '</error>' ) ; return 1 ; } $ output -> writeln ( '' ) ; $ output -> writeln ( '<comment>All Done. Took ' . sprintf ( '%.4fs' , $ end - $ start ) . '</comment>' ) ; return 0 ; }
Migrate the database.

@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return int integer 0 on success, or an error code.
Migrate the database .