This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/script/make_schema

84 lines
1.9 KiB
Text
Raw Permalink Normal View History

2017-02-24 19:27:43 +00:00
#! /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,
],
);