[Bast-commits] r3831 - 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
Tue Oct 23 13:18:14 GMT 2007
Author: captainL
Date: 2007-10-23 13:18:13 +0100 (Tue, 23 Oct 2007)
New Revision: 3831
Modified:
DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL
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:
fixed versioning test and checked db and schema versions are not equal before upgrading
Modified: DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL 2007-10-22 19:58:39 UTC (rev 3830)
+++ DBIx-Class/0.08/branches/versioned_enhancements/Makefile.PL 2007-10-23 12:18:13 UTC (rev 3831)
@@ -22,7 +22,7 @@
# Perl 5.8.0 doesn't have utf8::is_utf8()
requires 'Encode' => 0 if ($] <= 5.008000);
-build_requires 'DBD::SQLite' => 1.13;
+build_requires 'DBD::SQLite' => 1.14;
build_requires 'Test::Builder' => 0.33;
install_script 'script/dbicadmin';
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-10-22 19:58:39 UTC (rev 3830)
+++ DBIx-Class/0.08/branches/versioned_enhancements/lib/DBIx/Class/Schema/Versioned.pm 2007-10-23 12:18:13 UTC (rev 3831)
@@ -148,12 +148,10 @@
my ($self) = @_;
my $db_version = $self->get_db_version();
+ my %driver_to_db_map = (
+ 'mysql' => 'MySQL'
+ );
if (!$db_version) {
- my %driver_to_db_map = (
- 'mysql' => 'MySQL',
- 'Pg' => 'PostgreSQL',
- 'Oracle' => 'Oracle'
- );
my $db = $driver_to_db_map{$self->storage->dbh->{Driver}->{Name}};
unless ($db) {
print "Sorry, this is an unsupported DB\n";
@@ -168,7 +166,7 @@
parser_args => { dbh => $self->storage->dbh }
});
- $db_tr->producer($db);
+ $db_tr->producer($db);
my $dbic_tr = SQL::Translator->new;
$dbic_tr->parser('SQL::Translator::Parser::DBIx::Class');
$dbic_tr = $self->storage->configure_sqlt($dbic_tr, $db);
@@ -183,13 +181,13 @@
my $data = $tr->data;
$tr->parser->($tr, $$data);
}
-
+
my $diff = SQL::Translator::Diff::schema_diff($db_tr->schema, $db,
$dbic_tr->schema, $db,
{ ignore_constraint_names => 1, ignore_index_names => 1, caseopt => 1 });
my $filename = $self->ddl_filename(
- $self->storage->sqlt_type,
+ $db,
$self->upgrade_directory,
$self->schema_version,
'PRE',
@@ -208,6 +206,11 @@
print "WARNING: There may be differences between your DB and your DBIC schema. Please review and if necessary run the SQL in $filename to sync your DB.\n";
} else {
+ if ($db_version eq $self->schema_version) {
+ print "Upgrade not necessary\n";
+ return;
+ }
+
my $file = $self->ddl_filename(
$self->storage->sqlt_type,
$self->upgrade_directory,
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t 2007-10-22 19:58:39 UTC (rev 3830)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/94versioning.t 2007-10-23 12:18:13 UTC (rev 3831)
@@ -5,113 +5,55 @@
use File::Spec;
use File::Copy;
+#warn "$dsn $user $pass";
+my ($dsn, $user, $pass);
+
BEGIN {
- eval "use DBD::SQLite; use SQL::Translator 0.08;";
+ ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
+
+ plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
+ unless ($dsn && $user);
+
+
+ eval "use DBD::mysql; use SQL::Translator 0.08;";
plan $@
- ? ( skip_all => 'needs DBD::SQLite and SQL::Translator 0.08 for testing' )
- : ( tests => 6 );
+ ? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.08 for testing' )
+ : ( tests => 9 );
}
use lib qw(t/lib);
use_ok('DBICVersionOrig');
-my $db_file = "t/var/versioning.db";
-unlink($db_file) if -e $db_file;
-unlink($db_file . "-journal") if -e $db_file . "-journal";
-mkdir("t/var") unless -d "t/var";
-unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql');
+my $schema_orig = DBICVersion::Schema->connect($dsn, $user, $pass);
+eval { $schema_orig->storage->dbh->do('drop table SchemaVersions') };
-my $schema_orig = DBICVersion::Schema->connect(
- "dbi:SQLite:$db_file",
- undef,
- undef,
- { AutoCommit => 1 },
-);
-# $schema->storage->ensure_connected();
+is($schema_orig->ddl_filename('MySQL', 't/var', '1.0'), File::Spec->catfile('t', 'var', 'DBICVersion-Schema-1.0-MySQL.sql'), 'Filename creation working');
+unlink('t/var/DBICVersion-Schema-1.0-MySQL.sql') if (-e 't/var/DBICVersion-Schema-1.0-MySQL.sql');
+$schema_orig->create_ddl_dir('MySQL', undef, 't/var');
-is($schema_orig->ddl_filename('SQLite', 't/var', '1.0'), File::Spec->catfile('t', 'var', 'DBICVersion-Schema-1.0-SQLite.sql'), 'Filename creation working');
-$schema_orig->create_ddl_dir('SQLite', undef, 't/var');
+ok(-f 't/var/DBICVersion-Schema-1.0-MySQL.sql', 'Created DDL file');
+$schema_orig->deploy({ add_drop_table => 1 });
+$schema_orig->upgrade();
-ok(-f 't/var/DBICVersion-Schema-1.0-SQLite.sql', 'Created DDL file');
-## do this here or let Versioned.pm do it?
-# $schema->deploy();
-
-my $tvrs = $schema_orig->resultset('Table');
+my $tvrs = $schema_orig->{vschema}->resultset('Table');
is($schema_orig->_source_exists($tvrs), 1, 'Created schema from DDL file');
eval "use DBICVersionNew";
-my $schema_new = DBICVersion::Schema->connect(
- "dbi:SQLite:$db_file",
- undef,
- undef,
- { AutoCommit => 1 },
-);
-
-## create new to pick up filedata for upgrade files we just made (on_connect)
-
-# {
-# 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');
+ unlink('t/var/DBICVersion-Schema-2.0-MySQL.sql');
+ unlink('t/var/DBICVersion-Schema-1.0-2.0-MySQL.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 },
- );
-
-
+ my $schema_upgrade = DBICVersion::Schema->connect($dsn, $user, $pass);
is($schema_upgrade->get_db_version(), '1.0', 'get_db_version ok');
+ is($schema_upgrade->schema_version, '2.0', 'schema version ok');
+ $schema_upgrade->create_ddl_dir('MySQL', '2.0', 't/var', '1.0');
+ ok(-f 't/var/DBICVersion-Schema-1.0-2.0-MySQL.sql', 'Created DDL file');
+ $schema_upgrade->upgrade();
+ is($schema_upgrade->get_db_version(), '2.0', 'db version number upgraded');
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');
-unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
-unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
-unlink(<t/var/backup/*>);
Modified: DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm
===================================================================
--- DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm 2007-10-22 19:58:39 UTC (rev 3830)
+++ DBIx-Class/0.08/branches/versioned_enhancements/t/lib/DBICVersionNew.pm 2007-10-23 12:18:13 UTC (rev 3831)
@@ -24,7 +24,7 @@
'is_nullable' => 0,
'size' => '10'
},
- 'NewsVersionName' => {
+ 'NewVersionName' => {
'data_type' => 'VARCHAR',
'is_auto_increment' => 0,
'default_value' => undef,
More information about the Bast-commits
mailing list