Merge 'trunk' into 'multiple_version_upgrade'
Peter Rabbitson [Tue, 19 Jan 2010 12:47:48 +0000 (12:47 +0000)]
r8307@Thesaurus (orig r8295):  abraxxa | 2010-01-13 17:28:05 +0100
added the sources parser arg to the example code

r8327@Thesaurus (orig r8315):  ribasushi | 2010-01-15 01:25:39 +0100
 r8167@Thesaurus (orig r8155):  ribasushi | 2009-12-19 12:50:13 +0100
 New branch for null-only-result fix
 r8168@Thesaurus (orig r8156):  ribasushi | 2009-12-19 12:51:21 +0100
 Failing test
 r8322@Thesaurus (orig r8310):  ribasushi | 2010-01-15 00:48:09 +0100
 Correct test order
 r8323@Thesaurus (orig r8311):  ribasushi | 2010-01-15 01:15:33 +0100
 Generalize the to-node inner-join-er to apply to all related_resultset calls, not just counts
 r8324@Thesaurus (orig r8312):  ribasushi | 2010-01-15 01:16:05 +0100
 Adjust sql-emitter tests
 r8326@Thesaurus (orig r8314):  ribasushi | 2010-01-15 01:25:10 +0100
 One more sql-test fix and changes

r8328@Thesaurus (orig r8316):  ribasushi | 2010-01-15 01:31:58 +0100
Strict mysql bugfix
r8329@Thesaurus (orig r8317):  ribasushi | 2010-01-15 01:38:53 +0100
Better description of mysql strict option
r8331@Thesaurus (orig r8319):  ribasushi | 2010-01-15 03:12:13 +0100
Update troubleshooting doc
r8337@Thesaurus (orig r8325):  ribasushi | 2010-01-15 17:13:28 +0100
RT52674
r8346@Thesaurus (orig r8334):  ribasushi | 2010-01-17 09:41:49 +0100
No method aliasing in OO code, *ever*
r8373@Thesaurus (orig r8360):  ribasushi | 2010-01-18 11:54:51 +0100
Adjust my email
r8387@Thesaurus (orig r8374):  ribasushi | 2010-01-19 13:07:07 +0100
 r8340@Thesaurus (orig r8328):  abraxxa | 2010-01-15 19:21:20 +0100
 added branch no_duplicate_indexes_for_pk_cols with test and fix

 r8343@Thesaurus (orig r8331):  abraxxa | 2010-01-15 19:32:16 +0100
 don't use eq_set in test

 r8344@Thesaurus (orig r8332):  abraxxa | 2010-01-15 19:44:04 +0100
 don't sort the primary columns because order matters for indexes

 r8345@Thesaurus (orig r8333):  abraxxa | 2010-01-15 19:56:46 +0100
 don't sort the key columns because the order of columns is important for indexes

 r8372@Thesaurus (orig r8359):  abraxxa | 2010-01-18 10:22:09 +0100
 don't sort the columns in the tests either

 r8378@Thesaurus (orig r8365):  abraxxa | 2010-01-18 15:39:28 +0100
 added pod section for parser args

 r8379@Thesaurus (orig r8366):  abraxxa | 2010-01-18 15:53:08 +0100
 better pod thanks to ribasushi

 r8380@Thesaurus (orig r8367):  abraxxa | 2010-01-18 16:04:34 +0100
 test and pod fixes

 r8383@Thesaurus (orig r8370):  abraxxa | 2010-01-19 12:38:44 +0100
 fixed Authors section
 added License section
 fixed t/86sqlt.t tests

 r8384@Thesaurus (orig r8371):  ribasushi | 2010-01-19 12:59:52 +0100
 Regenaretd under new parser
 r8385@Thesaurus (orig r8372):  ribasushi | 2010-01-19 13:03:51 +0100
 Minor style change and white space trim
 r8386@Thesaurus (orig r8373):  ribasushi | 2010-01-19 13:06:54 +0100
 Changes abraxxa++

r8390@Thesaurus (orig r8377):  ribasushi | 2010-01-19 13:41:03 +0100
Some minor test refactor and tab cleanups

1  2 
Changes
lib/DBIx/Class/Schema/Versioned.pm
t/94versioning.t

