use Moose;
use Method::Signatures::Simple;
-# normally a VersionHandler will take
-# a to_version and yeild an iterator of
-# "version sets" or something like that.
-#
-# A "version set" is basically an arrayref
-# of "version numbers" (which we already know
-# is vague as is.) Typically an call to a
-# VH w/ a db version of 1 and a "to_version"
-# of 5 will iterate over something like this:
-# [1, 2]
-# [2, 3]
-# [3, 4]
-# [4, 5]
-#
-# Of course rob wants to be able to have dep
-# management with his versions, so I *think* his
-# would work like this:
-#
-# to_version = 7, db_version = 1
-# [1]
-# [5]
-# [7]
-#
-# Because 7 depended on 5, 5 was installed first;
-# note that this potentially never released module
-# doesn't use version pairs, instead it just yeilds
-# versions. Version pairs are too much work for users
-# to have to deal with in that sitation. We may
-# actually switch to this for other versioners.
-#
-# The upshot of all this is that the DeploymentMethod
-# needs to be able to take an ArrayRef[VersionNumber],
-# instead of just a pair of VersionNumber.
+with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
-has schema => (
- isa => 'DBIx::Class::Schema',
- is => 'ro',
- required => 1,
- handles => [qw( ddl_filename schema_version )],
+has once => (
+ is => 'rw',
+ isa => 'Bool',
+ default => undef,
);
-has version_rs => (
- isa => 'DBIx::Class::ResultSet',
- is => 'ro',
- lazy_build => 1,
- handles => [qw( is_installed db_version )],
-);
+sub next_version_set {
+ my $self = shift;
+ return undef
+ if $self->once;
-method _build_version_rs {
- $self->schema->set_us_up_the_bomb;
- $self->schema->resultset('__VERSION')
+ $self->once(!$self->once);
+ return undef
+ if $self->db_version eq $self->to_version;
+ return [$self->db_version, $self->to_version];
}
-method ordered_schema_versions {
- ( $self->db_version, $self->schema_version)
-}
__PACKAGE__->meta->make_immutable;
use Method::Signatures::Simple;
use Carp 'croak';
-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')
-}
-
-has to_version => (
- is => 'ro',
- required => 1,
-);
+with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
has ordered_versions => (
is => 'ro',
croak 'database version not found in ordered_versions!';
}
-method next_version_set {
+sub next_version_set { # sub instead of method because of when roles get composed
+ my $self = shift;
return undef
if $self->ordered_versions->[$self->_version_idx] eq $self->to_version;
my $next_idx = $self->_inc_version_idx;
--- /dev/null
+package DBIx::Class::DeploymentHandler::HandlesVersioning;
+use Moose::Role;
+
+requires 'next_version_set';
+
+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 )],
+);
+
+sub _build_version_rs {
+ $_[0]->schema->set_us_up_the_bomb;
+ $_[0]->schema->resultset('__VERSION')
+}
+
+has to_version => (
+ is => 'ro',
+ lazy_build => 1,
+);
+
+sub _build_to_version { $_[0]->schema->schema_version }
+
+1;
+
+__END__
+
+# normally a VersionHandler will take
+# a to_version and yeild an iterator of
+# "version sets" or something like that.
+#
+# A "version set" is basically an arrayref
+# of "version numbers" (which we already know
+# is vague as is.) Typically an call to a
+# VH w/ a db version of 1 and a "to_version"
+# of 5 will iterate over something like this:
+# [1, 2]
+# [2, 3]
+# [3, 4]
+# [4, 5]
+#
+# Of course rob wants to be able to have dep
+# management with his versions, so I *think* his
+# would work like this:
+#
+# to_version = 7, db_version = 1
+# [1]
+# [5]
+# [7]
+#
+# Because 7 depended on 5, 5 was installed first;
+# note that this potentially never released module
+# doesn't use version pairs, instead it just yeilds
+# versions. Version pairs are too much work for users
+# to have to deal with in that sitation. We may
+# actually switch to this for other versioners.
+#
+# The upshot of all this is that the DeploymentMethod
+# needs to be able to take an ArrayRef[VersionNumber],
+# instead of just a pair of VersionNumber.
+vim: ts=2 sw=2 expandtab
--- /dev/null
+#!perl
+
+use Test::More;
+use Test::Exception;
+
+use lib 't/lib';
+use DBICTest;
+use DBIx::Class::DeploymentHandler;
+use DBIx::Class::DeploymentHandler::ExplicitVersions;
+my $db = 'dbi:SQLite:db.db';
+my @connection = ($db, '', '', { ignore_version => 1 });
+my $sql_dir = 't/sql';
+
+unlink 'db.db' if -e 'db.db';
+if (-d 't/sql') {
+ unlink $_ for glob('t/sql/*');
+} else {
+ mkdir 't/sql';
+}
+
+use DBICVersion_v1;
+my $s = DBICVersion::Schema->connect(@connection);
+
+my $handler = DBIx::Class::DeploymentHandler->new({
+ upgrade_directory => $sql_dir,
+ schema => $s,
+ databases => 'SQLite',
+ sqltargs => { add_drop_table => 0 },
+});
+
+my $version = $s->schema_version();
+$handler->create_install_ddl();
+
+$handler->install;
+{
+ my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
+ schema => $s,
+ ordered_versions => $versions,
+ to_version => '5.0',
+ });
+
+ ok( $vh, 'VersionHandler gets instantiated' );
+ ok( eq_array( $vh->next_version_set, [qw( 1.0 5.0 )] ), 'db version and to_version get correctly put into version set');
+ ok( !$vh->next_version_set, 'next_version_set only works once');
+ ok( !$vh->next_version_set, 'seriously.');
+}
+
+{
+ my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
+ schema => $s,
+ ordered_versions => $versions,
+ });
+
+ ok( $vh, 'VersionHandler gets instantiated' );
+ ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
+}
+
+{
+ my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
+ schema => $s,
+ ordered_versions => $versions,
+ });
+
+ ok( $vh, 'VersionHandler gets instantiated' );
+ ok( !$vh->next_version_set, 'VersionHandler is null when schema_version and db_verison are the same' );
+}
+
+{
+ $DBICVersion::Schema::VERSION = '10.0';
+
+ my $vh = DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
+ schema => $s,
+ ordered_versions => $versions,
+ });
+
+ ok( $vh, 'VersionHandler gets instantiated' );
+ ok( eq_array( $vh->next_version_set, [qw( 1.0 10.0 )] ), 'db version and schema version get correctly put into version set');
+ ok( !$vh->next_version_set, 'VersionHandler is null on next try' );
+}
+
+done_testing;
+__END__
+
+vim: ts=2 sw=2 expandtab