line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
1113
|
use 5.010001; |
|
2
|
|
|
|
|
5
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
32
|
|
5
|
2
|
|
|
2
|
|
5
|
use utf8; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.7'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
70
|
use FindBin; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
113
|
|
10
|
2
|
|
|
2
|
|
931
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
1050
|
|
|
2
|
|
|
|
|
11
|
|
11
|
2
|
|
|
2
|
|
186
|
use Narada; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
12
|
2
|
|
|
2
|
|
6
|
use Narada::Config qw( get_config_line get_db_config ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
13
|
2
|
|
|
2
|
|
210
|
use DBI; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
14
|
2
|
|
|
2
|
|
7
|
use Path::Tiny; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
80
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
6
|
use constant IS_NARADA => Narada::detect() eq 'narada'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
17
|
2
|
|
|
2
|
|
8
|
use constant CONFIG_DIR => IS_NARADA ? 'mysql' : 'db'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
78
|
|
18
|
2
|
|
|
2
|
|
6
|
use constant SQL_DIR => IS_NARADA ? 'var/mysql' : 'var/sql'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
19
|
2
|
|
|
2
|
|
6
|
use constant SCHEME => SQL_DIR.'/db.scheme.sql'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
696
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
main(@ARGV) if !caller; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
|
|
sub err { die "narada-setup-mysql: @_\n" } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub main { |
28
|
0
|
0
|
0
|
0
|
|
|
die "Usage: narada-setup-mysql [--clean]\n" |
|
|
|
0
|
|
|
|
|
29
|
|
|
|
|
|
|
if (@_ > 1) |
30
|
|
|
|
|
|
|
|| (@_ == 1 && $_[0] ne '--clean'); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
my $db = get_db_config() or return; |
33
|
|
|
|
|
|
|
$::dbh = DBI->connect($db->{dsn_nodb}, $db->{login}, $db->{pass}, |
34
|
0
|
0
|
|
|
|
|
{RaiseError=>1}) or err DBI->errstr; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if (@_) { |
37
|
0
|
|
|
|
|
|
path('var/use/mysql')->remove; |
38
|
0
|
|
|
|
|
|
$::dbh->do('DROP DATABASE IF EXISTS `'.$db->{db}.q{`}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
0
|
|
|
|
|
|
if (IS_NARADA) { |
42
|
0
|
|
|
|
|
|
path('var/use/mysql')->touch; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
$::dbh->do('CREATE DATABASE IF NOT EXISTS `'.$db->{db}.q{`}); |
45
|
0
|
|
|
|
|
|
$::dbh->do('USE `'.$db->{db}.q{`}); |
46
|
0
|
0
|
|
|
|
|
if (0 < $::dbh->prepare('SHOW TABLES')->execute()) { |
47
|
0
|
|
|
|
|
|
err 'SQL files not imported because database does not empty'; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
0
|
|
|
|
|
if (-f SCHEME) { |
50
|
0
|
|
|
|
|
|
import_sql(SCHEME); |
51
|
0
|
0
|
|
|
|
|
for (grep {-f && $_ ne SCHEME} glob SQL_DIR.'/*.sql') { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
import_sql($_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub import_sql { |
61
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
62
|
0
|
|
|
|
|
|
warn "Importing $file...\n"; |
63
|
0
|
0
|
|
|
|
|
system("narada-mysql <\Q$file\E") == 0 or err 'Failed to import '.$file; |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
69
|
|
|
|
|
|
|
__END__ |