diff --combined Changes
+++ b/Changes
@@@ -9,16 -9,21 +9,22 @@@ Revision history for DBIx::Clas
          - Cookbook POD fix for add_drop_table instead of add_drop_tables
          - Views without a view_definition will throw an exception when
            parsed by SQL::Translator::Parser::DBIx::Class
+         - Stop the SQLT parser from auto-adding indexes identical to the
+           Primary Key
          - Schema POD improvement for dclone
          - Fix regression in context sensitiveness of deployment_statements
          - Fix regression resulting in overcomplicated query on
            search_related from prefetching resultsets
+         - Fix regression on all-null returning searches (properly switch
+           LEFT JOIN to JOIN in order to distinguish between both cases)
+         - Fix regression in groupedresultset count() used on strict-mode
+           MySQL connections
          - Better isolation of RNO-limited queries from the rest of a
            prefetching resultset
          - New MSSQL specific resultset attribute to allow hacky ordered
            subquery support
          - Fix nasty schema/dbhandle leak due to SQL::Translator
 +        - Add mechanism for schema version to apply multiple step upgrades
  
  0.08115 2009-12-10 09:02:00 (CST)
          - Real limit/offset support for MSSQL server (via Row_Number)
@@@ -181,7 -181,7 +181,7 @@@ use warnings
  use base 'DBIx::Class::Schema';
  
  use Carp::Clan qw/^DBIx::Class/;
 -use POSIX 'strftime';
 +use Time::HiRes qw/gettimeofday/;
  
  __PACKAGE__->mk_classdata('_filedata');
  __PACKAGE__->mk_classdata('upgrade_directory');
