| author | Vincent Tondellier <tonton+hg@team1664.org> |
| Mon, 04 Aug 2014 14:51:09 +0200 | |
| changeset 30 | f65708dc1be1 |
| parent 24 | lib/CrashTest/Commands/setup.pm@b69b7aa98a1d |
| child 49 | c088af64f31f |
| permissions | -rw-r--r-- |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
1 |
# This program is free software: you can redistribute it and/or modify |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
2 |
# it under the terms of the GNU General Public License as published by |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
3 |
# the Free Software Foundation, either version 3 of the License, or |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
4 |
# (at your option) any later version. |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
5 |
# |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
6 |
# This program is distributed in the hope that it will be useful, |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
7 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
8 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
9 |
# GNU General Public License for more details. |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
10 |
# |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
11 |
# You should have received a copy of the GNU General Public License |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
12 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
13 |
|
|
30
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
14 |
package CrashTest::Commands::db; |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
15 |
use Mojo::Base 'Mojolicious::Command'; |
|
30
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
16 |
use v5.12; |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
17 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
18 |
use aliased 'DBIx::Class::DeploymentHandler' => 'DH'; |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
19 |
use CrashTest::Storage::Sql::Schema; |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
20 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
21 |
# Short description |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
22 |
has description => 'Setup database.'; |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
23 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
24 |
# Short usage message |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
25 |
has usage => <<EOF; |
|
30
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
26 |
Usage: APPLICATION db [OPTIONS] |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
27 |
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
28 |
create Create database |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
29 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
30 |
EOF |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
31 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
32 |
sub run {
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
33 |
my ($self, @args) = @_; |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
34 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
35 |
my $schema = CrashTest::Storage::Sql::Schema->connect($self->app->config->{Storage}->{DSN});
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
36 |
|
|
30
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
37 |
my $dhargs = {
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
38 |
schema => $schema, |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
39 |
script_directory => "$FindBin::Bin/dbicdh", |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
40 |
sql_translator_args => { add_drop_table => 0 },
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
41 |
force_overwrite => 0, |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
42 |
}; |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
43 |
|
|
30
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
44 |
if($args[0] eq "prepare") {
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
45 |
$dhargs->{force_overwrite} = 1;
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
46 |
my $dh = DH->new($dhargs); |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
47 |
$dh->prepare_install; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
48 |
# $dh->prepare_upgrade; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
49 |
} elsif($args[0] eq "create") {
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
50 |
my $dh = DH->new($dhargs); |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
51 |
$dh->install; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
52 |
# } elsif($args[0] eq "upgrade") {
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
53 |
# my $dh = DH->new($dhargs); |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
54 |
# $dh->upgrade; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
55 |
} else {
|
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
56 |
say "Invalid arguments"; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
57 |
exit 1; |
|
f65708dc1be1
Rename setup command to db
Vincent Tondellier <tonton+hg@team1664.org>
parents:
24
diff
changeset
|
58 |
} |
|
24
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
59 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
60 |
} |
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
61 |
|
|
b69b7aa98a1d
Add basic SQL Storage
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff
changeset
|
62 |
1; |