Reputation: 5203
I've been building Catalyst apps lately and one thing I love is using Catalyst's create script to easily generate the table schemas for DBIx::Class. I'd like to be able to use DBIX::Class without having to write the schemas for my tables manually. Is there a way to do this without doing it by hand? Thanks!
Upvotes: 0
Views: 434
Reputation: 3294
#!/usr/bin/env perl
use Modern::Perl;
use DBIx::Class::Schema::Loader 'make_schema_at';
my $DEBUG = @ARGV and $ARGV[0] =~ /^\-[\-]*v/;
say $DBIx::Class::Schema::Loader::VERSION if $DEBUG;
my @dsn = 'dbi:Pg:dbname=yourDB.db';
my $options = {
debug => $DEBUG,
dump_directory => 'lib',
components => [qw/ InflateColumn::DateTime /],
generate_pod => 0,
};
make_schema_at(Schema => $options, \@dsn);
=head1 NAME
generate_dbic_schema
=head1 USAGE
perl generate_dbic_schema
=cut
Upvotes: 0
Reputation: 2204
The other, more generic module that supports that is SQL::Translator.
Upvotes: 0
Reputation: 74252
DBIx::Class::Schema::Loader
's dbicdump
script can be used for dumping schema. An example from the documentation:
dbicdump -o dump_directory=./lib \
-o components='["InflateColumn::DateTime"]' \
-o debug=1 \
My::Schema \
'dbi:Pg:dbname=foo' \
myuser \
mypassword
Upvotes: 5