@@@ -268,132 -268,35 +268,132 @@@ and the schema_version which is retriev
  =cut
  
  sub create_upgrade_path {
-       ## override this method
+   ## override this method
  }
  
 +=head2 ordered_schema_versions
 +
 +=over 4
 +
 +=item Returns: a list of version numbers, ordered from lowest to highest
 +
 +=back
 +
 +Virtual method that should be overriden to return an ordered list
 +of schema versions. This is then used to produce a set of steps to
 +upgrade through to achieve the required schema version.
 +
 +You may want the db_version retrieved via $self->get_db_version
 +and the schema_version which is retrieved via $self->schema_version 
 +
 +=cut
 +
 +sub ordered_schema_versions {
 +      ## override this method
 +}
 +
  =head2 upgrade
  
 -Call this to attempt to upgrade your database from the version it is at to the version
 -this DBIC schema is at. If they are the same it does nothing.
 +Call this to attempt to upgrade your database from the version it
 +is at to the version this DBIC schema is at. If they are the same
 +it does nothing.
  
 -It requires an SQL diff file to exist in you I<upgrade_directory>, normally you will
 -have created this using L<DBIx::Class::Schema/create_ddl_dir>.
 +It will call L</ordered_schema_versions> to retrieve an ordered
 +list of schema versions (if ordered_schema_versions returns nothing
 +then it is assumed you can do the upgrade as a single step). It
 +then iterates through the list of versions between the current db
 +version and the schema version applying one update at a time until
 +all relvant updates are applied.
  
 -If successful the dbix_class_schema_versions table is updated with the current
 -DBIC schema version.
 +The individual update steps are performed by using
 +L</upgrade_single_step>, which will apply the update and also
 +update the dbix_class_schema_versions table.
  
  =cut
  
 -sub upgrade
 -{
 -  my ($self) = @_;
 -  my $db_version = $self->get_db_version();
 +sub upgrade {
 +    my ($self) = @_;
 +    my $db_version = $self->get_db_version();
  
 -  # db unversioned
 -  unless ($db_version) {
 -    carp 'Upgrade not possible as database is unversioned. Please call install first.';
 -    return;
 -  }
 +    # db unversioned
 +    unless ($db_version) {
 +        carp 'Upgrade not possible as database is unversioned. Please call install first.';
 +        return;
 +    }
 +
 +    # db and schema at same version. do nothing
 +    if ( $db_version eq $self->schema_version ) {
 +        carp "Upgrade not necessary\n";
 +        return;
 +    }
 +
 +    my @version_list = $self->ordered_schema_versions;
 +
 +    # if nothing returned then we preload with min/max
 +    @version_list = ( $db_version, $self->schema_version )
 +      unless ( scalar(@version_list) );
 +
 +    # catch the case of someone returning an arrayref
 +    @version_list = @{ $version_list[0] }
 +      if ( ref( $version_list[0] ) eq 'ARRAY' );
 +
 +    # remove all versions in list above the required version
 +    while ( scalar(@version_list)
 +        && ( $version_list[-1] ne $self->schema_version ) )
 +    {
 +        pop @version_list;
 +    }
 +
 +    # remove all versions in list below the current version
 +    while ( scalar(@version_list) && ( $version_list[0] ne $db_version ) ) {
 +        shift @version_list;
 +    }
 +
 +    # check we have an appropriate list of versions
 +    if ( scalar(@version_list) < 2 ) {
 +        die;
 +    }
 +
 +    # do sets of upgrade
 +    while ( scalar(@version_list) >= 2 ) {
 +        $self->upgrade_single_step( $version_list[0], $version_list[1] );
 +        shift @version_list;
 +    }
 +}
 +
 +=head2 upgrade_single_step
 +
 +=over 4
 +
 +=item Arguments: db_version - the version currently within the db
 +
 +=item Arguments: target_version - the version to upgrade to
 +
 +=back
 +
 +Call this to attempt to upgrade your database from the
 +I<db_version> to the I<target_version>. If they are the same it
 +does nothing.
 +
 +It requires an SQL diff file to exist in your I<upgrade_directory>,
 +normally you will have created this using L<DBIx::Class::Schema/create_ddl_dir>.
 +
 +If successful the dbix_class_schema_versions table is updated with
 +the I<target_version>.
 +
 +This method may be called repeatedly by the upgrade method to
 +upgrade through a series of updates.
 +
 +=cut
 +
 +sub upgrade_single_step
 +{
 +  my ($self,
 +      $db_version,
 +      $target_version) = @_;
  
    # db and schema at same version. do nothing
 -  if ($db_version eq $self->schema_version) {
 +  if ($db_version eq $target_version) {
      carp "Upgrade not necessary\n";
      return;
    }
  
    my $upgrade_file = $self->ddl_filename(
                                           $self->storage->sqlt_type,
 -                                         $self->schema_version,
 +                                         $target_version,
                                           $self->upgrade_directory,
                                           $db_version,
                                          );
      return;
    }
  
-   carp "\nDB version ($db_version) is lower than the schema version (".$self->schema_version."). Attempting upgrade.\n";
+   carp "DB version ($db_version) is lower than the schema version (".$self->schema_version."). Attempting upgrade.\n";
  
    # backup if necessary then apply upgrade
    $self->_filedata($self->_read_sql_file($upgrade_file));
    $self->txn_do(sub { $self->do_upgrade() });
  
    # set row in dbix_class_schema_versions table
 -  $self->_set_db_version;
 +  $self->_set_db_version({version => $target_version});
  }
  
  =head2 do_upgrade
@@@ -488,7 -391,7 +488,7 @@@ differently
  sub apply_statement {
      my ($self, $statement) = @_;
  
-     $self->storage->dbh->do($_) or carp "SQL was:\n $_";
+     $self->storage->dbh->do($_) or carp "SQL was: $_";
  }
  
  =head2 get_db_version
@@@ -599,7 -502,7 +599,7 @@@ sub _on_connec
          return 1;
      }
  
-   carp "Versions out of sync. This is " . $self->schema_version . 
+   carp "Versions out of sync. This is " . $self->schema_version .
      ", your database contains version $pversion, please call upgrade on your Schema.\n";
  }
  
