public function up() { Lhm::setAdapter($this->getAdapter()); Lhm::changeTable('ponies', function (Table $ponies) { $ponies->renameColumn('name', 'first_name')->save(); }); }
public function down() { Lhm::setAdapter($this->getAdapter()); Lhm::changeTable('ponies', function (Table $ponies) { $ponies->removeIndex('age', ['name' => 'ponies_age_idx'])->removeColumn('age', 'integer', ['null' => true])->save(); }, ['archive_name' => 'drop_the_ponies_age']); }
public function up() { $ponies = $this->table('ponies'); $ponies->addColumn('location', 'string', ['null' => true, 'length' => 255, 'default' => 'Canada'])->save(); Lhm::setAdapter($this->getAdapter()); Lhm::changeTable('ponies', function (Table $ponies) { $ponies->addColumn('age', 'integer', ['null' => true])->save(); }); }
public function up() { Lhm::setAdapter($this->getAdapter()); Lhm::changeTable('ponies', function (Table $ponies) { $ponies->addColumn('age', 'integer', ['default' => 1]); $ponies->addColumn('nickname', 'string', ['after' => 'name', 'length' => 20, 'null' => true, 'default' => 'derp']); $ponies->save(); }); }
public function testCleanupDryRun() { $this->adapter->query('CREATE TABLE test(id INT PRIMARY KEY);'); $this->adapter->query('CREATE TABLE lhma_2015_03_04_13_22_33_test(id INT PRIMARY KEY);'); $this->adapter->query(implode("\n ", ['CREATE TRIGGER lhmt_update_test', 'AFTER UPDATE ON test FOR EACH ROW', 'REPLACE INTO derp (`id`) /* large hadron migration (php) */', 'VALUES (NEW.`id`)'])); Lhm::setAdapter($this->adapter); Lhm::cleanup(false, ['until' => new \DateTime()]); /** @var \PDOStatement $statement */ $statement = $this->adapter->query('show triggers'); $this->assertEquals('lhmt_update_test', $statement->fetchColumn(0)); $statement = $this->adapter->query('show tables'); $this->assertEquals(3, $statement->rowCount()); $this->assertEquals('lhma_2015_03_04_13_22_33_test', $statement->fetchColumn(0)); $this->assertEquals('phinxlog', $statement->fetchColumn(0)); $this->assertEquals('test', $statement->fetchColumn(0)); }
/** * Cleanup the database * * @param InputInterface $input * @param OutputInterface $output * @throws \RuntimeException * @throws \InvalidArgumentException * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->getConfig()) { $this->loadConfig($input, $output); } $this->loadManager($output); $environment = $input->getOption('environment'); if (null === $environment) { $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['name'])) { $output->writeln('<info>using database</info> ' . $envOptions['name']); } $run = (bool) $input->getOption('run'); $until = $input->getOption('until'); if ($until) { $until = \DateTime::createFromFormat('Y-m-d_H:i:s', $until, new \DateTimeZone('UTC')); if ($until === false) { throw new \InvalidArgumentException("The specified date in `until` is invalid."); } } if ($run) { $output->writeln('<info>LHM will drop temporary tables and triggers</info>'); } else { $output->writeln('<info>Executing dry-run</info>'); } $options = []; if ($until) { $options['until'] = $until; $output->writeln('<warning>LHM will drop archives created before ' . $until->format('Y-M-D H:i:s T') . '</warning>'); } $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); $handler = new ConsoleHandler($output); $logger = new Logger('lhm'); $logger->pushHandler($handler); Lhm::setLogger($logger); $environment = $this->manager->getEnvironment($environment); Lhm::setAdapter($environment->getAdapter()); Lhm::cleanup($run, $options); }