line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
1431
|
use 5.010001; |
|
2
|
|
|
|
|
4
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
101
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
6
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.6'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
90
|
use FindBin; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
134
|
|
10
|
2
|
|
|
2
|
|
1014
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
1181
|
|
|
2
|
|
|
|
|
14
|
|
11
|
2
|
|
|
2
|
|
227
|
use Narada; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
12
|
2
|
|
|
2
|
|
7
|
use Narada::Config qw( get_config_line get_db_config ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
16
|
|
13
|
2
|
|
|
2
|
|
256
|
use DBI; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
76
|
|
14
|
2
|
|
|
2
|
|
8
|
use Path::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
110
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
10
|
use constant IS_NARADA => Narada::detect() eq 'narada'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
9
|
|
17
|
2
|
|
|
2
|
|
10
|
use constant CONFIG_DIR => IS_NARADA ? 'mysql' : 'db'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
91
|
|
18
|
2
|
|
|
2
|
|
7
|
use constant SQL_DIR => IS_NARADA ? 'var/mysql' : 'var/sql'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
104
|
|
19
|
2
|
|
|
2
|
|
7
|
use constant SCHEME => SQL_DIR.'/db.scheme.sql'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
939
|
|
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__ |