forked from ledgersmb/LedgerSMB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport of 1.4 version of patch-release-upgrade.pl.
- Loading branch information
ehuelsmann
committed
Aug 17, 2014
1 parent
c59759b
commit b7679d0
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
use Getopt::Long; | ||
use LedgerSMB::Database; | ||
|
||
my $user; | ||
my $script_name = `basename $0`; chomp $script_name; | ||
my $usage = qq| | ||
usage: $script_name [ OPTION... ] database | ||
This script upgrades your database when moving from one patchlevel | ||
to another, e.g. 1.3.15 to 1.3.18. | ||
Options: | ||
--user <user> This option names the user to be used for logging in. | ||
The name of the current user is the default value. | ||
--help Prints this help screen. | ||
Note: | ||
If the user (implied or explicitly specified) requires a password, it | ||
will be asked for explicitly unless it's specified in an environment variable. | ||
This is to prevent passwords being saved into the history file. | ||
|; | ||
|
||
sub rebuild_modules { | ||
|
||
|
||
|
||
### Modified copy/paste from LedgerSMB/Scripts/setup.pm | ||
|
||
my $database = LedgerSMB::Database->new( | ||
{ | ||
username => $ENV{PGUSER}, | ||
company_name => $ENV{PGDATABASE}, | ||
password => $ENV{PGPASSWORD} | ||
}); | ||
|
||
$database->load_modules('LOADORDER'); | ||
$database->process_roles('Roles.sql'); | ||
|
||
my $dbh = DBI->connect( | ||
"dbi:Pg:dbname=$ENV{PGDATABASE}", | ||
$ENV{PGUSER}, $ENV{PGPASSWORD}, | ||
{ AutoCommit => 0, } | ||
); | ||
my $sth = $dbh->prepare( | ||
"UPDATE defaults SET value = ? WHERE setting_key = 'version'" | ||
); | ||
$sth->execute($LedgerSMB::VERSION); | ||
$dbh->commit; | ||
|
||
|
||
#### end of copied code | ||
|
||
return 1; | ||
}; | ||
|
||
|
||
sub usage { print $usage; exit; } | ||
|
||
|
||
GetOptions( | ||
'help' => \&usage, | ||
'user=s' => \$user, | ||
); | ||
|
||
if (scalar(@ARGV) != 1) { | ||
my $argnum = scalar(@ARGV); | ||
print STDERR "$script_name: Incorrect number of arguments ($argnum found; 1 expected)"; | ||
&usage; | ||
} | ||
|
||
$ENV{PGUSER} = $user if $user; | ||
$ENV{PGDATABASE} = $ARGV[0]; | ||
&rebuild_modules; | ||
|
||
|
||
print "Database upgraded to $LedgerSMB::VERSION.\n"; | ||
exit 0; |