Commit | Line | Data |
1efc6c6b |
1 | package Catalyst::Script::Deploy; |
2 | |
3 | use Moose; |
4 | use namespace::autoclean; |
5 | |
6 | with 'MooseX::Getopt'; |
4e45780e |
7 | use MooseX::Types::Moose qw/Str/; |
1efc6c6b |
8 | use Config::General; |
9 | use FindBin; |
10 | use lib "$FindBin::Bin/../lib"; |
11 | |
410d96eb |
12 | #extends qw(MooseX::App::Cmd); |
13 | |
14 | |
1efc6c6b |
15 | has _app => ( |
16 | reader => 'app', |
17 | init_arg => 'app', |
18 | traits => [qw(NoGetopt)], |
73e4f0f1 |
19 | isa => Str, |
1efc6c6b |
20 | is => 'ro', |
21 | ); |
22 | |
23 | has conf => ( |
24 | is => 'ro', |
73e4f0f1 |
25 | isa => Str, |
1efc6c6b |
26 | traits => [qw(Getopt)], |
27 | cmd_alias => 'c', |
d6e8e664 |
28 | documentation => qq{ specify a configuration file to read from } |
1efc6c6b |
29 | ); |
30 | |
1efc6c6b |
31 | sub usage { |
32 | |
d6e8e664 |
33 | print "usage: perl script/myapp_deploy_schema.pl myapp.conf\n"; |
1efc6c6b |
34 | exit; |
35 | |
36 | } |
37 | |
38 | sub run { |
39 | my ($self) = shift; |
40 | |
41 | $self->usage if $self->help; |
42 | |
43 | my $app = $self->app; |
44 | Class::MOP::load_class($app); |
45 | Class::MOP::load_class("$app::Schema"); |
46 | |
47 | my %hash = $conf->getall; |
48 | |
49 | my $schema = $app::Schema->connect( |
50 | $hash{"Model::$schema_name"}{connect_info}[0], |
51 | $hash{"Model::$schema_name"}{connect_info}[1], |
52 | $hash{"Model::$schema_name"}{connect_info}[2] |
53 | ); |
54 | $schema->deploy( { add_drop_tables => 1 } ); |
55 | |
56 | |
57 | } |
58 | |
1efc6c6b |
59 | __PACKAGE__->meta->make_immutable; |
60 | |
61 | 1; |
62 | |