-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/perl | ||
use lib 'lib'; | ||
|
||
BEGIN { | ||
|
||
package OpenNewsWire::DB::Script; | ||
|
||
use OpenNewsWire::DB; | ||
use DBIx::Class::DeploymentHandler; | ||
|
||
use Moose; | ||
use MooseX::AttributeShortcuts; | ||
|
||
with 'MooseX::Getopt'; | ||
|
||
has connection_name => ( | ||
traits => [ 'Getopt' ], | ||
is => 'ro', | ||
isa => 'Str', | ||
required => 1, | ||
cmd_aliases => 'c', | ||
default => sub { 'ONW_DB' }, | ||
); | ||
|
||
has force => ( | ||
is => 'ro', isa => 'Bool', default => sub { 0 } | ||
); | ||
|
||
has _dh => (is => 'lazy'); | ||
|
||
sub _build__dh { | ||
my ($self) = @_; | ||
print $self->connection_name; | ||
DBIx::Class::DeploymentHandler->new({ | ||
schema => OpenNewsWire::DB->connect($self->connection_name), | ||
force_overwrite => $self->force, | ||
script_directory => 'share/ddl', | ||
databases => [ 'PostgreSQL' ], | ||
}); | ||
} | ||
|
||
sub cmd_write_ddl { | ||
my ($self) = @_; | ||
|
||
$self->_dh->prepare_install; | ||
|
||
my $v = $self->_dh->schema_version; | ||
|
||
if ($v > 1) { | ||
$self->_dh->prepare_upgrade({ from_version => $v-1, to_version => $v}); | ||
} | ||
} | ||
|
||
sub cmd_install { | ||
my ($self) = @_; | ||
|
||
$self->_dh->install; | ||
|
||
$self->_dh->schema->install_defaults; | ||
} | ||
|
||
sub cmd_upgrade { | ||
shift->_dh->upgrade; | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
|
||
my ($cmd, @what) = @{$self->extra_argv}; | ||
|
||
die "Must supply a command\n" unless $cmd; | ||
die "Extra argv detected - command only please\n" if @what; | ||
die "No such command ${cmd}\n" unless $self->can("cmd_${cmd}"); | ||
|
||
$self->${\"cmd_${cmd}"}; | ||
} | ||
|
||
} # end of BEGIN block | ||
|
||
OpenNewsWire::DB::Script->new_with_options->run; | ||
|
||
=head1 NOTES | ||
=cut |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
HNW_DB: | ||
ONW_DB: | ||
dsn: dbi:Pg:host=localhost;dbname=housenewswire | ||
user: housenewswire | ||
password: housenewswire |
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