change installed column name to id, initial big test for standard version storage
Arthur Axel 'fREW' Schmidt [Sat, 20 Mar 2010 21:35:48 +0000 (16:35 -0500)]
lib/DBIx/Class/DeploymentHandler/VersionStorage/Standard/VersionResult.pm
lib/DBIx/Class/DeploymentHandler/VersionStorage/Standard/VersionResultSet.pm
t/version_storages/standard.t

index f3ce125..be31c7e 100644 (file)
@@ -8,7 +8,7 @@ use parent 'DBIx::Class::Core';
 __PACKAGE__->table('dbix_class_deploymenthandler_versions');
 
 __PACKAGE__->add_columns (
-  installed => {
+  id => {
     data_type         => 'int',
     is_auto_increment => 1,
   },
@@ -28,7 +28,7 @@ __PACKAGE__->add_columns (
   },
 );
 
-__PACKAGE__->set_primary_key('installed');
+__PACKAGE__->set_primary_key('id');
 __PACKAGE__->add_unique_constraint(['version']);
 __PACKAGE__->resultset_class('DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResultSet');
 
index 79f06a3..82d5e1e 100644 (file)
@@ -9,15 +9,19 @@ use Try::Tiny;
 
 sub version_storage_is_installed {
   my $self = shift;
-  try { $self->next; 1} catch { undef }
+  try { $self->next; 1 } catch { undef }
 }
 
 sub database_version {
   my $self = shift;
   $self->search(undef, {
-    order_by => { -desc => 'installed' },
+    order_by => { -desc => 'id' },
     rows => 1
   })->get_column('version')->next;
 }
 
 1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab
index b2476d8..d8b50ee 100644 (file)
@@ -1,11 +1,82 @@
 #!perl
 
 use Test::More;
+use Test::Deep;
 use Test::Exception;
 
 use lib 't/lib';
 use DBICDHTest;
 use DBICTest;
-use_ok 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
+use aliased 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
 
+use DBICVersion_v1;
+use DBIx::Class::DeploymentHandler;
+my $db = 'dbi:SQLite:db.db';
+my @connection = ($db, '', '', { ignore_version => 1 });
+my $sql_dir = 't/sql';
+
+my $s = DBICVersion::Schema->connect(@connection);
+DBICDHTest::ready;
+
+my $handler = DBIx::Class::DeploymentHandler->new({
+       upgrade_directory => $sql_dir,
+       schema => $s,
+       databases => 'SQLite',
+       sqltargs => { add_drop_table => 0 },
+});
+
+$handler->prepare_install();
+
+my $vs = Standard->new({ schema => $s });
+
+ok( $vs, 'DBIC::DH::VersionStorage::Standard instantiates correctly' );
+
+ok( !$vs->version_storage_is_installed, 'VersionStorage is not yet installed' );
+
+$handler->install();
+
+ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
+
+
+cmp_deeply(
+       [ map +{
+               version     => $_->version,
+               ddl         => $_->ddl,
+               upgrade_sql => $_->upgrade_sql,
+       }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
+       [{
+               version     => '1.0',
+               ddl         => undef,
+               upgrade_sql => undef
+       }],
+       'initial version works correctly'
+);
+
+is( $vs->database_version, '1.0', 'database version is 1.0');
+$vs->add_database_version({
+       version => '2.0',
+});
+is( $vs->database_version, '2.0', 'database version is 2.0');
+
+cmp_deeply(
+       [ map +{
+               version     => $_->version,
+               ddl         => $_->ddl,
+               upgrade_sql => $_->upgrade_sql,
+       }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
+       [{
+               version     => '1.0',
+               ddl         => undef,
+               upgrade_sql => undef
+       },{
+               version     => '2.0',
+               ddl         => undef,
+               upgrade_sql => undef
+       }],
+       'adding another version works correctly'
+);
+
+$vs->version_rs->delete;
+
+ok( $vs->version_storage_is_installed, 'VersionStorage is still installed even if all versions are deleted' );
 done_testing;