upgrade added external connection option, optimized db_schema.json (views now with brackets around expressions)

This commit is contained in:
OpenXE 2022-12-09 07:13:12 +00:00
parent 68554f91c1
commit 3ea5c0e478
4 changed files with 47 additions and 21 deletions

View File

@ -114243,17 +114243,17 @@
{ {
"name": "belege", "name": "belege",
"type": "VIEW", "type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belege` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe` from `rechnung` where `rechnung`.`status` <> 'angelegt' union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe` from `gutschrift` where `gutschrift`.`status` <> 'angelegt'" "Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belege` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe` from `rechnung` where (`rechnung`.`status` <> 'angelegt') union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,(`gutschrift`.`umsatz_netto` * -(1)) AS `umsatz_netto*-1`,(`gutschrift`.`erloes_netto` * -(1)) AS `erloes_netto*-1`,(`gutschrift`.`deckungsbeitrag` * -(1)) AS `deckungsbeitrag*-1`,(`gutschrift`.`provision_summe` * -(1)) AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe` from `gutschrift` where (`gutschrift`.`status` <> 'angelegt')"
}, },
{ {
"name": "belegegesamt", "name": "belegegesamt",
"type": "VIEW", "type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegegesamt` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`soll` AS `umsatz_brutto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`soll` * -1 AS `umsatz_brutto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift` union all select `auftrag`.`id` AS `id`,`auftrag`.`adresse` AS `adresse`,`auftrag`.`datum` AS `datum`,`auftrag`.`belegnr` AS `belegnr`,`auftrag`.`status` AS `status`,`auftrag`.`land` AS `land`,'auftrag' AS `typ`,`auftrag`.`umsatz_netto` AS `umsatz_netto`,`auftrag`.`gesamtsumme` AS `umsatz_brutto`,`auftrag`.`erloes_netto` AS `erloes_netto`,`auftrag`.`deckungsbeitrag` AS `deckungsbeitrag`,`auftrag`.`provision_summe` AS `provision_summe`,`auftrag`.`vertriebid` AS `vertriebid`,`auftrag`.`gruppe` AS `gruppe`,`auftrag`.`projekt` AS `projekt` from `auftrag` union all select `bestellung`.`id` AS `id`,`bestellung`.`adresse` AS `adresse`,`bestellung`.`datum` AS `datum`,`bestellung`.`belegnr` AS `belegnr`,`bestellung`.`status` AS `status`,`bestellung`.`land` AS `land`,'bestellung' AS `typ`,`bestellung`.`gesamtsumme` AS `umsatz_netto`,`bestellung`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`bestellung`.`projekt` AS `projekt` from `bestellung` union all select `lieferschein`.`id` AS `id`,`lieferschein`.`adresse` AS `adresse`,`lieferschein`.`datum` AS `datum`,`lieferschein`.`belegnr` AS `belegnr`,`lieferschein`.`status` AS `status`,`lieferschein`.`land` AS `land`,'lieferschein' AS `typ`,'0' AS `umsatz_netto`,'0' AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`lieferschein`.`projekt` AS `projekt` from `lieferschein` union all select `angebot`.`id` AS `id`,`angebot`.`adresse` AS `adresse`,`angebot`.`datum` AS `datum`,`angebot`.`belegnr` AS `belegnr`,`angebot`.`status` AS `status`,`angebot`.`land` AS `land`,'angebot' AS `typ`,`angebot`.`umsatz_netto` AS `umsatz_netto`,`angebot`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,`angebot`.`deckungsbeitrag` AS `deckungsbeitrag`,'0' AS `provision_summe`,`angebot`.`vertriebid` AS `vertriebid`,'0' AS `gruppe`,`angebot`.`projekt` AS `projekt` from `angebot`" "Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegegesamt` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`soll` AS `umsatz_brutto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,(`gutschrift`.`umsatz_netto` * -(1)) AS `umsatz_netto*-1`,(`gutschrift`.`soll` * -(1)) AS `umsatz_brutto*-1`,(`gutschrift`.`erloes_netto` * -(1)) AS `erloes_netto*-1`,(`gutschrift`.`deckungsbeitrag` * -(1)) AS `deckungsbeitrag*-1`,(`gutschrift`.`provision_summe` * -(1)) AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift` union all select `auftrag`.`id` AS `id`,`auftrag`.`adresse` AS `adresse`,`auftrag`.`datum` AS `datum`,`auftrag`.`belegnr` AS `belegnr`,`auftrag`.`status` AS `status`,`auftrag`.`land` AS `land`,'auftrag' AS `typ`,`auftrag`.`umsatz_netto` AS `umsatz_netto`,`auftrag`.`gesamtsumme` AS `umsatz_brutto`,`auftrag`.`erloes_netto` AS `erloes_netto`,`auftrag`.`deckungsbeitrag` AS `deckungsbeitrag`,`auftrag`.`provision_summe` AS `provision_summe`,`auftrag`.`vertriebid` AS `vertriebid`,`auftrag`.`gruppe` AS `gruppe`,`auftrag`.`projekt` AS `projekt` from `auftrag` union all select `bestellung`.`id` AS `id`,`bestellung`.`adresse` AS `adresse`,`bestellung`.`datum` AS `datum`,`bestellung`.`belegnr` AS `belegnr`,`bestellung`.`status` AS `status`,`bestellung`.`land` AS `land`,'bestellung' AS `typ`,`bestellung`.`gesamtsumme` AS `umsatz_netto`,`bestellung`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`bestellung`.`projekt` AS `projekt` from `bestellung` union all select `lieferschein`.`id` AS `id`,`lieferschein`.`adresse` AS `adresse`,`lieferschein`.`datum` AS `datum`,`lieferschein`.`belegnr` AS `belegnr`,`lieferschein`.`status` AS `status`,`lieferschein`.`land` AS `land`,'lieferschein' AS `typ`,'0' AS `umsatz_netto`,'0' AS `umsatz_brutto`,'0' AS `erloes_netto`,'0' AS `deckungsbeitrag`,'0' AS `provision_summe`,'0' AS `vertriebid`,'0' AS `gruppe`,`lieferschein`.`projekt` AS `projekt` from `lieferschein` union all select `angebot`.`id` AS `id`,`angebot`.`adresse` AS `adresse`,`angebot`.`datum` AS `datum`,`angebot`.`belegnr` AS `belegnr`,`angebot`.`status` AS `status`,`angebot`.`land` AS `land`,'angebot' AS `typ`,`angebot`.`umsatz_netto` AS `umsatz_netto`,`angebot`.`gesamtsumme` AS `umsatz_brutto`,'0' AS `erloes_netto`,`angebot`.`deckungsbeitrag` AS `deckungsbeitrag`,'0' AS `provision_summe`,`angebot`.`vertriebid` AS `vertriebid`,'0' AS `gruppe`,`angebot`.`projekt` AS `projekt` from `angebot`"
}, },
{ {
"name": "belegeregs", "name": "belegeregs",
"type": "VIEW", "type": "VIEW",
"Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegeregs` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,`gutschrift`.`umsatz_netto` * -1 AS `umsatz_netto*-1`,`gutschrift`.`erloes_netto` * -1 AS `erloes_netto*-1`,`gutschrift`.`deckungsbeitrag` * -1 AS `deckungsbeitrag*-1`,`gutschrift`.`provision_summe` * -1 AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift`" "Create": "CREATE ALGORITHM=UNDEFINED DEFINER=`openxe`@`localhost` SQL SECURITY DEFINER VIEW `belegeregs` AS select `rechnung`.`id` AS `id`,`rechnung`.`adresse` AS `adresse`,`rechnung`.`datum` AS `datum`,`rechnung`.`belegnr` AS `belegnr`,`rechnung`.`status` AS `status`,`rechnung`.`land` AS `land`,'rechnung' AS `typ`,`rechnung`.`umsatz_netto` AS `umsatz_netto`,`rechnung`.`erloes_netto` AS `erloes_netto`,`rechnung`.`deckungsbeitrag` AS `deckungsbeitrag`,`rechnung`.`provision_summe` AS `provision_summe`,`rechnung`.`vertriebid` AS `vertriebid`,`rechnung`.`gruppe` AS `gruppe`,`rechnung`.`projekt` AS `projekt` from `rechnung` union all select `gutschrift`.`id` AS `id`,`gutschrift`.`adresse` AS `adresse`,`gutschrift`.`datum` AS `datum`,`gutschrift`.`belegnr` AS `belegnr`,`gutschrift`.`status` AS `status`,`gutschrift`.`land` AS `land`,'gutschrift' AS `typ`,(`gutschrift`.`umsatz_netto` * -(1)) AS `umsatz_netto*-1`,(`gutschrift`.`erloes_netto` * -(1)) AS `erloes_netto*-1`,(`gutschrift`.`deckungsbeitrag` * -(1)) AS `deckungsbeitrag*-1`,(`gutschrift`.`provision_summe` * -(1)) AS `provision_summe*-1`,`gutschrift`.`vertriebid` AS `vertriebid`,`gutschrift`.`gruppe` AS `gruppe`,`gutschrift`.`projekt` AS `projekt` from `gutschrift`"
} }
] ]
} }

