Commit | Line | Data |
9274250d |
1 | #!/usr/bin/perl |
a705b175 |
2 | |
a94aa524 |
3 | use strict; |
4 | use warnings; |
5 | |
fd27648a |
6 | use Getopt::Long::Descriptive; |
fd27648a |
7 | use DBIx::Class::Admin; |
8 | |
fd27648a |
9 | my ($opts, $usage) = describe_options( |
a705b175 |
10 | "%c: %o", |
11 | ( |
12 | ['Actions'], |
13 | ["action" => hidden => { one_of => [ |
14 | ['create|c' => 'Create version diffs needs preversion',], |
15 | ['upgrade|u' => 'Upgrade the database to the current schema '], |
16 | ['install|i' => 'Install the schema to the database',], |
71ef99d5 |
17 | ['deploy|d' => 'Deploy the schema to the database',], |
a705b175 |
18 | ['select|s' => 'Select data from the schema', ], |
19 | ['insert|i' => 'Insert data into the schema', ], |
20 | ['update|u' => 'Update data in the schema', ], |
21 | ['delete|D' => 'Delete data from the schema',], |
22 | ['op:s' => 'compatiblity option all of the above can be suppied as --op=<action>'], |
23 | ['help|h' => 'display this help'], |
24 | ], required=> 1 }], |
25 | ['Options'], |
26 | ['schema-class|schema|C:s' => 'The class of the schema to load', { required => 1 } ], |
27 | ['resultset|resultset_class|class|r:s' => 'The resultset to operate on for data manipulation' ], |
28 | ['config-stanza|S:s' => 'Where in the config to find the connection_info, supply in form MyApp::Model::DB',], |
29 | ['config|f:s' => 'Supply the config file for parsing by Config::Any', { depends => 'config_stanza'} ], |
30 | ['connect-info|n:s%' => 'Supply the connect info as additonal options ie -I dsn=<dsn> user=<user> password=<pass> '], |
31 | ['connect:s' => 'Supply the connect info as a json string' ], |
32 | ['sql-dir|q:s' => 'The directory where sql diffs will be created'], |
33 | ['sql-type|t:s' => 'The RDBMs flavour you wish to use'], |
34 | ['version|v:i' => 'Supply a version install'], |
35 | ['preversion|p:s' => 'The previous version to diff against',], |
36 | ['set:s' => 'JSON data used to perform data operations' ], |
37 | ['lib|I:s' => 'Additonal library path to search in'], |
38 | ['attrs:s' => 'JSON string to be used for the second argument for search'], |
39 | ['where:s' => 'JSON string to be used for the where clause of search'], |
40 | ['force' => 'Be forceful with some operations'], |
41 | ['trace' => 'Turn on DBIx::Class trace output'], |
a705b175 |
42 | ['quiet' => 'Be less verbose'], |
43 | ) |
2bbc85c9 |
44 | ); |
a94aa524 |
45 | |
ad81fe7d |
46 | die "please only use one of --config or --connect-info\n" if ($opts->{config} and $opts->{connect_info}); |
a94aa524 |
47 | |
fd27648a |
48 | # option compatability mangle |
49 | if($opts->{connect}) { |
a705b175 |
50 | $opts->{connect_info} = delete $opts->{connect}; |
b04e5d3e |
51 | } |
a94aa524 |
52 | |
fd27648a |
53 | my $admin = DBIx::Class::Admin->new( %$opts ); |
54 | |
55 | |
56 | my $action = $opts->{action}; |
c57f1cf7 |
57 | |
58 | $action = $opts->{op} if ($action eq 'op'); |
fd27648a |
59 | |
ad81fe7d |
60 | print "Performig action $action...\n"; |
61 | |
62 | my $res = $admin->$action(); |
fd27648a |
63 | if ($action eq 'select') { |
64 | |
a705b175 |
65 | my $format = $opts->{format} || 'tsv'; |
66 | die('Invalid format') if ($format!~/^tsv|csv$/s); |
a705b175 |
67 | |
ad81fe7d |
68 | require Text::CSV; |
69 | |
70 | my $csv = Text::CSV->new({ |
71 | sep_char => ( $format eq 'tsv' ? "\t" : ',' ), |
72 | }); |
73 | |
a705b175 |
74 | foreach my $row (@$res) { |
75 | $csv->combine( @$row ); |
76 | print $csv->string()."\n"; |
77 | } |
a94aa524 |
78 | } |
79 | |
d8d6276a |
80 | |
6717e3a8 |
81 | |
a94aa524 |
82 | =head1 AUTHOR |
83 | |
84 | Aran Deltac <bluefeet@cpan.org> |
85 | |
9274250d |
86 | refactored by |
fd27648a |
87 | Gordon Irving <goraxe@cpan.org> |
88 | |
a94aa524 |
89 | =head1 LICENSE |
90 | |
91 | You may distribute this code under the same terms as Perl itself. |