line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::CLI::DbDeploy::Command::saveschema; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
3
|
|
|
|
|
|
|
$Tapper::CLI::DbDeploy::Command::saveschema::VERSION = '5.0.6'; |
4
|
1
|
|
|
1
|
|
893
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
34
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use parent 'App::Cmd::Command'; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
11
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
75
|
use Tapper::Model 'model'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
12
|
1
|
|
|
1
|
|
27
|
use Tapper::CLI::DbDeploy; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
7
|
|
13
|
1
|
|
|
1
|
|
205
|
use Tapper::Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
14
|
1
|
|
|
1
|
|
4
|
use Data::Dumper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
496
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub opt_spec { |
17
|
|
|
|
|
|
|
return ( |
18
|
0
|
|
|
0
|
1
|
|
[ "verbose", "some more informational output" ], |
19
|
|
|
|
|
|
|
[ "really", "Really do something." ], |
20
|
|
|
|
|
|
|
[ "db=s", "STRING, one of: ReportsDB, TestrunDB" ], |
21
|
|
|
|
|
|
|
[ "env=s", "STRING, default=development; one of: live, development, test" ], |
22
|
|
|
|
|
|
|
[ "upgradedir=s", "STRING, directory here upgradefiles are stored" ], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub abstract { |
27
|
0
|
|
|
0
|
1
|
|
'Save an initial database schema if no previous schema exists' |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub usage_desc |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
33
|
0
|
|
|
|
|
|
my $allowed_opts = join ' ', map { '--'.$_ } $self->_allowed_opts(); |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
"tapper-db-deploy saveschema --db=DBNAME [ --verbose | --env=s ]*"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _allowed_opts { |
38
|
0
|
|
|
0
|
|
|
my ($self, $opt, $args) = @_; |
39
|
0
|
|
|
|
|
|
my @allowed_opts = map { $_->[0] } $self->opt_spec(); |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub validate_args { |
43
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# print "opt = ", Dumper($opt); |
46
|
|
|
|
|
|
|
# print "args = ", Dumper($args); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $ok = 1; |
49
|
0
|
0
|
|
|
|
|
if (not $opt->{db}) |
|
|
0
|
|
|
|
|
|
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
|
|
|
say "Missing argument --db\n"; |
52
|
0
|
|
|
|
|
|
$ok = 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif (not $opt->{db} = 'TestrunDB') |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
|
|
|
say "Wrong DB name '".$opt->{db}."' (must be TestrunDB)"; |
57
|
0
|
|
|
|
|
|
$ok = 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
return $ok if $ok; |
61
|
0
|
|
|
|
|
|
die $self->usage->text; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub run |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
0
|
0
|
|
my ($self, $opt, $args) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
unless ($opt->{really}) { |
69
|
0
|
|
|
|
|
|
say "You nearly never want to call me -- only if no previous schema exists."; |
70
|
0
|
|
|
|
|
|
say "You probably want to call: tapper-db-deploy makeschemadiffs ..."; |
71
|
0
|
|
|
|
|
|
say "Or use option --really if you know what you do"; |
72
|
0
|
|
|
|
|
|
exit 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
local $DBIx::Class::Schema::Versioned::DBICV_DEBUG = 1; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
Tapper::Config::_switch_context($opt->{env}); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $db = $opt->{db}; |
80
|
0
|
|
|
|
|
|
my $upgradedir = $opt->{upgradedir}; |
81
|
0
|
0
|
|
|
|
|
model($db)->upgrade_directory($upgradedir) if $upgradedir; |
82
|
0
|
|
0
|
|
|
|
model($db)->create_ddl_dir([qw/MySQL SQLite PostgreSQL/], |
83
|
|
|
|
|
|
|
undef, |
84
|
|
|
|
|
|
|
($upgradedir || model($db)->upgrade_directory) |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# perl -Ilib bin/tapper-db-deploy saveschema --db=TestrunDB |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding UTF-8 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Tapper::CLI::DbDeploy::Command::saveschema |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software, licensed under: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |