mirror of
https://github.com/dani/vroom.git
synced 2024-06-26 17:43:29 +02:00
Add a script skeleton to update the database
This commit is contained in:
parent
eff9565144
commit
2b861dba96
|
@ -4,7 +4,10 @@ use strict;
|
|||
use warnings;
|
||||
use base 'Exporter';
|
||||
|
||||
our @EXPORT = qw/COMPONENTS MOH JS_STRINGS API_ACTIONS/;
|
||||
our @EXPORT = qw/DB_VERSION COMPONENTS MOH JS_STRINGS API_ACTIONS/;
|
||||
|
||||
# Database version
|
||||
use constant DB_VERSION => 1;
|
||||
|
||||
# Components used to generate the credits part
|
||||
use constant COMPONENTS => {
|
||||
|
|
60
scripts/db_upgrade.pl
Normal file
60
scripts/db_upgrade.pl
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Basename;
|
||||
use lib dirname($0) . '/../lib';
|
||||
use DBI;
|
||||
use Config::Simple;
|
||||
use Vroom::Constants;
|
||||
use utf8;
|
||||
|
||||
|
||||
# Load and parse global config file
|
||||
my $cfg = new Config::Simple();
|
||||
$cfg->read(dirname($0) . '/../conf/settings.ini');
|
||||
my $config = $cfg->vars();
|
||||
|
||||
# Open a handle to the database server
|
||||
my $dbh = DBI->connect(
|
||||
$config->{'database.dsn'},
|
||||
$config->{'database.user'},
|
||||
$config->{'database.password'},
|
||||
{
|
||||
mysql_enable_utf8 => 1,
|
||||
PrintError => 0,
|
||||
RaiseError => 1,
|
||||
ShowErrorStatement => 1,
|
||||
}
|
||||
) || die "Cannot connect to the database: " . DBI->errstr . "\n";
|
||||
|
||||
# Check current schema version
|
||||
my $sth = eval {
|
||||
$dbh->prepare('SELECT `value`
|
||||
FROM `config`
|
||||
WHERE `key`=\'schema_version\'');
|
||||
};
|
||||
if ($@){
|
||||
die "DB Error: $@\n";
|
||||
}
|
||||
$sth->execute;
|
||||
if ($sth->err){
|
||||
die "DB Error: " . $sth->errstr . " (code: " . $sth->err . ")\n";
|
||||
}
|
||||
my $cur_ver;
|
||||
$sth->bind_columns(\$cur_ver);
|
||||
$sth->fetch;
|
||||
|
||||
print "Current version is $cur_ver\n";
|
||||
|
||||
if ($cur_ver > Vroom::Constants::DB_VERSION){
|
||||
die "Database version is unknown, sorry (current version is $cur_ver when it should be " .
|
||||
Vroom::Constants::DB_VERSION . ")\n";
|
||||
}
|
||||
|
||||
if ($cur_ver == Vroom::Constants::DB_VERSION){
|
||||
print "Database is up to date, nothing to do\n";
|
||||
exit 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user