use SL::LXDebug;
use SL::Layout::None;
use SL::LxOfficeConf;
+use Support::TestSetup;
-our ($db_cfg, $dbh);
+our ($db_cfg, $dbh, $superuser_dbh);
sub dbg {
# diag(@_);
$::lxdebug = LXDebug->new(target => LXDebug::STDERR_TARGET);
$::lxdebug->disable_sub_tracing;
$::locale = Locale->new($::lx_office_conf{system}->{language});
- $::form = Form->new;
+ $::form = Support::TestSetup->create_new_form;
$::auth = SL::Auth->new(unit_tests_database => 1);
$::locale = Locale->new('de');
$::instance_conf = SL::InstanceConfiguration->new;
sub report_success {
$dbh->disconnect;
- ok(1, "Database has been setup sucessfully.");
+ $superuser_dbh->disconnect if $superuser_dbh;
+ ok(1, "Database has been set up successfully.");
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");