From: Eden Cardim Date: Tue, 28 Feb 2012 12:23:57 +0000 (-0300) Subject: making config flags actually recognize config files X-Git-Tag: v0.08197~92 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7b71391b3;p=dbsrgits%2FDBIx-Class.git making config flags actually recognize config files --- diff --git a/Changes b/Changes index 5b196b2..71b24e4 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ Revision history for DBIx::Class - Allow complex update/delete operations on sources without a primary key, as long as they have at least one non-nullable unique constraint + - dbicadmin now better supports catalyst-style config files, by + unrolling 'config_info' hashkeys * Fixes - Fix SkipFirst and FirstSkip limit dialects (Informix and Firebird) @@ -24,6 +26,7 @@ Revision history for DBIx::Class - Fix more cases of $schema leakage in SQLT::Parser::DBIC - Remove useless vestigial pessimization in Ordered.pm for cases when the position column is part of a unique constraint + - Fix dbicadmin to no longer ignore the documented 'config' option * Misc - Centralized leak-checks for all instances of DBICTest::Schema diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 7a8c313..87beb08 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -348,6 +348,8 @@ dwc: Daniel Westermann-Clark dyfrgi: Michael Leuchtenburg +edenc: Eden Cardim + felliott: Fitz Elliott freetime: Bill Moseley diff --git a/lib/DBIx/Class/Admin.pm b/lib/DBIx/Class/Admin.pm index 0e2cf78..b0d76b8 100644 --- a/lib/DBIx/Class/Admin.pm +++ b/lib/DBIx/Class/Admin.pm @@ -167,7 +167,7 @@ sub _build_connect_info { config_file provide a config_file to read connect_info from, if this is provided config_stanze should also be provided to locate where the connect_info is in the config -The config file should be in a format readable by Config::General +The config file should be in a format readable by Config::Any. =cut @@ -579,6 +579,7 @@ sub _find_stanza { die ("Could not find $stanza in config, $path does not seem to exist.\n"); } } + $cfg = $cfg->{connect_info} if exists $cfg->{connect_info}; return $cfg; } diff --git a/script/dbicadmin b/script/dbicadmin index 10cd89f..e167ee4 100755 --- a/script/dbicadmin +++ b/script/dbicadmin @@ -44,14 +44,16 @@ my ($opts, $usage) = describe_options( ['op:s' => 'compatiblity option all of the above can be suppied as --op='], ['help' => 'display this help', { implies => { schema_class => '__dummy__' } } ], ['selfinject-pod' => 'hidden', { implies => { schema_class => '__dummy__' } } ], - ], required=> 1 }], + ], required => 1 }], ['Arguments'], + ["configuration" => hidden => { one_of => [ + ['config-file|config:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ], + ['connect-info:s%' => 'Supply the connect info as trailing options e.g. --connect-info dsn= user= password=' ], + ['connect:s' => 'Supply the connect info as a JSON-encoded structure, e.g. an --connect=["dsn","user","pass"]'], + ], required => 1 }], ['schema-class:s' => 'The class of the schema to load', { required => 1 } ], - ['resultset|resultset-class|class:s' => 'The resultset to operate on for data manipulation' ], ['config-stanza:s' => 'Where in the config to find the connection_info, supply in form MyApp::Model::DB',], - ['config:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ], - ['connect-info:s%' => 'Supply the connect info as additional options ie -I dsn= user= password= '], - ['connect:s' => 'Supply the connect info as a json string' ], + ['resultset|resultset-class|class:s' => 'The resultset to operate on for data manipulation' ], ['sql-dir:s' => 'The directory where sql diffs will be created'], ['sql-type:s' => 'The RDBMs flavour you wish to use'], ['version:i' => 'Supply a version install'], @@ -66,8 +68,6 @@ my ($opts, $usage) = describe_options( ) ); -die "please only use one of --config or --connect-info\n" if ($opts->{config} and $opts->{connect_info}); - if($opts->{selfinject_pod}) { die "This is an internal method, do not call!!!\n" @@ -98,9 +98,11 @@ if($opts->{help}) { } # option compatability mangle +# (can not be joined in the spec, one is s% the other is s) if($opts->{connect}) { $opts->{connect_info} = delete $opts->{connect}; } + my $admin = DBIx::Class::Admin->new( %$opts ); my $action = $opts->{action}; diff --git a/t/admin/10script.t b/t/admin/10script.t index abcd2f9..ce3d27e 100644 --- a/t/admin/10script.t +++ b/t/admin/10script.t @@ -16,19 +16,27 @@ BEGIN { } my @json_backends = qw/XS JSON DWIW/; -my $tests_per_run = 5; -plan tests => ($tests_per_run * @json_backends) + 1; - # test the script is setting @INC properly -test_exec (qw| -It/lib/testinclude --schema=DBICTestAdminInc --insert --connect=[] |); +test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|); cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' ); +# test that config works properly +{ + no warnings 'qw'; + test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|); + cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit; +} + +# test that config-file works properly +test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|); +cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig'); + for my $js (@json_backends) { eval {JSON::Any->import ($js) }; SKIP: { - skip ("JSON backend $js is not available, skip testing", $tests_per_run) if $@; + skip ("JSON backend $js is not available, skip testing", 1) if $@; $ENV{JSON_ANY_ORDER} = $js; eval { test_dbicadmin () }; @@ -36,6 +44,8 @@ for my $js (@json_backends) { } } +done_testing(); + sub test_dbicadmin { my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run diff --git a/t/lib/admincfgtest.json b/t/lib/admincfgtest.json new file mode 100644 index 0000000..e499423 --- /dev/null +++ b/t/lib/admincfgtest.json @@ -0,0 +1,11 @@ +{ + "Model" : { + "Gort" : { + "connect_info" : [ + "klaatu", + "barada", + "nikto" + ] + } + } +} diff --git a/t/lib/testinclude/DBICTestConfig.pm b/t/lib/testinclude/DBICTestConfig.pm new file mode 100644 index 0000000..10f0b7f --- /dev/null +++ b/t/lib/testinclude/DBICTestConfig.pm @@ -0,0 +1,15 @@ +package DBICTestConfig; +use base 'DBIx::Class::Schema'; + +sub connect { + my($self, @opt) = @_; + @opt == 4 + and $opt[0] eq 'klaatu' + and $opt[1] eq 'barada' + and $opt[2] eq 'nikto' + and $opt[3]->{ignore_version} + and exit 71; # this is what the test will expect to see + exit 1; +} + +1;