X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FDeploymentHandler.pm;h=076d29460c0f383f14a109cdc892e37af4ea1ff1;hb=387b11d2bb037c66f8dc4bf6cae3213753254b2e;hp=db13a93096afd24878eadb3ec62ecb2aed120cbc;hpb=189697a77c935fd19474ef8a10886aa0fb90f2c8;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index db13a93..076d294 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -6,24 +6,17 @@ require DBIx::Class::Schema; # loaded for type constraint require DBIx::Class::ResultSet; # loaded for type constraint use Carp::Clan '^DBIx::Class::DeploymentHandler'; -with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod'; -with 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'; - -BEGIN { - use Moose::Util::TypeConstraints; - subtype 'DBIx::Class::DeploymentHandler::Databases' - => as 'ArrayRef[Str]'; - - coerce 'DBIx::Class::DeploymentHandler::Databases' - => from 'Str' - => via { [$_] }; - no Moose::Util::TypeConstraints; -} +use DBIx::Class::DeploymentHandler::Types; +with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod', + 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions', + 'DBIx::Class::DeploymentHandler::WithStandardVersionStorage'; + has schema => ( isa => 'DBIx::Class::Schema', is => 'ro', required => 1, + handles => ['schema_version'], ); has upgrade_directory => ( # configuration @@ -39,20 +32,13 @@ has backup_directory => ( # configuration predicate => 'has_backup_directory', ); -has version_rs => ( - isa => 'DBIx::Class::ResultSet', - is => 'ro', - lazy_build => 1, # builder comes from another role... - # which is... probably not how we want it - handles => [qw( is_installed )], -); - has to_version => ( # configuration is => 'ro', - lazy_build => 1, # builder comes from another role... - # which is... probably not how we want it + lazy_build => 1, ); +sub _build_to_version { $_[0]->schema->schema_version } + has databases => ( # configuration coerce => 1, isa => 'DBIx::Class::DeploymentHandler::Databases', @@ -67,28 +53,30 @@ has sqltargs => ( # configuration ); method install { - carp 'Install not possible as versions table already exists in database' - if $self->is_installed; + croak 'Install not possible as versions table already exists in database' + if $self->version_storage_is_installed; - my $new_version = $self->to_version; + my $ddl = $self->_deploy; - if ($new_version) { - $self->_deploy; + $self->version_storage->add_database_version({ + version => $self->to_version, + ddl => $ddl, + }); +} - $self->version_rs->create({ - version => $new_version, +sub upgrade { + my $self = shift; + while ( my $version_list = $self->next_version_set ) { + $self->_upgrade_single_step($version_list); + + $self->add_database_version({ + version => $version_list->[-1], # ddl => $ddl, # upgrade_sql => $upgrade_sql, }); } } -sub upgrade { - while ( my $version_list = $_[0]->next_version_set ) { - $_[0]->_upgrade_single_step($version_list); - } -} - method backup { $self->storage->backup($self->backup_directory) } __PACKAGE__->meta->make_immutable;