-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_db.pl
executable file
·49 lines (44 loc) · 1.05 KB
/
update_db.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl -w -I.
use strict;
use Data::Dumper;
use RSSTootalizer::Migration;
use JSON;
sub Error {
my $headline = shift;
my $msg = shift;
print "$headline: $msg\n";
}
our $config = "";
open CONFIG, "rsstootalizer.conf.json" or die "Cannot open rsstootalizer.conf.json";
{
local $/ = undef;
$config = <CONFIG>;
}
close CONFIG;
$config = decode_json($config);
# Force Unicode output
binmode STDERR, ":utf8";
binmode STDOUT, ":utf8";
my @migrations = glob ("migrations/*sql");
foreach my $migration (@migrations){
my $sth = RSSTootalizer::DB->doSELECT("SELECT * FROM migrations WHERE name = ?", $migration);
if (scalar(@$sth) == 0){
print "Running migration $migration\n";
open (M, "<", $migration);
my $sql = "";
while (<M>){
chomp;
$sql .= $_;
if ($sql =~ /;/){
RSSTootalizer::DB->doDELETE($sql); # Using doDELETE for lack of error handling...
$sql = "";
}
}
close M;
my %migdata;
$migdata{name} = $migration;
RSSTootalizer::Migration->create(%migdata);
} else {
print "Migration $migration already done\n";
}
}