Skip to content

Commit

Permalink
Add option in initdb.sh to update schema if already exists (#8438)
Browse files Browse the repository at this point in the history
This can be used by the Docker images where we don't know whether the configured database is already initialized or not.
  • Loading branch information
thomascube authored Feb 7, 2022
1 parent a482ff7 commit fa7f6a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion bin/initdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require_once INSTALL_PATH . 'program/include/clisetup.php';
// get arguments
$opts = rcube_utils::get_opt([
'd' => 'dir',
'u' => 'update'
]);

if (empty($opts['dir'])) {
Expand All @@ -36,4 +37,11 @@ if (!file_exists($opts['dir'])) {
rcube::raise_error("Specified database schema directory doesn't exist.", false, true);
}

rcmail_utils::db_init($opts['dir']);
$db = rcmail_utils::db();

if (!empty($opts['update']) && in_array($db->table_name('system'), (array)$db->list_tables())) {
echo "Checking for database schema updates..." . PHP_EOL;
rcmail_utils::db_update($opts['dir'], 'roundcube', null, ['errors' => true]);
} else {
rcmail_utils::db_init($opts['dir']);
}

0 comments on commit fa7f6a7

Please sign in to comment.