From: Arthur Axel 'fREW' Schmidt Date: Sat, 27 Mar 2010 04:55:00 +0000 (-0500) Subject: tiny refactor to allow different "bundles" X-Git-Tag: v0.001000_01~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c4f4d4a2795f30717ae026c4a44b8a36a86ddcfb;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git tiny refactor to allow different "bundles" --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index 076d294..3079451 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -1,84 +1,12 @@ package DBIx::Class::DeploymentHandler; use Moose; -use Method::Signatures::Simple; -require DBIx::Class::Schema; # loaded for type constraint -require DBIx::Class::ResultSet; # loaded for type constraint -use Carp::Clan '^DBIx::Class::DeploymentHandler'; -use DBIx::Class::DeploymentHandler::Types; +extends 'DBIx::Class::DeploymentHandler::Dad'; 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 - isa => 'Str', - is => 'ro', - required => 1, - default => 'sql', -); - -has backup_directory => ( # configuration - isa => 'Str', - is => 'ro', - predicate => 'has_backup_directory', -); - -has to_version => ( # configuration - is => 'ro', - lazy_build => 1, -); - -sub _build_to_version { $_[0]->schema->schema_version } - -has databases => ( # configuration - coerce => 1, - isa => 'DBIx::Class::DeploymentHandler::Databases', - is => 'ro', - default => sub { [qw( MySQL SQLite PostgreSQL )] }, -); - -has sqltargs => ( # configuration - isa => 'HashRef', - is => 'ro', - default => sub { {} }, -); - -method install { - croak 'Install not possible as versions table already exists in database' - if $self->version_storage_is_installed; - - my $ddl = $self->_deploy; - - $self->version_storage->add_database_version({ - version => $self->to_version, - ddl => $ddl, - }); -} - -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, - }); - } -} - -method backup { $self->storage->backup($self->backup_directory) } - __PACKAGE__->meta->make_immutable; 1; diff --git a/lib/DBIx/Class/DeploymentHandler/Dad.pm b/lib/DBIx/Class/DeploymentHandler/Dad.pm new file mode 100644 index 0000000..2c19b3d --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/Dad.pm @@ -0,0 +1,101 @@ +package DBIx::Class::DeploymentHandler::Dad; + +use Moose; +use Method::Signatures::Simple; +use DBIx::Class::DeploymentHandler::Types; +require DBIx::Class::Schema; # loaded for type constraint +require DBIx::Class::ResultSet; # loaded for type constraint +use Carp::Clan '^DBIx::Class::DeploymentHandler'; + +has schema => ( + isa => 'DBIx::Class::Schema', + is => 'ro', + required => 1, + handles => ['schema_version'], +); + +has upgrade_directory => ( # configuration + isa => 'Str', + is => 'ro', + required => 1, + default => 'sql', +); + +has backup_directory => ( # configuration + isa => 'Str', + is => 'ro', + predicate => 'has_backup_directory', +); + +has to_version => ( # configuration + is => 'ro', + lazy_build => 1, +); + +sub _build_to_version { $_[0]->schema->schema_version } + +has databases => ( # configuration + coerce => 1, + isa => 'DBIx::Class::DeploymentHandler::Databases', + is => 'ro', + default => sub { [qw( MySQL SQLite PostgreSQL )] }, +); + +has sqltargs => ( # configuration + isa => 'HashRef', + is => 'ro', + default => sub { {} }, +); + +method install { + croak 'Install not possible as versions table already exists in database' + if $self->version_storage_is_installed; + + my $ddl = $self->_deploy; + + $self->version_storage->add_database_version({ + version => $self->to_version, + ddl => $ddl, + }); +} + +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, + }); + } +} + +method backup { $self->storage->backup($self->backup_directory) } + +__PACKAGE__->meta->make_immutable; + +1; + +=pod + +=attr schema + +=attr upgrade_directory + +=attr backup_directory + +=attr to_version + +=attr databases + +=method install + +=method upgrade + +=method backup + +__END__ + +vim: ts=2 sw=2 expandtab