Skip to content

Commit

Permalink
DB changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
symkat committed Sep 17, 2021
1 parent 5d82e22 commit 9e2cced
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
87 changes: 87 additions & 0 deletions Database/bin/opennewswire-db-deploy
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
3 changes: 2 additions & 1 deletion Database/dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ copyright_holder = Kaitlyn Parkhurst
copyright_year = 2021
abstract = OpenNewsWire Database

version = 0.001
version = 1

[@Basic]

Expand All @@ -14,6 +14,7 @@ DBIx::Class::InflateColumn::Serializer = 0
DBIx::Class::Schema::Config = 0
DBIx::Class::DeploymentHandler = 0
MooseX::AttributeShortcuts = 0
MooseX::Getopt = 0
DBD::Pg = 0

[AutoPrereqs]
6 changes: 5 additions & 1 deletion Database/lib/OpenNewsWire/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ __PACKAGE__->load_namespaces;
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-06 15:34:11
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:R9/3GgzPrYil31aQ9mTKUw

our $VERSION = 1;

sub install_defaults {
my ( $self ) = @_;
}

# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;
2 changes: 1 addition & 1 deletion Web/dbic.yaml
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
2 changes: 1 addition & 1 deletion Web/lib/OpenNewsWire/Web/Model/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extends 'Catalyst::Model::DBIC::Schema';

__PACKAGE__->config(
schema_class => 'OpenNewsWire::DB',
connect_info => [ 'HNW_DB' ],
connect_info => [ 'ONW_DB' ],
);

__PACKAGE__->meta->make_immutable;

0 comments on commit 9e2cced

Please sign in to comment.