Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $version = $input->hasArgument('to-version') ? $input->getArgument('to-version') : null;
     $migration = $this->getContainer()->get('dami.migration');
     $message = function ($name, $version) use($output) {
         $output->write(sprintf("\n<comment>Migration %s %s</comment>", $version, $name));
     };
     try {
         $numberMigrations = $migration->migrate($version, $message);
         if ($numberMigrations > 0) {
             if ($numberMigrations == 1) {
                 $output->write(sprintf("\n<info>%d migration was executed.</info>", $numberMigrations));
             } else {
                 $output->write(sprintf("\n<info>%d migrations were executed.</info>", $numberMigrations));
             }
         } else {
             $output->writeln(sprintf('<comment>No migrations detected.</comment>'));
         }
     } catch (\PDOException $e) {
         $output->writeln("\n<error>There was something wrong during migration. Database schema has not been changed.</error>");
         if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
             $output->writeln(sprintf("\n<error>%s</error>", $e->getMessage()));
         }
     }
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $migrationFiles = $this->getContainer()->get('dami.migration_files');
     $migrationFiles->statusIntention();
     $rows = array();
     foreach ($migrationFiles->get() as $migrationFile) {
         $status = $migrationFile->isMigrated() ? 'Migrated' : 'Not migrated';
         $rows[] = array($status, $migrationFile->getVersion(), $migrationFile->getName());
     }
     if (count($rows) > 0) {
         $table = $this->getHelperSet()->get('table');
         $table->setHeaders(array('Status', 'Version', 'Name'))->setRows($rows)->render($output);
     } else {
         $output->writeln(sprintf('<comment>There are no migrations.</comment>'));
     }
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $arguments = $input->getArguments();
     $migrationName = $arguments['migration_name'];
     $filenameBuilder = new FileNameBuilder($migrationName);
     $fileSystem = new Filesystem();
     $templateRenderer = $this->getContainer()->get('dami.template_renderer');
     $migrationDirectory = $this->getContainer()->getparameter('dami.migrations_directory');
     try {
         $fileName = $filenameBuilder->build();
         $path = $migrationDirectory . '/' . $fileName;
         $fileSystem->dumpFile($path, $templateRenderer->render($migrationName));
         $output->writeln('<info>Migration has been created.</info>');
         $output->writeln(sprintf('<comment>Location: %s</comment>', $path));
     } catch (\Exception $e) {
         $output->writeln(sprintf("<error>Something went wrong.</error>\n\n%s", $e->getMessage()));
     }
 }
Exemplo n.º 4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $version = $input->getArgument('to-version');
     $migration = $this->getContainer()->get('dami.migration');
     $message = function ($name, $version) use($output) {
         $output->write(sprintf("\n<comment>Migration %s %s</comment>", $version, $name));
     };
     if (null === $version) {
         $numberMigrations = $migration->migrateToPreviousVersion($message);
     } else {
         if ($version === 'all') {
             $version = 0;
         }
         $numberMigrations = $migration->migrate($version, $message);
     }
     if (0 === $numberMigrations) {
         $output->writeln(sprintf("<comment>Nothing migrations detected to rollback.</comment>"));
     } elseif ($numberMigrations > 1) {
         $output->writeln(sprintf("\n<info>%d migrations were rollbacked.</info>", $numberMigrations));
     }
 }