line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
930
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
42
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
5
|
2
|
|
|
2
|
|
9
|
use utf8; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.8'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
78
|
use FindBin; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
96
|
|
10
|
2
|
|
|
2
|
|
9
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
11
|
2
|
|
|
2
|
|
257
|
use Narada; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
12
|
2
|
|
|
2
|
|
8
|
use Narada::Config qw( get_config_line get_db_config ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
13
|
2
|
|
|
2
|
|
273
|
use DBI; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
87
|
|
14
|
2
|
|
|
2
|
|
10
|
use Path::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
82
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
20
|
use constant IS_NARADA => Narada::detect() eq 'narada'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
17
|
2
|
|
|
2
|
|
11
|
use constant CONFIG_DIR => IS_NARADA ? 'mysql' : 'db'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
18
|
2
|
|
|
2
|
|
9
|
use constant SQL_DIR => IS_NARADA ? 'var/mysql' : 'var/sql'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
19
|
2
|
|
|
2
|
|
9
|
use constant SCHEME => SQL_DIR.'/db.scheme.sql'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
759
|
|
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__ |