croak instead of carp on double install
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler.pm
index 76d48e0..5deb9c6 100644 (file)
@@ -25,6 +25,7 @@ has schema => (
   isa      => 'DBIx::Class::Schema',
   is       => 'ro',
   required => 1,
+  handles => ['schema_version'],
 );
 
 has upgrade_directory => ( # configuration
@@ -42,10 +43,11 @@ has backup_directory => ( # configuration
 
 has to_version => ( # configuration
   is         => 'ro',
-  lazy_build => 1, # builder comes from another role...
-                   # which is... probably not how we want it
+  lazy_build => 1,
 );
 
+sub _build_to_version { $_[0]->schema->schema_version }
+
 has databases => ( # configuration
   coerce  => 1,
   isa     => 'DBIx::Class::DeploymentHandler::Databases',
@@ -60,20 +62,15 @@ has sqltargs => ( # configuration
 );
 
 method install {
-  carp 'Install not possible as versions table already exists in database'
+  croak 'Install not possible as versions table already exists in database'
     if $self->version_storage_is_installed;
 
-  my $new_version = $self->to_version;
-
-  if ($new_version) {
-    $self->_deploy;
+  my $ddl = $self->_deploy;
 
-    $self->add_database_version({
-      version     => $new_version,
-      # ddl         => $ddl,
-      # upgrade_sql => $upgrade_sql,
-    });
-  }
+  $self->version_storage->add_database_version({
+    version     => $self->to_version,
+    ddl         => $ddl,
+  });
 }
 
 sub upgrade {