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;
SL::DBConnect->get_options,
);
- $::auth->reset;
my $dbh_template = SL::DBConnect->connect(@dbi_options) || BAIL_OUT("No database connection to the template database: " . $DBI::errstr);
my $auth_dbh = $::auth->dbconnect(1);
$auth_dbh->disconnect;
dbh_do($dbh_template, "DROP DATABASE \"" . $db_cfg->{db} . "\"", message => "Database could not be dropped");
-
- $::auth->reset;
}
dbg("Creating database");
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");
signature => '',
hide_cvar_search_options => '',
numberformat => '1.000,00',
- vclimit => 0,
favorites => '',
copies => '',
menustyle => 'v3',
dbh_do($dbh, $sth, bind => [ $_, $config{$_} ]) for sort keys %config;
$sth->finish;
- my $sth = $dbh->prepare(qq|INSERT INTO auth.group_rights (group_id, "right", granted) VALUES (1, ?, TRUE)|) || BAIL_OUT($dbh->errstr);
+ $sth = $dbh->prepare(qq|INSERT INTO auth.group_rights (group_id, "right", granted) VALUES (1, ?, TRUE)|) || BAIL_OUT($dbh->errstr);
dbh_do($dbh, $sth, bind => [ $_ ]) for sort $::auth->all_rights;
$sth->finish;