Created
February 24, 2017 13:35
-
-
Save TBSliver/aa73c3f40bc5e5c9fa73053e26cfe280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env perl | |
use strict; | |
use warnings; | |
=head1 NAME | |
make_schema - Make or update a schema from the database | |
=cut | |
use Getopt::Long; | |
use Pod::Usage; | |
use FindBin qw/ $Bin /; | |
use DBIx::Class::Schema::Loader qw/ make_schema_at /; | |
my $username = ''; | |
my $password = ''; | |
my $connection; | |
my $schema = 'public'; | |
my $dbic_schema = 'MyApp::Schema'; | |
my $help = 0; | |
my $man = 0; | |
my $overwrite = 0; | |
my $verbose = 0; | |
GetOptions ( | |
"username|u=s" => \$username, | |
"password|p=s" => \$password, | |
"connection|c=s" => \$connection, | |
"schema|s=s" => \$schema, | |
"dbic|d=s" => \$dbic_schema, | |
"force" => \$overwrite, | |
"verbose" => \$verbose, | |
"help|?" => \$help, | |
"man" => \$man, | |
) or pod2usage(2); | |
pod2usage(0) if $help; | |
pod2usage(-exitval => 0, -verbose => 2) if $man; | |
pod2usage( | |
-message => "Must define a connection", | |
-exitval => 2, | |
) unless defined $connection; | |
=head1 SYNOPSIS | |
make_schema [--help|?] [--man] --connection|-c <connection string> [--user|-u <username>] [--pass|-p <password>] | |
Options: | |
--help Print Brief Help | |
--man Print Full Documentation | |
--connection The DBI connection string to use | |
--user [Optional] Username for the DBI connection | |
--pass [Optional] Password for the DBI connection | |
--schema [Optional - default 'public'] Schema to dump from | |
--dbic [Optional - default 'MyApp::Schema'] Package namespace for your DBIC Schema | |
--force [Optional] will overwrite modifications in the schema | |
--verbose [Optional] Print out all tables during processing | |
=cut | |
make_schema_at( | |
$dbic_schema, | |
{ | |
db_schema => $schema, | |
relationships => 1, | |
dump_directory => "$Bin/../lib", | |
debug => 1, | |
overwrite_modifications => $overwrite, | |
components => [qw/ | |
InflateColumn::DateTime | |
/], | |
}, | |
[ | |
$connection, | |
$username, | |
$password, | |
], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment