|
Lines 25-39
use DBIx::Class::Schema::Loader qw/ make_schema_at /;
Link Here
|
| 25 |
use Getopt::Long; |
25 |
use Getopt::Long; |
| 26 |
use Pod::Usage; |
26 |
use Pod::Usage; |
| 27 |
|
27 |
|
| 28 |
my $path = "./"; |
28 |
my ($path, $db_driver, $db_host, $db_port, $db_name, $db_user, $db_passwd, $tablename, $help); |
| 29 |
my $db_driver = 'mysql'; |
29 |
|
| 30 |
my $db_host = 'localhost'; |
30 |
#Get defaults if exists ~/.my.cnf |
| 31 |
my $db_port = '3306'; |
31 |
defaultFromMyCnf(); |
| 32 |
my $db_name; |
32 |
|
| 33 |
my $db_user; |
33 |
$path = "./" unless $path; |
| 34 |
my $db_passwd; |
34 |
$db_driver = 'mysql' unless $db_driver; |
| 35 |
my $tablename; |
35 |
$db_host = 'localhost' unless $db_host; |
| 36 |
my $help; |
36 |
$db_port = '3306' unless $db_port; |
| 37 |
|
37 |
|
| 38 |
GetOptions( |
38 |
GetOptions( |
| 39 |
"path=s" => \$path, |
39 |
"path=s" => \$path, |
|
Lines 53-69
pod2usage(1) if defined $help;
Link Here
|
| 53 |
if (! defined $db_name ) { |
53 |
if (! defined $db_name ) { |
| 54 |
print "Error: \'db_name\' parameter is mandatory.\n"; |
54 |
print "Error: \'db_name\' parameter is mandatory.\n"; |
| 55 |
pod2usage(1); |
55 |
pod2usage(1); |
| 56 |
} else { |
56 |
} |
| 57 |
my $options = { debug => 1, dump_directory => $path, preserve_case => 1 }; |
57 |
|
| 58 |
if ($tablename) { |
58 |
|
| 59 |
$options->{constraint} = qr/\A$tablename\z/ |
59 |
my $options = { debug => 1, dump_directory => $path, preserve_case => 1 }; |
| 60 |
} |
60 |
if ($tablename) { |
| 61 |
|
61 |
$options->{constraint} = qr/\A$tablename\z/ |
| 62 |
make_schema_at( |
62 |
} |
| 63 |
"Koha::Schema", |
63 |
|
| 64 |
$options, |
64 |
make_schema_at( |
| 65 |
["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ] |
65 |
"Koha::Schema", |
| 66 |
); |
66 |
$options, |
|
|
67 |
["DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",$db_user, $db_passwd ] |
| 68 |
); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
sub defaultFromMyCnf { |
| 75 |
my $c = _parseMyCnf(); |
| 76 |
return unless $c; |
| 77 |
$db_user = $c->{'client.user'} unless $db_user; |
| 78 |
$db_host = $c->{'client.host'} unless $db_host; |
| 79 |
$db_port = $c->{'client.port'} unless $db_port; |
| 80 |
$db_name = $c->{'client.database'} unless $db_name; |
| 81 |
$db_passwd = $c->{'client.password'} unless $db_passwd; |
| 82 |
$db_driver = 'mysql' unless $db_driver; |
| 83 |
} |
| 84 |
sub _parseMyCnf { |
| 85 |
use Config::Simple; |
| 86 |
my %c; |
| 87 |
my $home = `echo ~`; |
| 88 |
chomp $home; |
| 89 |
return undef unless $home; |
| 90 |
Config::Simple->import_from("$home/.my.cnf", \%c); |
| 91 |
return \%c; |
| 67 |
} |
92 |
} |
| 68 |
|
93 |
|
| 69 |
1; |
94 |
1; |
|
Lines 117-120
path into which create the schema files. (defaults to './')
Link Here
|
| 117 |
|
142 |
|
| 118 |
prints this help text |
143 |
prints this help text |
| 119 |
|
144 |
|
| 120 |
=back |
145 |
=back |
| 121 |
- |
|
|