3 namespace Friendica\Core\Console;
6 use Friendica\Core\Update;
7 use Friendica\Database\DBA;
8 use Friendica\Database\DBStructure;
12 * @brief Performs database updates from the command line
14 * @author Hypolite Petovan <hypolite@mrpetovan.com>
16 class DatabaseStructure extends \Asika\SimpleConsole\Console
18 protected $helpOptions = ['h', 'help', '?'];
20 protected function getHelp()
23 console dbstructure - Performs database updates
25 bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
28 dryrun Show database update schema queries without running them
29 update Update database schema
30 dumpsql Dump database schema
31 toinnodb Convert all tables from MyISAM to InnoDB
34 -h|--help|-? Show help information
35 -v Show more debug information.
36 -f|--force Force the command in case of "update" (Ignore failed updates/running updates)
41 protected function doExecute()
43 if ($this->getOption('v')) {
44 $this->out('Class: ' . __CLASS__);
45 $this->out('Arguments: ' . var_export($this->args, true));
46 $this->out('Options: ' . var_export($this->options, true));
49 if (count($this->args) == 0) {
50 $this->out($this->getHelp());
54 if (count($this->args) > 1) {
55 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
58 if (!DBA::connected()) {
59 throw new RuntimeException('Unable to connect to database');
64 switch ($this->getArgument(0)) {
66 $output = DBStructure::update(true, false);
69 $force = $this->getOption(['f', 'force'], false);
70 $output = Update::run($force, true, false);
74 DBStructure::printStructure();
75 $output = ob_get_clean();
79 DBStructure::convertToInnoDB();
80 $output = ob_get_clean();
83 $output = 'Unknown command: ' . $this->getArgument(0);