View File

@ -94,6 +94,12 @@ if ($cli) {
$force = false; $force = false;
} }
if (in_array('-connection', $argv)) {
$connection = true;
} else {
$connection = false;
}
if (in_array('-s', $argv)) { if (in_array('-s', $argv)) {
$check_git = true; $check_git = true;
} else { } else {
@ -103,7 +109,7 @@ if ($cli) {
$check_db = true; $check_db = true;
} else { } else {
} }
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;
@ -118,7 +124,7 @@ if ($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); upgrade_main($directory,$verbose,$check_git,$do_git,$export_db,$check_db,$do_db,$force,$connection);
} else { } else {
info(); info();
} }
@ -130,21 +136,38 @@ if ($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) { 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) {
class DatabaseConnectionInfo { if ($connection) {
function __construct($dir) { $connection_file_name = $directory."/data/connection.json";
require($dir."/../conf/user.inc.php"); $connection_file_contents = file_get_contents($connection_file_name);
if (!$connection_file_contents) {
abort("Unable to load $connection_file_name");
return(-1);
}
$connection_info = json_decode($connection_file_contents, true);
$host = $connection_info['host'];
$user = $connection_info['user'];
$passwd = $connection_info['passwd'];
$schema = $connection_info['schema'];
} else {
class DatabaseConnectionInfo {
function __construct($dir) {
require($dir."/../conf/user.inc.php");
}
} }
$dbci = new DatabaseConnectionInfo($directory);
$host = $dbci->WFdbhost;
$user = $dbci->WFdbuser;
$passwd = $dbci->WFdbpass;
$schema = $dbci->WFdbname;
} }
$dbci = new DatabaseConnectionInfo($directory);
$host = $dbci->WFdbhost;
$user = $dbci->WFdbuser;
$passwd = $dbci->WFdbpass;
$schema = $dbci->WFdbname;
require_once($directory.'/../vendor/mustal/mustal_mysql_upgrade_tool.php'); require_once($directory.'/../vendor/mustal/mustal_mysql_upgrade_tool.php');
$datafolder = $directory."/data"; $datafolder = $directory."/data";
@ -435,6 +458,7 @@ function info() {
echo_out("\t-do: execute all upgrades\n"); echo_out("\t-do: execute all upgrades\n");
echo_out("\t-v: verbose output\n"); echo_out("\t-v: verbose output\n");
echo_out("\t-f: force override of existing files\n"); echo_out("\t-f: force override of existing files\n");
echo_out("\t-connection use connection.json in data folder instead of user.inc.php\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

@ -378,7 +378,7 @@ function mustal_compare_table_array(array $nominal, string $nominal_name, array
if ($found_view) { if ($found_view) {
if ($database_view['Create'] != $found_view['Create']) { if (trim($database_view['Create']) != trim($found_view['Create'])) {
$compare_difference = array(); $compare_difference = array();
$compare_difference['type'] = "View definition"; $compare_difference['type'] = "View definition";
$compare_difference[$nominal_name] = $database_view['name']; $compare_difference[$nominal_name] = $database_view['name'];

View File

@ -38,25 +38,27 @@ 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)
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("../upgrade",$verbose,true,false,true,false,$force); upgrade_main("../upgrade",$verbose,true,false,false,true,false,$force,false);
break; break;
case 'do_upgrade': case 'do_upgrade':
unlink($logfile); unlink($logfile);
upgrade_main("../upgrade",$verbose,true,true,true,true,$force); upgrade_main("../upgrade",$verbose,true,true,false,true,true,$force,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("../upgrade",$db_verbose,false,false,true,false,$force); upgrade_main("../upgrade",$db_verbose,false,false,false,true,false,$force,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("../upgrade",$db_verbose,false,false,true,true,$force); upgrade_main("../upgrade",$db_verbose,false,false,false,true,true,$force,false);
break; break;
case 'refresh': case 'refresh':
break; break;