@@@ -671,33 -574,10 +671,33 @@@ sub _set_db_version 
  
    my $version = $params->{version} ? $params->{version} : $self->schema_version;
    my $vtable = $self->{vschema}->resultset('Table');
 -  $vtable->create({ version => $version,
 -                      installed => strftime("%Y-%m-%d %H:%M:%S", gmtime())
 -                      });
  
 +  ##############################################################################
 +  #                             !!! NOTE !!!
 +  ##############################################################################
 +  #
 +  # The travesty below replaces the old nice timestamp format of %Y-%m-%d %H:%M:%S
 +  # This is necessary since there are legitimate cases when upgrades can happen
 +  # back to back within the same second. This breaks things since we relay on the
 +  # ability to sort by the 'installed' value. The logical choice of an autoinc
 +  # is not possible, as it will break multiple legacy installations. Also it is 
 +  # not possible to format the string sanely, as the column is a varchar(20).
 +  # The 'v' character is added to the front of the string, so that any version
 +  # formatted by this new function will sort _after_ any existing 200... strings.
 +  my @tm = gettimeofday();
 +  my @dt = gmtime ($tm[0]);
 +  my $o = $vtable->create({ 
 +    version => $version,
 +    installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f",
 +      $dt[5] + 1900,
 +      $dt[4] + 1,
 +      $dt[3],
 +      $dt[2],
 +      $dt[1],
 +      $dt[0],
 +      $tm[1] / 1000, # convert to millisecs, format as up/down rounded int above
 +    ),
 +  });
  }
  
  sub _read_sql_file {
diff --combined t/94versioning.t
@@@ -3,7 -3,10 +3,10 @@@
  use strict;
  use warnings;
  use Test::More;
- use File::Spec;
+ use Test::Warn;
+ use Test::Exception;
+ use Path::Class;
  use File::Copy;
  
  #warn "$dsn $user $pass";
@@@ -28,160 -31,89 +31,148 @@@ BEGIN 
  my $version_table_name = 'dbix_class_schema_versions';
  my $old_table_name = 'SchemaVersions';
  
- my $ddl_dir = File::Spec->catdir ('t', 'var');
+ my $ddl_dir = dir ('t', 'var');
  my $fn = {
-     v1 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-1.0-MySQL.sql'),
-     v2 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-2.0-MySQL.sql'),
-     v3 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-3.0-MySQL.sql'),
-     trans_v12 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-1.0-2.0-MySQL.sql'),
-     trans_v23 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-2.0-3.0-MySQL.sql'),
+     v1 => $ddl_dir->file ('DBICVersion-Schema-1.0-MySQL.sql'),
+     v2 => $ddl_dir->file ('DBICVersion-Schema-2.0-MySQL.sql'),
 -    trans => $ddl_dir->file ('DBICVersion-Schema-1.0-2.0-MySQL.sql'),
++    v3 => $ddl_dir->file ('DBICVersion-Schema-3.0-MySQL.sql'),
++    trans_v12 => $ddl_dir-> ('DBICVersion-Schema-1.0-2.0-MySQL.sql'),
++    trans_v23 => $ddl_dir-> ('DBICVersion-Schema-2.0-3.0-MySQL.sql'),
  };
  
  use lib qw(t/lib);
  use DBICTest; # do not remove even though it is not used
  
 -use_ok('DBICVersionOrig');
 +use_ok('DBICVersion_v1');
  
 -my $schema_orig = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
 -eval { $schema_orig->storage->dbh->do('drop table ' . $version_table_name) };
 -eval { $schema_orig->storage->dbh->do('drop table ' . $old_table_name) };
 +my $schema_v1 = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
 +eval { $schema_v1->storage->dbh->do('drop table ' . $version_table_name) };
 +eval { $schema_v1->storage->dbh->do('drop table ' . $old_table_name) };
  
 -is($schema_orig->ddl_filename('MySQL', '1.0', $ddl_dir), $fn->{v1}, 'Filename creation working');
 +is($schema_v1->ddl_filename('MySQL', '1.0', $ddl_dir), $fn->{v1}, 'Filename creation working');
  unlink( $fn->{v1} ) if ( -e $fn->{v1} );
 -$schema_orig->create_ddl_dir('MySQL', undef, $ddl_dir);
 +$schema_v1->create_ddl_dir('MySQL', undef, $ddl_dir);
  
  ok(-f $fn->{v1}, 'Created DDL file');
 -$schema_orig->deploy({ add_drop_table => 1 });
 +$schema_v1->deploy({ add_drop_table => 1 });
  
 -my $tvrs = $schema_orig->{vschema}->resultset('Table');
 -is($schema_orig->_source_exists($tvrs), 1, 'Created schema from DDL file');
 +my $tvrs = $schema_v1->{vschema}->resultset('Table');
 +is($schema_v1->_source_exists($tvrs), 1, 'Created schema from DDL file');
  
  # loading a new module defining a new version of the same table
  DBICVersion::Schema->_unregister_source ('Table');
 -eval "use DBICVersionNew";
 +eval "use DBICVersion_v2";
  
 -my $schema_upgrade = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
 +my $schema_v2 = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
  {
    unlink($fn->{v2});
 -  unlink($fn->{trans});
 +  unlink($fn->{trans_v12});
  
 -  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', $ddl_dir, '1.0');
 -  ok(-f $fn->{trans}, 'Created DDL file');
 +  is($schema_v2->get_db_version(), '1.0', 'get_db_version ok');
 +  is($schema_v2->schema_version, '2.0', 'schema version ok');
 +  $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0');
 +  ok(-f $fn->{trans_v12}, 'Created DDL file');
  
-   {
-     my $w;
-     local $SIG{__WARN__} = sub { $w = shift };
-     $schema_v2->upgrade();
-     like ($w, qr/Attempting upgrade\.$/, 'Warn before upgrade');
-   }
+   sleep 1;    # remove this when TODO below is completed
+   warnings_like (
 -    sub { $schema_upgrade->upgrade() },
++    sub { $schema_v2->upgrade() },
+     qr/DB version .+? is lower than the schema version/,
+     'Warn before upgrade',
+   );
  
 -  is($schema_upgrade->get_db_version(), '2.0', 'db version number upgraded');
 +  is($schema_v2->get_db_version(), '2.0', 'db version number upgraded');
  
-   eval {
+   lives_ok ( sub {
 -    $schema_upgrade->storage->dbh->do('select NewVersionName from TestVersion');
 +    $schema_v2->storage->dbh->do('select NewVersionName from TestVersion');
-   };
-   is($@, '', 'new column created');
-   # should overwrite files and warn about it
-   my @w;
-   local $SIG{__WARN__} = sub { 
-     if ($_[0] =~ /Overwriting existing/) {
-       push @w, $_[0];
-     }
-     else {
-       warn @_;
-     }
-   };
-   $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0');
-   is (2, @w, 'A warning generated for both the DDL and the diff');
-   like ($w[0], qr/Overwriting existing DDL file - $fn->{v2}/, 'New version DDL overwrite warning');
-   like ($w[1], qr/Overwriting existing diff file - $fn->{trans_v12}/, 'Upgrade diff overwrite warning');
+   }, 'new column created' );
+   warnings_exist (
 -    sub { $schema_upgrade->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0') },
++    sub { $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0') },
+     [
+       qr/Overwriting existing DDL file - $fn->{v2}/,
+       qr/Overwriting existing diff file - $fn->{trans}/,
+     ],
+     'An overwrite warning generated for both the DDL and the diff',
+   );
  }
  
  {
    my $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
-   eval {
+   lives_ok (sub {
      $schema_version->storage->dbh->do('select * from ' . $version_table_name);
-   };
-   is($@, '', 'version table exists');
+   }, 'version table exists');
  
-   eval {
+   lives_ok (sub {
      $schema_version->storage->dbh->do("DROP TABLE IF EXISTS $old_table_name");
      $schema_version->storage->dbh->do("RENAME TABLE $version_table_name TO $old_table_name");
-   };
-   is($@, '', 'versions table renamed to old style table');
+   }, 'versions table renamed to old style table');
  
    $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
    is($schema_version->get_db_version, '2.0', 'transition from old table name to new okay');
  
-   eval {
+   dies_ok (sub {
      $schema_version->storage->dbh->do('select * from ' . $old_table_name);
-   };
-   ok($@, 'old version table gone');
+   }, 'old version table gone');
  
  }
  
 +# repeat the v1->v2 process for v2->v3 before testing v1->v3
 +DBICVersion::Schema->_unregister_source ('Table');
 +eval "use DBICVersion_v3";
 +
 +my $schema_v3 = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
 +{
 +  unlink($fn->{v3});
 +  unlink($fn->{trans_v23});
 +
 +  is($schema_v3->get_db_version(), '2.0', 'get_db_version 2.0 ok');
 +  is($schema_v3->schema_version, '3.0', 'schema version 3.0 ok');
 +  $schema_v3->create_ddl_dir('MySQL', '3.0', $ddl_dir, '2.0');
 +  ok(-f $fn->{trans_v23}, 'Created DDL 2.0 -> 3.0 file');
 +
 +  {
 +    my $w;
 +    local $SIG{__WARN__} = sub { $w = shift };
 +
 +    $schema_v3->upgrade();
 +    like ($w, qr/Attempting upgrade\.$/, 'Warn before upgrade');
 +  }
 +
 +  is($schema_v3->get_db_version(), '3.0', 'db version number upgraded');
 +
 +  eval {
 +    $schema_v3->storage->dbh->do('select ExtraColumn from TestVersion');
 +  };
 +  is($@, '', 'new column created');
 +}
 +
 +# now put the v1 schema back again
 +{
 +  # drop all the tables...
 +  eval { $schema_v1->storage->dbh->do('drop table ' . $version_table_name) };
 +  eval { $schema_v1->storage->dbh->do('drop table ' . $old_table_name) };
 +  eval { $schema_v1->storage->dbh->do('drop table TestVersion') };
 +
 +  {
 +    local $DBICVersion::Schema::VERSION = '1.0';
 +    $schema_v1->deploy;
 +  }
 +  is($schema_v1->get_db_version(), '1.0', 'get_db_version 1.0 ok');
 +}
 +
 +# attempt v1 -> v3 upgrade....
 +{
 +  {
 +    my $w;
 +    local $SIG{__WARN__} = sub { $w = shift };
 +
 +    $schema_v3->upgrade();
 +    like ($w, qr/Attempting upgrade\.$/, 'Warn before upgrade');
 +  }
 +
 +  is($schema_v3->get_db_version(), '3.0', 'db version number upgraded');
 +}
 +
  # check behaviour of DBIC_NO_VERSION_CHECK env var and ignore_version connect attr
  {
    my $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
    };
  
  
-   my $warn = '';
-   local $SIG{__WARN__} = sub { $warn = shift };
-   $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
-   like($warn, qr/Your DB is currently unversioned/, 'warning detected without env var or attr');
+   warnings_like ( sub {
+     $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
+   }, qr/Your DB is currently unversioned/, 'warning detected without env var or attr' );
  
+   warnings_like ( sub {
+     $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
+   },  [], 'warning not detected with attr set');
  
-   # should warn
-   $warn = '';
-   $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 });
-   is($warn, '', 'warning not detected with attr set');
-   # should not warn
  
    local $ENV{DBIC_NO_VERSION_CHECK} = 1;
-   $warn = '';
-   $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
-   is($warn, '', 'warning not detected with env var set');
-   # should not warn
+   warnings_like ( sub {
+     $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
+   }, [], 'warning not detected with env var set');
  
-   $warn = '';
-   $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 0 });
-   like($warn, qr/Your DB is currently unversioned/, 'warning detected without env var or attr');
-   # should warn
+   warnings_like ( sub {
+     $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 0 });
+   }, qr/Your DB is currently unversioned/, 'warning detected without env var or attr');
  }
  
  # attempt a deploy/upgrade cycle within one second
