5 dbicdump - Dump a schema using DBIx::Class::Schema::Loader
9 dbicdump <configuration_file>
10 dbicdump [-I <lib-path>] [-o <loader_option>=<value> ] \
11 <schema_class> <connect_info>
15 $ dbicdump schema.conf
17 $ dbicdump -o dump_directory=./lib \
18 -o components='["InflateColumn::DateTime"]' \
19 MyApp::Schema dbi:SQLite:./foo.db
21 $ dbicdump -o dump_directory=./lib \
22 -o components='["InflateColumn::DateTime"]' \
23 MyApp::Schema dbi:SQLite:./foo.db '{ quote_char => "\"" }'
25 $ dbicdump -Ilib -o dump_directory=./lib \
26 -o components='["InflateColumn::DateTime"]' \
28 MyApp::Schema dbi:mysql:database=foo user pass '{ quote_char => "`" }'
30 $ dbicdump -o dump_directory=./lib \
31 -o components='["InflateColumn::DateTime"]' \
32 MyApp::Schema 'dbi:mysql:database=foo;host=domain.tld;port=3306' user pass
34 On Windows that would be:
36 $ dbicdump -o dump_directory=.\lib ^
37 -o components="[q{InflateColumn::DateTime}]" ^
39 MyApp::Schema dbi:mysql:database=foo user pass "{ quote_char => q{`} }"
41 Configuration files must have schema_class and connect_info sections,
42 an example of a general config file is as follows:
44 schema_class MyApp::Schema
57 components InflateColumn::DateTime
61 Using a config file requires L<Config::Any> installed.
63 The optional C<lib> key is equivalent to the C<-I> option.
67 Dbicdump generates a L<DBIx::Class> schema using
68 L<DBIx::Class::Schema::Loader/make_schema_at> and dumps it to disk.
70 You can pass any L<DBIx::Class::Schema::Loader::Base> constructor option using
71 C<< -o <option>=<value> >>. For convenience, option names will have C<->
72 replaced with C<_> and values that look like references or quote-like
73 operators will be C<eval>-ed before being passed to the constructor.
75 The C<dump_directory> option defaults to the current directory if not
80 L<DBIx::Class::Schema::Loader>, L<DBIx::Class>.
84 Dagfinn Ilmari Manns?ker C<< <ilmari@ilmari.org> >>
88 Caelum: Rafael Kitover <rkitover@cpan.org>
90 alnewkirk: Al Newkirk <awncorp@cpan.org>
94 This program is free software; you can redistribute it and/or modify it
95 under the same terms as Perl itself.
103 use DBIx::Class::Schema::Loader 'make_schema_at';
104 use namespace::clean;
105 use DBIx::Class::Schema::Loader::Base ();
106 use DBIx::Class::Schema::Loader::Optional::Dependencies ();
111 Getopt::Long::Configure('gnu_getopt');
114 'I=s' => sub { shift; lib->import(shift) },
115 'loader-option|o=s%' => \&handle_option,
118 $loader_options->{dump_directory} ||= '.';
121 if (not DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('dbicdump_config')) {
122 die sprintf "You must install the following CPAN modules to use a config file with dbicdump: %s.\n",
123 DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('dbicdump_config');
126 my $configuration_file = shift @ARGV;
129 Config::Any->load_files( {
131 flatten_to_hash => 1,
132 files => [$configuration_file] } );
134 my $c = (values %$configurations)[0];
136 unless (keys %{$c->{connect_info}} && $c->{schema_class}) {
144 @libs = @{ $c->{lib} };
150 lib->import($_) for @libs;
152 my ($dsn, $user, $pass, $options) =
153 map { $c->{connect_info}->{$_} } qw/dsn user pass options/;
155 $c->{loader_options}->{dump_directory} ||=
156 $loader_options->{dump_directory};
160 $c->{loader_options} || {},
161 [ $dsn, $user, $pass, %{$options} ],
165 my ($schema_class, @loader_connect_info) = @ARGV
168 my $dsn = shift @loader_connect_info;
170 my ($user, $pass) = $dsn =~ /sqlite/i ? ('', '')
171 : splice @loader_connect_info, 0, 2;
173 my @extra_connect_info_opts = map parse_value($_), @loader_connect_info;
178 [ $dsn, $user, $pass, @extra_connect_info_opts ],
187 $value = eval $value if $value =~ /^\s*(?:sub\s*\{|q\w?\s*[^\w\s]|[[{])/;
193 my ($self, $key, $value) = @_;
196 die "Unknown option: $key\n"
197 unless DBIx::Class::Schema::Loader::Base->can($key);
199 $value = parse_value $value;
201 $loader_options->{$key} = $value;