7 dbicdump - Dump a schema using DBIx::Class::Schema::Loader
11 dbicdump <configuration_file>
12 dbicdump [-I <lib-path>] [-o <loader_option>=<value> ] \
13 <schema_class> <connect_info>
17 $ dbicdump schema.conf
19 $ dbicdump -o dump_directory=./lib \
20 -o components='["InflateColumn::DateTime"]' \
21 MyApp::Schema dbi:SQLite:./foo.db
23 $ dbicdump -o dump_directory=./lib \
24 -o components='["InflateColumn::DateTime"]' \
25 MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
27 $ dbicdump -Ilib -o dump_directory=./lib \
28 -o components='["InflateColumn::DateTime"]' \
30 MyApp::Schema dbi:mysql:database=foo user pass '{ quote_char => "`" }'
32 $ dbicdump -o dump_directory=./lib \
33 -o components='["InflateColumn::DateTime"]' \
34 MyApp::Schema 'dbi:mysql:database=foo;host=domain.tld;port=3306' user pass
36 On Windows that would be:
38 $ dbicdump -o dump_directory=.\lib ^
39 -o components="[q{InflateColumn::DateTime}]" ^
41 MyApp::Schema dbi:mysql:database=foo user pass "{ quote_char => q{`} }"
43 Configuration files must have schema_class and connect_info sections,
44 an example of a general config file is as follows:
46 schema_class MyApp::Schema
60 components InflateColumn::DateTime
64 Using a config file requires L<Config::Any> installed.
66 The optional C<lib> key is equivalent to the C<-I> option.
70 Dbicdump generates a L<DBIx::Class> schema using
71 L<DBIx::Class::Schema::Loader/make_schema_at> and dumps it to disk.
73 You can pass any L<DBIx::Class::Schema::Loader::Base> constructor option using
74 C<< -o <option>=<value> >>. For convenience, option names will have C<->
75 replaced with C<_> and values that look like references or quote-like
76 operators will be C<eval>-ed before being passed to the constructor.
78 The C<dump_directory> option defaults to the current directory if not
83 L<DBIx::Class::Schema::Loader>, L<DBIx::Class>.
87 Dagfinn Ilmari Mannsåker C<< <ilmari@ilmari.org> >>
91 Caelum: Rafael Kitover <rkitover@cpan.org>
93 alnewkirk: Al Newkirk <awncorp@cpan.org>
97 This program is free software; you can redistribute it and/or modify it
98 under the same terms as Perl itself.
106 use DBIx::Class::Schema::Loader 'make_schema_at';
107 use namespace::clean;
108 use DBIx::Class::Schema::Loader::Base ();
109 use DBIx::Class::Schema::Loader::Optional::Dependencies ();
114 Getopt::Long::Configure('gnu_getopt');
117 'I=s' => sub { shift; lib->import(shift) },
118 'loader-option|o=s%' => \&handle_option,
121 $loader_options->{dump_directory} ||= '.';
124 if (not DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('dbicdump_config')) {
125 die sprintf "You must install the following CPAN modules to use a config file with dbicdump: %s.\n",
126 DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('dbicdump_config');
129 my $configuration_file = shift @ARGV;
132 Config::Any->load_files( {
134 flatten_to_hash => 1,
135 files => [$configuration_file] } );
137 my $c = (values %$configurations)[0];
139 unless (keys %{$c->{connect_info}} && $c->{schema_class}) {
147 @libs = @{ $c->{lib} };
153 lib->import($_) for @libs;
155 my ($dsn, $user, $pass, $options) =
156 map { $c->{connect_info}->{$_} } qw/dsn user pass options/;
158 $c->{loader_options}->{dump_directory} ||=
159 $loader_options->{dump_directory};
163 $c->{loader_options} || {},
164 [ $dsn, $user, $pass, %{$options} ],
168 my ($schema_class, @loader_connect_info) = @ARGV
171 my $dsn = shift @loader_connect_info;
173 my ($user, $pass) = $dsn =~ /sqlite/i ? ('', '')
174 : splice @loader_connect_info, 0, 2;
176 my @extra_connect_info_opts = map parse_value($_), @loader_connect_info;
181 [ $dsn, $user, $pass, @extra_connect_info_opts ],
190 $value = eval $value if $value =~ /^\s*(?:sub\s*\{|q\w?\s*[^\w\s]|[[{])/;
196 my ($self, $key, $value) = @_;
199 die "Unknown option: $key\n"
200 unless DBIx::Class::Schema::Loader::Base->can($key);
202 $value = parse_value $value;
204 $loader_options->{$key} = $value;