3 namespace Friendica\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 update command (Even if the database structure matches)
37 -o|--override Override running or stalling updates
42 protected function doExecute()
44 if ($this->getOption('v')) {
45 $this->out('Class: ' . __CLASS__);
46 $this->out('Arguments: ' . var_export($this->args, true));
47 $this->out('Options: ' . var_export($this->options, true));
50 if (count($this->args) == 0) {
51 $this->out($this->getHelp());
55 if (count($this->args) > 1) {
56 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
59 if (!DBA::connected()) {
60 throw new RuntimeException('Unable to connect to database');
67 switch ($this->getArgument(0)) {
69 $output = DBStructure::update($a->getBasePath(), true, false);
72 $force = $this->getOption(['f', 'force'], false);
73 $override = $this->getOption(['o', 'override'], false);
74 $output = Update::run($a->getBasePath(), $force, $override,true, false);
78 DBStructure::printStructure($a->getBasePath());
79 $output = ob_get_clean();
83 DBStructure::convertToInnoDB();
84 $output = ob_get_clean();
87 $output = 'Unknown command: ' . $this->getArgument(0);