Skip to content

Commit 9e2cced

Browse files
committed
DB changes.
1 parent 5d82e22 commit 9e2cced

5 files changed

Lines changed: 96 additions & 4 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/perl
2+
use lib 'lib';
3+
4+
BEGIN {
5+
6+
package OpenNewsWire::DB::Script;
7+
8+
use OpenNewsWire::DB;
9+
use DBIx::Class::DeploymentHandler;
10+
11+
use Moose;
12+
use MooseX::AttributeShortcuts;
13+
14+
with 'MooseX::Getopt';
15+
16+
has connection_name => (
17+
traits => [ 'Getopt' ],
18+
is => 'ro',
19+
isa => 'Str',
20+
required => 1,
21+
cmd_aliases => 'c',
22+
default => sub { 'ONW_DB' },
23+
);
24+
25+
has force => (
26+
is => 'ro', isa => 'Bool', default => sub { 0 }
27+
);
28+
29+
has _dh => (is => 'lazy');
30+
31+
sub _build__dh {
32+
my ($self) = @_;
33+
print $self->connection_name;
34+
DBIx::Class::DeploymentHandler->new({
35+
schema => OpenNewsWire::DB->connect($self->connection_name),
36+
force_overwrite => $self->force,
37+
script_directory => 'share/ddl',
38+
databases => [ 'PostgreSQL' ],
39+
});
40+
}
41+
42+
sub cmd_write_ddl {
43+
my ($self) = @_;
44+
45+
$self->_dh->prepare_install;
46+
47+
my $v = $self->_dh->schema_version;
48+
49+
if ($v > 1) {
50+
$self->_dh->prepare_upgrade({ from_version => $v-1, to_version => $v});
51+
}
52+
}
53+
54+
sub cmd_install {
55+
my ($self) = @_;
56+
57+
$self->_dh->install;
58+
59+
$self->_dh->schema->install_defaults;
60+
}
61+
62+
sub cmd_upgrade {
63+
shift->_dh->upgrade;
64+
}
65+
66+
sub run {
67+
my ($self) = @_;
68+
69+
my ($cmd, @what) = @{$self->extra_argv};
70+
71+
die "Must supply a command\n" unless $cmd;
72+
die "Extra argv detected - command only please\n" if @what;
73+
die "No such command ${cmd}\n" unless $self->can("cmd_${cmd}");
74+
75+
$self->${\"cmd_${cmd}"};
76+
}
77+
78+
} # end of BEGIN block
79+
80+
OpenNewsWire::DB::Script->new_with_options->run;
81+
82+
=head1 NOTES
83+
84+
85+
86+
87+
=cut

Database/dist.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ copyright_holder = Kaitlyn Parkhurst
55
copyright_year = 2021
66
abstract = OpenNewsWire Database
77

8-
version = 0.001
8+
version = 1
99

1010
[@Basic]
1111

@@ -14,6 +14,7 @@ DBIx::Class::InflateColumn::Serializer = 0
1414
DBIx::Class::Schema::Config = 0
1515
DBIx::Class::DeploymentHandler = 0
1616
MooseX::AttributeShortcuts = 0
17+
MooseX::Getopt = 0
1718
DBD::Pg = 0
1819

1920
[AutoPrereqs]

Database/lib/OpenNewsWire/DB.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ __PACKAGE__->load_namespaces;
1717
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-09-06 15:34:11
1818
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:R9/3GgzPrYil31aQ9mTKUw
1919

20+
our $VERSION = 1;
21+
22+
sub install_defaults {
23+
my ( $self ) = @_;
24+
}
2025

21-
# You can replace this text with custom code or comments, and it will be preserved on regeneration
2226
1;

Web/dbic.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
HNW_DB:
1+
ONW_DB:
22
dsn: dbi:Pg:host=localhost;dbname=housenewswire
33
user: housenewswire
44
password: housenewswire

Web/lib/OpenNewsWire/Web/Model/DB.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extends 'Catalyst::Model::DBIC::Schema';
66

77
__PACKAGE__->config(
88
schema_class => 'OpenNewsWire::DB',
9-
connect_info => [ 'HNW_DB' ],
9+
connect_info => [ 'ONW_DB' ],
1010
);
1111

1212
__PACKAGE__->meta->make_immutable;

0 commit comments

Comments
 (0)