Skip to content

Commit

Permalink
added stubs for database connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Aug 12, 2012
1 parent 73ea81f commit 46e9484
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bin/scenefinity_deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/perl
use strictures;

package scenefinity_deploy;

use Web::Scenefinity::Schema::Script;
Web::Scenefinity::Schema::Script->new_with_options->run;
9 changes: 8 additions & 1 deletion lib/Web/Scenefinity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ use HTTP::Tiny;
use Data::Dumper;
use YAML 'Load';
use List::Util qw( shuffle );
use Web::Scenefinity::Schema;
use File::Slurp 'read_file';

sub {
has $_ => ( is => 'lazy' ) for qw( config );
has $_ => ( is => 'lazy' ) for qw( db config );
}
->();

Expand All @@ -35,6 +36,12 @@ sub config_path {

sub _build_config { Load read_file( shift->config_path ) }

sub _build_db {
my ( $self ) = @_;
my $db = $self->config->{db};
my $schema = Web::Scenefinity::Schema->connect( $db );
return $schema;
}

sub dispatch_request {
(
Expand Down
11 changes: 11 additions & 0 deletions lib/Web/Scenefinity/Schema.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use strictures;

package Web::Scenefinity::Schema;
use base 'DBIx::Class::Schema::Config';

our $VERSION = 1;
__PACKAGE__->load_namespaces;

sub install_defaults {}

1;
73 changes: 73 additions & 0 deletions lib/Web/Scenefinity/Schema/Script.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use strictures;

package Web::Scenefinity::Schema::Script;

use Web::Scenefinity::Schema;
use DBIx::Class::DeploymentHandler;
use File::ShareDir::ProjectDistDir 'dist_dir';

use Moose;
use MooseX::AttributeShortcuts;

with 'MooseX::Getopt';

has connection_name => (
traits => ['Getopt'],
is => 'ro',
isa => 'Str',
required => 1,
cmd_aliases => 'c',
default => sub { 'development' },
);

has force => (
is => 'ro',
isa => 'Bool',
default => sub { 0 }
);

has _dh => ( is => 'lazy' );

sub _build__dh {
my ( $self ) = @_;
my $args = {
schema => Web::Scenefinity::Schema->connect( $self->connection_name ),
force_overwrite => $self->force,
script_directory => dist_dir( "Web-Scenefinity" ) . '/ddl',
databases => [ 'PostgreSQL', 'SQLite', 'MySQL' ],
};
DBIx::Class::DeploymentHandler->new( $args );
}

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 = shift;
$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}" };
}

1;

0 comments on commit 46e9484

Please sign in to comment.