Permalink
Browse files

added stubs for database connectivity

  • Loading branch information...
1 parent 73ea81f commit 46e9484f35029b4cf452a18b535bc21a65e5c2da @wchristian committed Aug 12, 2012
Showing with 99 additions and 1 deletion.
  1. +7 −0 bin/scenefinity_deploy
  2. +8 −1 lib/Web/Scenefinity.pm
  3. +11 −0 lib/Web/Scenefinity/Schema.pm
  4. +73 −0 lib/Web/Scenefinity/Schema/Script.pm
View
@@ -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;
View
@@ -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 );
}
->();
@@ -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 {
(
@@ -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;
@@ -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.