[Bast-commits] r3682 - in
DBIx-Class/0.08/branches/versioned_enhancements:
lib/DBIx/Class/Schema t t/lib
captainL at dev.catalyst.perl.org
captainL at dev.catalyst.perl.org
Wed Aug 15 23:29:59 GMT 2007
Author: captainL
Date: 2007-08-15 23:29:57 +0100 (Wed, 15 Aug 2007)
New Revision: 3682
Modified:
DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema/Versioned.pm
DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t
DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm
Log:
tests are a mess, but Versioned.pm should work now
Modified: DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema/Versioned.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema/Versioned.pm 2007-08-15 13:29:01 UTC (rev 3681)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema/Versioned.pm 2007-08-15 22:29:57 UTC (rev 3682)
@@ -48,6 +48,7 @@
__PACKAGE__->mk_classdata('_filedata');
__PACKAGE__->mk_classdata('upgrade_directory');
__PACKAGE__->mk_classdata('backup_directory');
+__PACKAGE__->mk_classdata('do_backup');
sub schema_version {
my ($self) = @_;
@@ -131,7 +132,7 @@
my $fh;
open $fh, "<$file" or warn("Can't open upgrade file, $file ($!)");
- my @data = split(/;\n/, join('', <$fh>));
+ my @data = split(/[;\n]/, join('', <$fh>));
close($fh);
@data = grep { $_ && $_ !~ /^-- / } @data;
@data = grep { $_ !~ /^(BEGIN TRANACTION|COMMIT)/m } @data;
@@ -156,7 +157,7 @@
],
as => ['maxinstall'],
})->first;
- $pversion = $vtable->search({ Installed => $psearch->get_column('maxinstall'),
+ my $pversion = $vtable->search({ Installed => $psearch->get_column('maxinstall'),
})->first;
$pversion = $pversion->Version if($pversion);
return $pversion;
@@ -185,13 +186,17 @@
{
my ($self) = @_;
- $self->backup();
- $self->do_upgrade();
+ $self->backup() if($self->do_backup);
+ $self->txn_do(sub {
+ $self->do_upgrade();
+ });
+
my $vtable = $self->{vschema}->resultset('Table');
$vtable->create({ Version => $self->schema_version,
Installed => strftime("%Y-%m-%d %H:%M:%S", gmtime())
});
+
}
sub do_upgrade
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t 2007-08-15 13:29:01 UTC (rev 3681)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t 2007-08-15 22:29:57 UTC (rev 3682)
@@ -3,6 +3,7 @@
use warnings;
use Test::More;
use File::Spec;
+use File::Copy;
BEGIN {
eval "use DBD::SQLite; use SQL::Translator 0.08;";
@@ -47,24 +48,67 @@
{ AutoCommit => 1 },
);
-unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
-unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
-$schema_new->create_ddl_dir('SQLite', undef, 't/var', '1.0');
-ok(-f 't/var/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'Created DDL upgrade file');
-
## create new to pick up filedata for upgrade files we just made (on_connect)
-my $schema_upgrade = DBICVersion::Schema->connect(
- "dbi:SQLite:$db_file",
- undef,
- undef,
- { AutoCommit => 1 },
-);
-## do this here or let Versioned.pm do it?
-$schema_upgrade->upgrade();
-$tvrs = $schema_upgrade->resultset('Table');
-is($schema_upgrade->_source_exists($tvrs), 1, 'Upgraded schema from DDL file');
+# {
+# unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
+# copy('t/var/DBICVersion-Schema-1.0-2.0-SQLite-erroneous.sql', 't/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
+# my $schema_upgrade = DBICVersion::Schema->connect(
+# "dbi:SQLite:$db_file",
+# undef,
+# undef,
+# { AutoCommit => 1 },
+# );
+
+
+# is($schema_upgrade->get_db_version(), '1.0', 'get_db_version ok');
+
+# eval {
+# # this will die with errors
+# $schema_upgrade->upgrade();
+# };
+# isnt($@, '', 'dodgy upgrade dies');
+
+# eval {
+# my @results = $schema_upgrade->storage->dbh->do('select VersionName from TestVersion');
+# };
+# is($@, '', 'partial upgrade properly rolledback');
+# is($schema_upgrade->get_db_version(), '1.0', 'db version number not upgraded');
+# }
+
+{
+ unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
+ unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
+
+# $schema_new->create_ddl_dir('SQLite', undef, 't/var', '1.0');
+# ok(-f 't/var/DBICVersion-Schema-1.0-2.0-SQLite.sql', 'Created DDL upgrade file');
+
+ copy('t/var/DBICVersion-Schema-1.0-2.0-SQLite-proper.sql', 't/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
+
+ my $schema_upgrade = DBICVersion::Schema->connect(
+ "dbi:SQLite:$db_file",
+ undef,
+ undef,
+ { AutoCommit => 1 },
+ );
+
+
+ is($schema_upgrade->get_db_version(), '1.0', 'get_db_version ok');
+
+ eval {
+ # this should be okay
+ $schema_upgrade->upgrade();
+ };
+ is($@, '', 'proper upgrade okay');
+ eval {
+ $schema_upgrade->storage->dbh->do('select NewVersionName from TestVersion');
+ };
+ is($@, '', 'new column created');
+ is($schema_upgrade->get_db_version(), '2.0', 'db version number successfully upgraded');
+}
+
+exit;
unlink($db_file) if -e $db_file;
unlink($db_file . "-journal") if -e $db_file . "-journal";
unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql');
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm 2007-08-15 13:29:01 UTC (rev 3681)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm 2007-08-15 22:29:57 UTC (rev 3682)
@@ -21,9 +21,17 @@
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
+ 'is_nullable' => 0,
+ 'size' => '10'
+ },
+ 'NewsVersionName' => {
+ 'data_type' => 'VARCHAR',
+ 'is_auto_increment' => 0,
+ 'default_value' => undef,
+ 'is_foreign_key' => 0,
'is_nullable' => 1,
'size' => '20'
- },
+ }
);
__PACKAGE__->set_primary_key('Version');
More information about the Bast-commits
mailing list