From: Arthur Axel 'fREW' Schmidt Date: Thu, 25 Feb 2010 05:34:41 +0000 (-0600) Subject: super basic version handlers X-Git-Tag: v0.001000_01~120 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e70a1600bca78dbce41af0b35f4b231e88399365;p=dbsrgits%2FDBIx-Class-DeploymentHandler.git super basic version handlers --- diff --git a/lib/DBIx/Class/DeploymentHandler.pm b/lib/DBIx/Class/DeploymentHandler.pm index c06f124..e595e46 100644 --- a/lib/DBIx/Class/DeploymentHandler.pm +++ b/lib/DBIx/Class/DeploymentHandler.pm @@ -7,6 +7,7 @@ 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; @@ -87,8 +88,6 @@ method install($new_version) { } } -method ordered_schema_versions { undef } - method upgrade { my $db_version = $self->db_version; my $schema_version = $self->schema_version; @@ -105,8 +104,7 @@ method upgrade { return; } - my @version_list = $self->ordered_schema_versions || - ( $db_version, $schema_version ); + my @version_list = $self->ordered_schema_versions; # remove all versions in list above the required version while ( @version_list && ( $version_list[-1] ne $schema_version ) ) { diff --git a/lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm new file mode 100644 index 0000000..0c4a249 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm @@ -0,0 +1,34 @@ +package DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions; +use Moose; +use Method::Signatures::Simple; + +has schema => ( + isa => 'DBIx::Class::Schema', + is => 'ro', + required => 1, + handles => [qw( ddl_filename schema_version )], +); + +has version_rs => ( + isa => 'DBIx::Class::ResultSet', + is => 'ro', + lazy_build => 1, + handles => [qw( is_installed db_version )], +); + +method _build_version_rs { + $self->schema->set_us_up_the_bomb; + $self->schema->resultset('__VERSION') +} + +method ordered_schema_versions { + ( $self->db_version, $self->schema_version) +} + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm new file mode 100644 index 0000000..da87886 --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm @@ -0,0 +1,13 @@ +package DBIx::Class::DeploymentHandler::ExplicitVersions; +use Moose; +use Method::Signatures::Simple; + +method ordered_schema_versions { undef } + +__PACKAGE__->meta->make_immutable; + +1; + +__END__ + +vim: ts=2 sw=2 expandtab diff --git a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm new file mode 100644 index 0000000..9cdba4c --- /dev/null +++ b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm @@ -0,0 +1,33 @@ +package DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions; +use Moose::Role; + +use DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions; + +use Carp 'carp'; + +has version_handler => ( + +# < mst> isa => 'DBIx::Class::DeploymentHandler::SqltDeployMethod', +# < mst> should be +# < mst> does => +# < mst> and that role should supply those methods +# < mst> then you can pass handles => as well + + isa => 'DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions', + is => 'ro', + lazy_build => 1, + handles => [qw{ ordered_schema_versions }], +); + +sub _build_version_handler { + my $self = shift; + DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({ + schema => $self->schema, + }); +} + +1; + +__END__ + +vim: ts=2 sw=2 expandtab