use Test::Exception;
use lib 't/lib';
-use DBICTest;
-use DBIx::Class::DeploymentHandler;
-use DBIx::Class::DeploymentHandler::VersionHandler::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);
+use aliased
+ 'DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions';
-my $handler = DBIx::Class::DeploymentHandler->new({
- upgrade_directory => $sql_dir,
- schema => $s,
- databases => 'SQLite',
- sqltargs => { add_drop_table => 0 },
-});
-
-my $v_storage = $handler->version_storage;
+my $versions = [map "$_.0", 0..100];
-my $version = $s->schema_version();
-$handler->prepare_install();
+{
+ my $vh = ExplicitVersions->new({
+ ordered_versions => $versions,
+ schema_version => '2.0',
+ database_version => '1.0',
+ });
-$handler->install;
+ ok $vh, 'VersionHandler gets instantiated';
-my $versions = [map "$_.0", 0..100];
+ ok(
+ eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
+ 'first version pair works'
+ );
+ ok(
+ !$vh->next_version_set,
+ 'next version set returns undef when we are done'
+ );
+}
{
- my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
- schema => $s,
+ my $vh = ExplicitVersions->new({
ordered_versions => $versions,
to_version => '1.0',
- version_storage => $v_storage,
+ schema_version => '1.0',
+ database_version => '1.0',
});
ok $vh, 'VersionHandler gets instantiated';
- ok( !$vh->next_version_set, 'next version set returns undef if we are at the version requested' );
+ ok(
+ !$vh->next_version_set,
+ 'next version set returns undef if we are at the version requested'
+ );
}
{
- my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
- schema => $s,
+ my $vh = ExplicitVersions->new({
ordered_versions => $versions,
to_version => '5.0',
- version_storage => $v_storage,
+ schema_version => '1.0',
+ database_version => '1.0',
});
ok $vh, 'VersionHandler gets instantiated';
- ok( eq_array($vh->next_version_set, [qw( 1.0 2.0 )]), 'first version pair works' );
- ok( eq_array($vh->next_version_set, [qw( 2.0 3.0 )]), 'second version pair works' );
- ok( eq_array($vh->next_version_set, [qw( 3.0 4.0 )]), 'third version pair works' );
- ok( eq_array($vh->next_version_set, [qw( 4.0 5.0 )]), 'fourth version pair works' );
+ ok(
+ eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
+ 'first version pair works'
+ );
+ ok(
+ eq_array($vh->next_version_set, [qw( 2.0 3.0 )]),
+ 'second version pair works'
+ );
+ ok(
+ eq_array($vh->next_version_set, [qw( 3.0 4.0 )]),
+ 'third version pair works'
+ );
+ ok(
+ eq_array($vh->next_version_set, [qw( 4.0 5.0 )]),
+ 'fourth version pair works'
+ );
ok( !$vh->next_version_set, 'no more versions after final pair' );
ok( !$vh->next_version_set, 'still no more versions after final pair' );
}
+{
+ my $vh = ExplicitVersions->new({
+ ordered_versions => $versions,
+ to_version => '1.0',
+ schema_version => '5.0',
+ database_version => '5.0',
+ });
+
+ ok $vh, 'VersionHandler gets instantiated';
+ ok(
+ eq_array($vh->previous_version_set, [qw( 4.0 5.0 )]),
+ 'first version pair works'
+ );
+ ok(
+ eq_array($vh->previous_version_set, [qw( 3.0 4.0 )]),
+ 'second version pair works'
+ );
+ ok(
+ eq_array($vh->previous_version_set, [qw( 2.0 3.0 )]),
+ 'third version pair works'
+ );
+ ok(
+ eq_array($vh->previous_version_set, [qw( 1.0 2.0 )]),
+ 'fourth version pair works'
+ );
+ ok( !$vh->previous_version_set, 'no more versions after final pair' );
+ ok( !$vh->previous_version_set, 'still no more versions after final pair' );
+}
+
dies_ok {
- my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
- schema => $s,
+ my $vh = ExplicitVersions->new({
+ ordered_versions => $versions,
+ schema_version => '2.0',
+ database_version => '1.1',
+ });
+ $vh->next_version_set
+} 'dies if database version not found in ordered_versions';
+
+dies_ok {
+ my $vh = ExplicitVersions->new({
ordered_versions => $versions,
to_version => '0.0',
- version_storage => $v_storage,
+ schema_version => '1.0',
+ database_version => '1.0',
});
-} 'cannot request a version before the current version';
+ $vh->next_version_set;
+} 'cannot request an upgrade before the current version';
-done_testing;
-__END__
+dies_ok {
+ my $vh = ExplicitVersions->new({
+ ordered_versions => $versions,
+ to_version => '2.0',
+ schema_version => '1.0',
+ database_version => '1.0',
+ });
+ $vh->previous_version_set;
+} 'cannot request a downgrade after the current version';
-vim: ts=2 sw=2 expandtab
+done_testing;
+#vim: ts=2 sw=2 expandtab