X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDeploymentHandler.pm;h=988adc131160fbb50decbdbd463cb0fd66d5a0f3;hb=7f50d101838b1cb69f53128fa658b6039bd0d3ce;hp=c67fb920aa784eedbdd116f019bdcecaa055195e;hpb=334bced5e3d08a9f7fe0688c9c730c48c38e1550;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index c67fb92..988adc1 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -30,16 +30,17 @@ 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 => ( @@ -54,13 +55,7 @@ method _build_storage { $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, @@ -78,53 +73,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 $schema = $self->schema; - my $type = undef; - my $sqltargs = $self->sqltargs; - my $dir = $self->upgrade_directory; - 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; @@ -132,7 +93,7 @@ method install($new_version) { $new_version ||= $self->schema_version; if ($new_version) { - $self->deploy(); + $self->deploy; $self->version_rs->create({ version => $new_version, @@ -189,4 +150,4 @@ __PACKAGE__->meta->make_immutable; __END__ -vim: ts=2,sw=2,expandtab +vim: ts=2 sw=2 expandtab