protected function execute(InputInterface $input, OutputInterface $output) { $app = $this->app; $description = $input->getArgument('description'); $directory = Migration::getDirectory(); $data = Migration::getTemplate(); $underscore = implode('_', $description); $version = Migration::getNextVersion($app); $filename = $version . '_' . $underscore . '.yml'; $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false); $output = Output::style($output); $output->writeln('<highlight>Creating migration file:</highlight>'); $output->writeln("<info> - {$filename}</info>"); if (!$helper->ask($input, $output, $question)) { return; } if (file_exists($directory . '/' . $filename)) { $output->writeln("<error>The migration file already {$filename} exists.</error>"); return; } file_put_contents($directory . '/' . $filename, $data); $text = '<info>Sucessfully created migration file.</info>'; $output->writeln($text); }
protected function execute(InputInterface $input, OutputInterface $output) { $app = $this->app; $yaml = new Parser(); $dir = Migration::getDirectory(); $files = Migration::getUnMigratedFiles($app); $output = Output::style($output); $total = count($files); $helper = $this->getHelper('question'); if ($total == 0) { $output->writeln('<error>No new files to be migrated.</error>'); return; } $output->writeln('<highlight>Migration will run the following files:</highlight>'); foreach ($files as $file) { $output->writeln("<info>- {$file}</info>"); } $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false); if (!$helper->ask($input, $output, $question)) { return; } foreach ($files as $file) { $output->writeln("<info>- Migrating ({$file})</info>"); $content = $yaml->parse(file_get_contents($dir . '/' . $file)); $up = explode(';', trim($content['up'])); $up = array_filter($up); $date = element('date', $content); $author = element('author', $content); $changelog = element('changelog', $content); $dateFormat = validate_date($date); $fileFormat = Migration::validateFileFormat($file); if (!$fileFormat) { $output->writeln('<error>Invalid file format.</error>'); return; } elseif (!$dateFormat) { $output->writeln('<error>Invalid date (YYYY-mm-dd HH:mm:ss).</error>'); return; } elseif (!$author) { $output->writeln('<error>Invalid author.</error>'); return; } elseif (!$changelog) { $output->writeln('<error>Invalid changelog.</error>'); return; } foreach ($up as $query) { $app['db']::statement(trim($query)); } $info = Migration::getFileInfo($file); $app['db']->table('migrations')->insert(['version' => $info['version'], 'author' => $author, 'filename' => $file, 'changelog' => $changelog, 'created_at' => $date, 'updated_at' => new \DateTime()]); } }
protected function execute(InputInterface $input, OutputInterface $output) { $output = Output::style($output); $files = []; foreach (Migration::getUnMigratedFiles($this->app) as $file) { $files[] = [$file]; } if (!$files) { $output->writeln('<highlight>Nothing to migrate.</highlight>'); return; } $table = new Table($output); $table->setHeaders(['Unmigrated YML'])->setRows($files); $table->render(); }
protected function execute(InputInterface $input, OutputInterface $output) { $app = $this->app; $dir = Migration::getDirectory(); $output = Output::style($output); $yaml = new Parser(); $version = $input->getArgument('version'); $helper = $this->getHelper('question'); $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (y/N):</question> ', false); if ($version) { $record = $app['db']->table('migrations')->where('version', '=', $version)->first(); if (!$record) { $output->writeln('<error>Unable to find migration version.</error>'); return; } $records = $app['db']->table('migrations')->where('id', '>=', $record->id)->orderBy('version', 'DESC')->get(); } else { $records = $app['db']->table('migrations')->orderBy('version', 'DESC')->take(1)->get(); } if (count($records) == 0) { $output->writeln('<error>Nothing to downgrade.</error>'); return; } $output->writeln('<highlight>Migration will downgrade to the following files:</highlight>'); foreach ($records as $record) { $output->writeln("<info>- {$record->filename}</info>"); } if (!$helper->ask($input, $output, $question)) { return; } foreach ($records as $record) { $id = $record->id; $version = $record->version; $filename = $record->filename; $output->writeln("<info>- Downgrading ({$filename})</info>"); $value = $yaml->parse(file_get_contents($dir . '/' . $filename)); $down = explode(';', trim($value['down'])); $down = array_filter($down); foreach ($down as $query) { $app['db']::statement(trim($query)); } $app['db']->table('migrations')->delete($id); } }