[Bast-commits] r8014 - in DBIx-Class/0.08/branches/dbicadmin_refactor: lib/DBIx/Class t/admin

goraxe at dev.catalyst.perl.org goraxe at dev.catalyst.perl.org
Wed Dec 2 22:52:41 GMT 2009


Author: goraxe
Date: 2009-12-02 22:52:40 +0000 (Wed, 02 Dec 2009)
New Revision: 8014

Removed:
   DBIx-Class/0.08/branches/dbicadmin_refactor/t/admin/var/
Modified:
   DBIx-Class/0.08/branches/dbicadmin_refactor/lib/DBIx/Class/Admin.pm
   DBIx-Class/0.08/branches/dbicadmin_refactor/t/admin/02ddl.t
Log:
all ddl tests now pass

Modified: DBIx-Class/0.08/branches/dbicadmin_refactor/lib/DBIx/Class/Admin.pm
===================================================================
--- DBIx-Class/0.08/branches/dbicadmin_refactor/lib/DBIx/Class/Admin.pm	2009-12-02 21:50:42 UTC (rev 8013)
+++ DBIx-Class/0.08/branches/dbicadmin_refactor/lib/DBIx/Class/Admin.pm	2009-12-02 22:52:40 UTC (rev 8014)
@@ -87,7 +87,6 @@
 	$self->ensure_class_loaded($self->schema_class);
 
 	$self->connect_info->[3]->{ignore_version} =1;
-	#warn Dumper ($self->connect_info(), $self->connect_info->[3], {ignore_version => 1 });
 	return $self->schema_class->connect(@{$self->connect_info()} ); # ,  $self->connect_info->[3], { ignore_version => 1} );
 }
 
@@ -143,7 +142,7 @@
 );
 
 has version => (
-	is			=> 'ro',
+	is			=> 'rw',
 	isa			=> 'Str',
 );
 
@@ -153,13 +152,22 @@
 	predicate	=> 'has_preversion',
 );
 
+has force => (
+	is			=> 'rw',
+	isa			=> 'Bool',
+);
+
+has '_confirm' => (
+	is		=> 'ro',
+	isa		=> 'Bool',
+);
+
 sub create {
 	my ($self, $sqlt_type, $sqlt_args) = @_;
 	if ($self->has_preversion) {
 		print "attempting to create diff file for ".$self->preversion."\n";
 	}
 	my $schema = $self->schema();
-#	warn "running with params sqlt_type = $sqlt_type, version = " .$schema->schema_version . " sql_dir = " . $self->sql_dir . " preversion = " . ($self->has_preversion ?  $self->preversion : "" ). "\n";
 	# create the dir if does not exist
 	$self->sql_dir->mkpath() if ( ! -d $self->sql_dir);
 
@@ -171,23 +179,34 @@
 	my $schema = $self->schema();
 	if (!$schema->get_db_version()) {
 		# schema is unversioned
-		warn "could not determin current schema version, please either install or deploy";
+		die "could not determin current schema version, please either install or deploy";
 	} else {
 		$schema->upgrade();
 	}
 }
 
 sub install {
-	my ($self) = @_;
+	my ($self, $version) = @_;
 
 	my $schema = $self->schema();
-	if (!$schema->get_db_version()) {
+	$version ||= $self->version();
+	if (!$schema->get_db_version() ) {
 		# schema is unversioned
-		print "Going to install schema version";
-		$schema->install($self->version);
-	} else {
-		warn "schema already has a version not installing, try upgrade instead";
+		print "Going to install schema version\n";
+		my $ret = $schema->install($version);
+		print "retun is $ret\n";
 	}
+	elsif ($schema->get_db_version() and $self->force ) {
+		warn "forcing install may not be a good idea";
+		if($self->confirm() ) {
+			# FIXME private api
+			warn $version;
+			$self->schema->_set_db_version({ version => $version});
+		}
+	}
+	else {
+		die "schema already has a version not installing, try upgrade instead";
+	}
 
 }
 
@@ -196,13 +215,10 @@
 	my $schema = $self->schema();
 	if (!$schema->get_db_version() ) {
 		# schema is unversioned
-#		warn "going to deploy";
-#		warn Dumper $schema->deployment_statements();
-		
 		$schema->deploy( $args, $self->sql_dir)
 			or die "could not deploy schema";
 	} else {
-		warn "there already is a database with a version here, try upgrade instead";
+		die "there already is a database with a version here, try upgrade instead";
 	}
 }
 
