public function handle($request) { parent::handle($request); $this->initTracker(); $migrations = $this->app->getTrackedMigrations(); $this->checkNonMigrated($migrations); foreach ($migrations as $id => $migration) { if ($migration->status == 'new') { $this->printMigration($migration); $this->register($migration); if (!empty($migration->before)) { $this->setStatus($migration, 'before'); Utilities::exec($migration->before); } $this->setStatus($migration, 'loading...'); $this->app->getTracker()->load($migration); if (!empty($migration->after)) { $this->setStatus($migration, 'after'); Utilities::exec($migration->after); } $this->setStatus($migration, 'migrated'); echo "\n"; } } echo "All migrated\n"; }
public function handle($request) { echo "Mysql migration loader. Version: " . $this->app->parameters['app-version'] . "\n\n"; echo "Usage:\n"; echo " db-migration <command> [--option value]\n"; $commands = $this->getAvaialbeCommands(); echo "\nCommands:\n"; foreach ($commands as $key => $value) { echo sprintf(" %-15s %s\n", $key, $value); } echo "\nOptions:\n"; echo " Full name | Short | Default | Note\n"; echo "-----------------------------------------------------\n"; echo " --clean no (yes|no) Clean output, no headers\n"; echo " --config -f db-migration.yml Path to config YML file. Default at current folder\n"; echo " --migrations -m migrations Path to migration scripts, repeatable option\n"; echo " --driver -r mysql Database driver\n"; $drivers = $this->getAvaialbeDrivers(); foreach ($drivers as $driver_name) { $c_name = Utilities::strToClassName($driver_name); $c_name = 'Reactor\\DbMigration\\Drivers\\' . $c_name . 'Driver'; $driver = new $c_name(); $argumets = $driver->getDefaults(); echo "\n'{$driver_name}' driver:\n"; echo " Full name | Short | Default | Note\n"; echo "-----------------------------------------------------\n"; foreach ($argumets as $value) { echo sprintf(" --%-16s -%-6s %-18s %s\n", $value[0], $value[1], $value[2], $value[3]); } } echo "\nAll options can be specified in YML file. Pleae use full name of option.\n\n"; }
public function handleBody() { $this->loadCommonParameters(); if (!$this->app->parameters['clean']) { $this->welcome(); } $command = $this->getCommand(); $c_name = Utilities::strToClassName($command); $c_name = 'Reactor\\DbMigration\\CliControllers\\' . $c_name . 'Controller'; if (!class_exists($c_name)) { throw new \Exception("No such command '{$command}'", 1); } $command_ctrl = new $c_name($this->app); $command_ctrl->handle($this->request); }
public static function loadConfig($file) { $file_options = self::parseYAML(file_get_contents($file), true); return Utilities::resolveEnv($file_options); }
public function printParameters() { echo "Current parameters:\n"; $parameters = $this->app->parameters; if (!empty($parameters['password'])) { $parameters['password'] = '******'; } unset($parameters['_words_']); echo Utilities::dumpYAML($parameters, 10, 2); echo "\n"; }
protected function buildCmd($options, $migration) { $full_name = $migration->fullname; $rez = 'mysql -B ' . Utilities::buildCmdArgs($options, array('host' => '--host=', 'user' => '--user='******'port' => '--port=', 'password' => '--password='******'unix_socket' => '--socket=', 'database' => '--database=')); if (isset($options['extra'])) { $rez .= ' ' . $options['extra']; } return $rez . ' < ' . escapeshellarg($full_name); }