X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDeploymentHandler.pm;h=c06f124de2bb9231c8c2560c3feea74655567584;hb=d23c7c771d9f64d59bff4043b6493c795d9282af;hp=64202aafa26991da1c72dd543f85f6bd591952ce;hpb=6b826c6a3b15681ef22f9571da8f270796fac4ce;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 64202aa..c06f124 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -3,12 +3,8 @@ package DBIx::Class::DeploymentHandler; use Moose; use Method::Signatures::Simple; require DBIx::Class::Schema; # loaded for type constraint -require DBIx::Class::Storage; # loaded for type constraint require DBIx::Class::ResultSet; # loaded for type constraint use Carp::Clan '^DBIx::Class::DeploymentHandler'; -use SQL::Translator; -require SQL::Translator::Diff; -use Try::Tiny; with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod'; @@ -30,38 +26,20 @@ has schema => ( handles => [qw( ddl_filename schema_version )], ); -has upgrade_directory => ( +has upgrade_directory => ( # configuration isa => 'Str', is => 'ro', required => 1, default => 'sql', ); -has backup_directory => ( +has backup_directory => ( # configuration isa => 'Str', is => 'ro', predicate => 'has_backup_directory', ); -has storage => ( - isa => 'DBIx::Class::Storage', - is => 'ro', - lazy_build => 1, -); - -method _build_storage { - my $s = $self->schema->storage; - $s->_determine_driver; - $s -} - -has do_backup => ( - isa => 'Bool', - is => 'ro', - default => undef, -); - -has do_diff_on_init => ( +has do_backup => ( # configuration isa => 'Bool', is => 'ro', default => undef, @@ -79,49 +57,19 @@ method _build_version_rs { $self->schema->resultset('__VERSION') } -has databases => ( +has databases => ( # configuration coerce => 1, isa => 'DBIx::Class::DeploymentHandler::Databases', is => 'ro', default => sub { [qw( MySQL SQLite PostgreSQL )] }, ); -has sqltargs => ( +has sqltargs => ( # configuration isa => 'HashRef', is => 'ro', default => sub { {} }, ); -method deploy { - my $storage = $self->storage; - - my $deploy = sub { - my $line = shift; - return if(!$line || $line =~ /^--|^BEGIN TRANSACTION|^COMMIT|^\s+$/); - $storage->_query_start($line); - try { - # do a dbh_do cycle here, as we need some error checking in - # place (even though we will ignore errors) - $storage->dbh_do (sub { $_[1]->do($line) }); - } - catch { - carp "$_ (running '${line}')" - } - $storage->_query_end($line); - }; - my @statements = $self->deployment_statements(); - if (@statements > 1) { - foreach my $statement (@statements) { - $deploy->( $statement ); - } - } - elsif (@statements == 1) { - foreach my $line ( split(";\n", $statements[0])) { - $deploy->( $line ); - } - } -} - method install($new_version) { carp 'Install not possible as versions table already exists in database' if $self->is_installed; @@ -129,7 +77,7 @@ method install($new_version) { $new_version ||= $self->schema_version; if ($new_version) { - $self->deploy(); + $self->deploy; $self->version_rs->create({ version => $new_version, @@ -186,4 +134,4 @@ __PACKAGE__->meta->make_immutable; __END__ -vim: ts=2,sw=2,expandtab +vim: ts=2 sw=2 expandtab