@@@ -219,9 -146,9 +205,9 @@@ TODO: 
  
    local $TODO = 'To fix this properly the table must be extended with an autoinc column, mst will not accept anything less';
  
 -  eval { $schema_orig->storage->dbh->do('drop table ' . $version_table_name) };
 -  eval { $schema_orig->storage->dbh->do('drop table ' . $old_table_name) };
 -  eval { $schema_orig->storage->dbh->do('drop table TestVersion') };
 +  eval { $schema_v2->storage->dbh->do('drop table ' . $version_table_name) };
 +  eval { $schema_v2->storage->dbh->do('drop table ' . $old_table_name) };
 +  eval { $schema_v2->storage->dbh->do('drop table TestVersion') };
  
    # this attempts to sleep until the turn of the second
    my $t = time();
    diag ('Fast deploy/upgrade start: ', time() );
  
    {
 -    local $DBICVersion::Schema::VERSION = '1.0';
 -    $schema_orig->deploy;
 +    local $DBICVersion::Schema::VERSION = '2.0';
 +    $schema_v2->deploy;
    }
  
    local $SIG{__WARN__} = sub { warn if $_[0] !~ /Attempting upgrade\.$/ };
 -  $schema_upgrade->upgrade();
 +  $schema_v2->upgrade();
  
 -  is($schema_upgrade->get_db_version(), '2.0', 'Fast deploy/upgrade');
 +  is($schema_v2->get_db_version(), '3.0', 'Fast deploy/upgrade');
  };
  
  unless ($ENV{DBICTEST_KEEP_VERSIONING_DDL}) {