/**
  * Execute this command.
  *
  * @return int|void
  */
 protected function doExecute()
 {
     $model = new SchemaModel();
     $this->out()->out('Backing up...');
     // Backup
     $model->backup();
     $this->out()->out(sprintf('Database backup to: %s', $model->getState()->get('dump.path')));
     return;
 }
 /**
  * Execute this command.
  *
  * @return int|void
  */
 protected function doExecute()
 {
     $type = $this->getOption('s') ? 'sql' : 'yaml';
     $model = new SchemaModel();
     if ($this->getOption('a')) {
         $profiles = ProfileHelper::getAllProfiles();
     } else {
         $profiles = $this->io->getArguments() ?: array(ProfileHelper::getProfile());
     }
     $config = Factory::getConfig();
     foreach ($profiles as $profile) {
         $config->set('profile', $profile);
         // Check schema.
         $path = $model->getPath($type);
         if (file_exists($path) && !$this->getOption('y')) {
             $prompter = new BooleanPrompter(sprintf('Schema file <info>%s</info> exists, do you want to override it? [Y/n]: ', $profile));
             if (!$prompter->ask()) {
                 $this->out('cancelled.');
                 return;
             }
         }
         // Exporting
         $this->out()->out('<comment>Exporting</comment> profile schema: <info>' . $profile . '</info>');
         $model->export($type);
         $this->out()->out(sprintf('Schema file dumped to: <info>%s</info>', $model->getState()->get('dump.path')));
     }
     /*
     $yaml = $this->getOption('yaml');
     
     $exporter = $yaml ? new YamlExporter : new SqlExporter;
     
     $result = $exporter->export();
     
     $config = \JFactory::getConfig();
     
     $file = 'site-' . $config->get('db') . '-' . date('Y-m-d-H-i-s');
     
     if ($yaml)
     {
     	$file .= '.yml';
     }
     else
     {
     	$file .= '.sql';
     }
     
     $file = JCONSOLE . '/jconsole/resource/sql/export/' . ($yaml ? 'yaml/' : '') . $file;
     
     \JFile::write($file, $result);
     
     $this->out()->out(sprintf('Sql file dumped to: %s', $file));
     */
 }
 /**
  * Execute this command.
  *
  * @throws \RuntimeException
  * @return int|void
  */
 protected function doExecute()
 {
     $type = $this->getOption('s') ? 'sql' : 'yaml';
     $model = new SchemaModel();
     $path = $model->getPath($type);
     if (file_exists($path) && !$this->getOption('y')) {
         $prompter = new BooleanPrompter('This action will compare and update your sql schema [Y/n]: ');
         if (!$prompter->ask()) {
             $this->out('cancelled.');
             return;
         }
     } elseif (!file_exists($path)) {
         throw new \RuntimeException('Schema file not exists.');
     }
     $force = $this->getOption('f');
     if ($force) {
         throw new \RuntimeException('Sorry, force mode not prepare yet...');
     }
     $state = $model->getState();
     if ($this->getOption('a')) {
         $profiles = ProfileHelper::getAllProfiles();
     } else {
         $profiles = $this->io->getArguments() ?: array(ProfileHelper::getProfile());
     }
     $config = Factory::getConfig();
     foreach ($profiles as $profile) {
         $config->set('profile', $profile);
         // Backup
         $this->out()->out(sprintf('<comment>Backing up</comment> profile <info>%s</info> ...', $profile));
         $model->backup();
         $this->out()->out(sprintf('Schema file backup to: %s', $model->getState()->get('dump.path')));
         // Import
         $this->out()->out(sprintf('<option>Importing</option> profile schema: <info>%s</info> ...', $profile));
         $model->import($force, $type);
         $this->out()->out(sprintf('Schema file dumped to: %s', $model->getState()->get('dump.path')));
         // Report
         $analyze = $state->get('import.analyze');
         foreach ($analyze as $table => $schema) {
             $this->out()->out($table . ':');
             foreach ($schema as $action => $count) {
                 $this->out('    ' . $action . ': ' . $count);
             }
         }
     }
     return;
 }
 /**
  * Execute this command.
  *
  * @throws \RuntimeException
  * @return int|void
  */
 protected function doExecute()
 {
     $model = new SchemaModel();
     $path = $model->backupPath;
     if (file_exists($path) && !$this->getOption('y')) {
         $prompter = new BooleanPrompter('Are you sure you want to restore? [Y/n]: ');
         if (!$prompter->ask()) {
             $this->out('cancelled.');
             return;
         }
     }
     if (!file_exists($path)) {
         throw new \RuntimeException('Backup file not exists.');
     }
     $this->out()->out('Restoring...');
     $model->restore();
     $state = $model->getState();
     $queries = $state->get('import.queries');
     $this->out()->out(sprintf('Restore success, %s queries executed.', $queries));
     return;
 }
 /**
  * Execute this command.
  *
  * @return int|void
  */
 protected function doExecute()
 {
     $table = $this->getArgument(0);
     $name = $this->getArgument(1);
     $value = $this->getArgument(2);
     if (!$table) {
         throw new \InvalidArgumentException("Missing argument <comment>1</comment>: Table name.\n\nUsage:\n" . $this->usage);
     }
     if (!$name) {
         throw new \InvalidArgumentException("Missing argument <comment>2</comment>: Column name.\n\nUsage:\n" . $this->usage);
     }
     $schemaModel = new SchemaModel();
     /** @var $schema Registry */
     $schema = $schemaModel->load();
     // Get this column
     $column = (array) $schema->get($table . '.columns.' . $name);
     if (!$column) {
         throw new \UnexpectedValueException('We are not tracking this table or column of this table not exists.');
     }
     // Notice
     if (isset($column['From'])) {
         $this->out()->out(sprintf('Current rename setting is: %s => %s', implode('|', $column['From']), $column['Field']));
     }
     // If argument 3 not exists, get input.
     $value = $value ?: $this->out()->in('Enter new name:');
     // Not input, cancelled.
     if (!$value) {
         throw new \Exception('Cancelled.');
     }
     // Set input value to new name
     $column['Field'] = $value;
     // Remove origin
     $schema->set($table . '.columns.' . $name, $column);
     $schemaModel->save(null, $schema);
     $this->out()->out("Set rename to : " . $value);
     return true;
 }