upgrade added strict DB mode

This commit is contained in:
OpenXE 2023-12-07 13:38:59 +01:00
parent 5816dedbc0
commit 7ffb9a86a5
3 changed files with 74 additions and 13 deletions

View File

@ -113,6 +113,12 @@ if (php_sapi_name() == "cli") {
} else { } else {
} }
if (in_array('-strict', $argv)) {
$strict_db = true;
} else {
$strict_db = false;
}
if (in_array('-do', $argv)) { if (in_array('-do', $argv)) {
if (!$check_git && !$check_db) { if (!$check_git && !$check_db) {
$do_git = true; $do_git = true;
@ -127,7 +133,17 @@ if (php_sapi_name() == "cli") {
} }
if ($check_git || $check_db || $do_git || $do_db) { if ($check_git || $check_db || $do_git || $do_db) {
upgrade_main($directory,$verbose,$check_git,$do_git,$export_db,$check_db,$do_db,$force,$connection,$origin); upgrade_main( directory: $directory,
verbose: $verbose,
check_git: $check_git,
do_git: $do_git,
export_db: $export_db,
check_db: $check_db,
strict_db: $strict_db,
do_db: $do_db,
force: $force,
connection: $connection,
origin: $origin);
} else { } else {
info(); info();
} }
@ -139,7 +155,7 @@ if (php_sapi_name() == "cli") {
} }
// -------------------------------- END // -------------------------------- END
function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $do_db, bool $force, bool $connection, bool $origin) { function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $strict_db, bool $do_db, bool $force, bool $connection, bool $origin) {
$mainfolder = dirname($directory); $mainfolder = dirname($directory);
$datafolder = $directory."/data"; $datafolder = $directory."/data";
@ -379,7 +395,7 @@ function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do
echo_out("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n"); echo_out("--------------- Calculating database upgrade for '$schema@$host'... ---------------\n");
$upgrade_sql = array(); $upgrade_sql = array();
$result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers); $result = mustal_calculate_db_upgrade($compare_def, $db_def, $upgrade_sql, $mustal_replacers, $strict_db);
if (!empty($result)) { if (!empty($result)) {
abort(count($result)." errors.\n"); abort(count($result)." errors.\n");
@ -482,6 +498,7 @@ function info() {
echo_out("\t-f: force override of existing files\n"); echo_out("\t-f: force override of existing files\n");
echo_out("\t-o: update from origin instead of remote.json\n"); echo_out("\t-o: update from origin instead of remote.json\n");
echo_out("\t-connection use connection.json in data folder instead of user.inc.php\n"); echo_out("\t-connection use connection.json in data folder instead of user.inc.php\n");
echo_out("\t-strict: innodb_strict_mode=ON\n");
echo_out("\t-clean: (not yet implemented) create the needed SQL to remove items from the database not in the JSON\n"); echo_out("\t-clean: (not yet implemented) create the needed SQL to remove items from the database not in the JSON\n");
echo_out("\n"); echo_out("\n");
} }

View File

@ -21,7 +21,7 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array
Compare two database structures Compare two database structures
Returns a structured array containing information on all the differences. Returns a structured array containing information on all the differences.
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql) : int function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, bool $strict) : int
Generate the SQL needed to upgrade the database to match the definition, based on a comparison. Generate the SQL needed to upgrade the database to match the definition, based on a comparison.
Data structure in Array and JSON Data structure in Array and JSON
@ -542,7 +542,7 @@ function mustal_implode_with_quote(string $quote, string $delimiter, array $arra
// 11 Table type upgrade not supported // 11 Table type upgrade not supported
// 12 Upgrade type not supported // 12 Upgrade type not supported
function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers) : array { function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$upgrade_sql, array $replacers, bool $strict) : array {
$result = array(); $result = array();
$upgrade_sql = array(); $upgrade_sql = array();
@ -752,8 +752,10 @@ function mustal_calculate_db_upgrade(array $compare_def, array $db_def, array &$
$upgrade_sql = array_unique($upgrade_sql); $upgrade_sql = array_unique($upgrade_sql);
if (count($upgrade_sql) > 0) { if (count($upgrade_sql) > 0) {
array_unshift($upgrade_sql,"SET SQL_MODE='ALLOW_INVALID_DATES';");
array_unshift($upgrade_sql,"SET SQL_MODE='ALLOW_INVALID_DATES';","SET SESSION innodb_strict_mode=OFF;"); if (!$strict) {
array_unshift($upgrade_sql,"SET SESSION innodb_strict_mode=OFF;");
}
} }
return($result); return($result);

View File

@ -41,29 +41,71 @@ class upgrade {
$this->app->Tpl->Set('UPGRADE_VISIBLE', "hidden"); $this->app->Tpl->Set('UPGRADE_VISIBLE', "hidden");
$this->app->Tpl->Set('UPGRADE_DB_VISIBLE', "hidden"); $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', "hidden");
//function upgrade_main(string $directory,bool $verbose, bool $check_git, bool $do_git, bool $export_db, bool $check_db, bool $do_db, bool $force, bool $connection, bool $origin) {
$directory = dirname(getcwd())."/upgrade"; $directory = dirname(getcwd())."/upgrade";
switch ($submit) { switch ($submit) {
case 'check_upgrade': case 'check_upgrade':
$this->app->Tpl->Set('UPGRADE_VISIBLE', ""); $this->app->Tpl->Set('UPGRADE_VISIBLE', "");
unlink($logfile); unlink($logfile);
upgrade_main($directory,$verbose,true,false,false,true,false,$force,false,false); upgrade_main( directory: $directory,
verbose: $verbose,
check_git: true,
do_git: false,
export_db: false,
check_db: true,
strict_db: false,
do_db: false,
force: $force,
connection: false,
origin: false
);
break; break;
case 'do_upgrade': case 'do_upgrade':
unlink($logfile); unlink($logfile);
upgrade_main($directory,$verbose,true,true,false,true,true,$force,false,false); upgrade_main( directory: $directory,
verbose: $verbose,
check_git: true,
do_git: true,
export_db: false,
check_db: true,
strict_db: false,
do_db: true,
force: $force,
connection: false,
origin: false
);
break; break;
case 'check_db': case 'check_db':
$this->app->Tpl->Set('UPGRADE_DB_VISIBLE', ""); $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', "");
unlink($logfile); unlink($logfile);
upgrade_main($directory,$db_verbose,false,false,false,true,false,$force,false,false); upgrade_main( directory: $directory,
verbose: $db_verbose,
check_git: false,
do_git: false,
export_db: false,
check_db: true,
strict_db: false,
do_db: false,
force: $force,
connection: false,
origin: false
);
break; break;
case 'do_db_upgrade': case 'do_db_upgrade':
$this->app->Tpl->Set('UPGRADE_DB_VISIBLE', ""); $this->app->Tpl->Set('UPGRADE_DB_VISIBLE', "");
unlink($logfile); unlink($logfile);
upgrade_main($directory,$db_verbose,false,false,false,true,true,$force,false,false); upgrade_main( directory: $directory,
verbose: $db_verbose,
check_git: false,
do_git: false,
export_db: false,
check_db: true,
strict_db: false,
do_db: true,
force: $force,
connection: false,
origin: false
);
break; break;
case 'refresh': case 'refresh':
break; break;