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