Commit | Line | Data |
1efc6c6b |
1 | package Catalyst::Script::Deploy; |
2 | |
3 | use Moose; |
4 | use namespace::autoclean; |
5 | |
6 | with 'MooseX::Getopt'; |
7 | use Config::General; |
8 | use FindBin; |
9 | use lib "$FindBin::Bin/../lib"; |
10 | |
11 | has _app => ( |
12 | reader => 'app', |
13 | init_arg => 'app', |
14 | traits => [qw(NoGetopt)], |
15 | isa => 'Str', |
16 | is => 'ro', |
17 | ); |
18 | |
19 | has conf => ( |
20 | is => 'ro', |
21 | isa => 'Str', |
22 | traits => [qw(Getopt)], |
23 | cmd_alias => 'c', |
d6e8e664 |
24 | documentation => qq{ specify a configuration file to read from } |
1efc6c6b |
25 | ); |
26 | |
27 | |
28 | |
29 | |
30 | |
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 | |
59 | no Moose; |
60 | __PACKAGE__->meta->make_immutable; |
61 | |
62 | 1; |
63 | |