@@ -303,8 +319,11 @@
 }
 
 sub confirm {
-    print "Are you sure you want to do this? (type YES to confirm) ";
-    my $response = <STDIN>;
+    my ($self) = @_;
+	print "Are you sure you want to do this? (type YES to confirm) ";
+	# mainly here for testing
+	return 1 if ($self->_confirm());
+	my $response = <STDIN>;
     return 1 if ($response=~/^YES/);
     return;
 }

Modified: DBIx-Class/0.08/branches/dbicadmin_refactor/t/admin/02ddl.t
===================================================================
--- DBIx-Class/0.08/branches/dbicadmin_refactor/t/admin/02ddl.t	2009-12-02 21:50:42 UTC (rev 8013)
+++ DBIx-Class/0.08/branches/dbicadmin_refactor/t/admin/02ddl.t	2009-12-02 22:52:40 UTC (rev 8014)
@@ -34,7 +34,7 @@
 
 use DBICTest;
 
-my $sql_dir = dir($Bin,"var","sql");
+my $sql_dir = dir($Bin,"..","var");
 
 { # create the schema
 
@@ -87,19 +87,52 @@
 
 $admin = DBIx::Class::Admin->new(
 	schema_class => 'DBICVersion::Schema', 
-	sql_dir =>  $sql_dir,
+	sql_dir =>  "t/var",
 	connect_info => $schema->storage->connect_info(),
 );
 
-lives_ok { $admin->create($schema->storage->sqlt_type(), {add_drop_table=>0}); } 'Can create DBICVersionOrig sql in ' . $schema->storage->sqlt_type;
+$admin->preversion("1.0");
+lives_ok { $admin->create($schema->storage->sqlt_type(), ); } 'Can create diff for ' . $schema->storage->sqlt_type;
 lives_ok {$admin->upgrade();} 'upgrade the schema';
 
-is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema deployed and versions match');
+is($schema->get_db_version, $DBICVersion::Schema::VERSION, 'Schema and db versions match');
 
 }
 
+{ # install
+
+clean_dir($sql_dir);
+
+my $schema = DBICTest->init_schema(
+    no_deploy=>1,
+    no_populate=>1,
+	sqlite_use_file	=> 1,
+	);
+
+my $admin = DBIx::Class::Admin->new(
+	schema_class	=> 'DBICVersion::Schema', 
+	sql_dir			=> $sql_dir,
+	connect_info	=> $schema->storage->connect_info(),
+	_confirm		=> 1,
+);
+
+$admin->version("3.0");
+lives_ok { $admin->install(); } 'install schema version 3.0';
+is($admin->schema->get_db_version, "3.0", 'db thinks its version 3.0');
+dies_ok { $admin->install("4.0"); } 'cannot install to allready existing version';
+sleep 1;
+$admin->force(1);
+lives_ok { $admin->install("4.0"); } 'can force install to allready existing version';
+is($admin->schema->get_db_version, "4.0", 'db thinks its version 4.0');
+#clean_dir($sql_dir);
+}
+
 sub clean_dir {
 	my ($dir)  =@_;
+	$dir = $dir->resolve;
+	if ( ! -d $dir ) {
+		$dir->mkpath();
+	}
 	foreach my $file ($dir->children) {
 		# skip any hidden files
 		next if ($file =~ /^\./); 




More information about the Bast-commits mailing list