Last active
December 15, 2015 18:38
-
-
Save ynonp/5304930 to your computer and use it in GitHub Desktop.
install catalyst DB using config file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use v5.14; | |
package My::Script::Params; | |
use Moose; | |
with 'MooseX::Getopt'; | |
has 'app_pkg', is => 'rw', required => 1, isa => 'Str'; | |
has 'model', is => 'rw', isa => 'Str'; | |
has 'drop_tables', is => 'rw', default => 0; | |
has 'usage', is => 'rw', default => "Usage: $0 <Catalyst App Module> <DB Model>"; | |
package main; | |
use DBIx::Class::Migration; | |
my $app = My::Script::Params->new_with_options(); | |
my $app_pkg = $app->app_pkg; | |
my $model_name = $app->model; | |
eval "require $app_pkg"; | |
if ( ! $model_name ) { | |
my @candidates = grep { exists $app_pkg->config->{$_}->{schema_class} } | |
grep /^Model::/, keys %{$app_pkg->config}; | |
die "No model name specified and failed to guess one" | |
if @candidates != 1; | |
( $model_name ) = $candidates[0] =~ /^Model::(.*)/; | |
} | |
my $migration = DBIx::Class::Migration->new( | |
schema => $app_pkg->model( $model_name )->schema, | |
dbic_dh_args => { | |
force_overwrite => 1 | |
}, | |
%{$app_pkg->config->{extra_migration_init_args}} | |
); | |
$migration->drop_tables if $app->drop_tables; | |
$migration->install; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment