3 namespace Friendica\Core\Console;
6 use Friendica\Database\DBStructure;
8 require_once 'boot.php';
9 require_once 'include/dba.php';
12 * @brief Does database updates from the command line
14 * @author Hypolite Petovan <mrpetovan@gmail.com>
16 class DatabaseStructure extends \Asika\SimpleConsole\Console
18 protected $helpOptions = ['h', 'help', '?'];
20 protected function getHelp()
23 console dbstructure - Does database updates
25 bin/console dbstructure <command> [-h|--help|-?] [-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.
40 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');
65 switch ($this->getArgument(0)) {
67 $output = DBStructure::update(true, false);
70 $output = DBStructure::update(true, true);
72 $build = Core\Config::get('system', 'build');
74 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
75 $build = DB_UPDATE_VERSION;
78 $stored = intval($build);
79 $current = intval(DB_UPDATE_VERSION);
81 // run any left update_nnnn functions in update.php
82 for ($x = $stored; $x < $current; $x ++) {
83 $r = run_update_function($x);
89 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
93 DBStructure::printStructure();
94 $output = ob_get_clean();
98 DBStructure::convertToInnoDB();
99 $output = ob_get_clean();