# database will be dropped & created before any other test is run. The
# following parameters must be given:
[testing/database]
-host = localhost
-port = 5432
-db =
-user = postgres
-password =
-template = template1
+host = localhost
+port = 5432
+db =
+user = postgres
+password =
+template = template1
+superuser_user = postgres
+superuser_password =
[devel]
# Several settings related to the development of kivitendo.
use SL::LxOfficeConf;
use Support::TestSetup;
-our ($db_cfg, $dbh);
+our ($db_cfg, $dbh, $superuser_dbh);
sub dbg {
# diag(@_);
sub report_success {
$dbh->disconnect;
+ $superuser_dbh->disconnect if $superuser_dbh;
ok(1, "Database has been setup sucessfully.");
done_testing();
}
dbg("Applying $file");
- my $error = $dbupdater->process_file($dbh, $file, $control);
+ my $script_dbh = $control && $control->{superuser_privileges} ? ($superuser_dbh // $dbh) : $dbh;
+ my $error = $dbupdater->process_file($script_dbh, $file, $control);
BAIL_OUT("Error applying $file: $error") if $error;
}
my $dbupdater = SL::DBUpgrade2->new(form => $::form, return_on_error => 1, silent => 1);
my $coa = 'Germany-DATEV-SKR03EU';
+ if ($db_cfg->{superuser_user} && ($db_cfg->{superuser_user} ne $db_cfg->{user})) {
+ @dbi_options = (
+ 'dbi:Pg:dbname=' . $db_cfg->{db} . ';host=' . $db_cfg->{host} . ';port=' . $db_cfg->{port},
+ $db_cfg->{superuser_user},
+ $db_cfg->{superuser_password},
+ SL::DBConnect->get_options(PrintError => 0, PrintWarn => 0),
+ );
+
+ $superuser_dbh = SL::DBConnect->connect(@dbi_options) || BAIL_OUT("Database superuser connection failed: " . $DBI::errstr);
+ }
+
apply_dbupgrade($dbupdater, "sql/lx-office.sql");
apply_dbupgrade($dbupdater, "sql/${coa}-chart.sql");