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');
66 switch ($this->getArgument(0)) {
68 $output = DBStructure::update($a->getBasePath(), true, false);
71 $force = $this->getOption(['f', 'force'], false);
72 $output = Update::run($a->getBasePath(), $force, true, false);
76 DBStructure::printStructure($a->getBasePath());
77 $output = ob_get_clean();
81 DBStructure::convertToInnoDB();
82 $output = ob_get_clean();
85 $output = 'Unknown command: ' . $this->getArgument(0);