Changeset 450

Show
Ignore:
Timestamp:
07/12/08 01:49:47 (4 years ago)
Author:
dom
Message:

Cater for the case where the index being added in MySQL schema 10 was manually created in the database beforehand

Location:
wiki-toolkit/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm

    r444 r450  
    179179 
    180180my %upgrades = ( 
    181 '9_to_10' => [ qq| 
    182 CREATE UNIQUE INDEX node_name ON node (name) 
    183 |, qq| 
     181    '9_to_10' => [ sub { 
     182        my $dbh = shift; 
     183        my $sth = $dbh->prepare('SHOW INDEX FROM node WHERE key_name="node_name"'); 
     184        $sth->execute(); 
     185        unless ( $sth->rows ) { 
     186            $dbh->do('CREATE UNIQUE INDEX node_name ON node (name)') 
     187                or croak $dbh->errstr; 
     188        } 
     189    }, 
     190    qq| 
    184191ALTER TABLE content ADD COLUMN verified datetime default NULL 
    185192|, qq| 
     
    187194|, qq| 
    188195UPDATE schema_info SET version = 10 
    189 | 
    190 ], 
     196| ] 
     197 
    191198); 
    192199 
  • wiki-toolkit/trunk/t/400_upgrade.t

    r448 r450  
    3131use Wiki::Toolkit::Setup::SQLite; 
    3232 
     33my $num_mysql_only_tests = 0; 
     34my @mysql_databases; 
     35 
    3336foreach my $db (@configured_databases) { 
    3437    my $setup_class = $db->{setup_class}; 
     
    4245        push @schemas_to_test, $schema if $schema < $current_schema; 
    4346    } 
     47    if ( $db->{dsn} =~ /mysql/i ) { 
     48        $num_mysql_only_tests = 2; 
     49        push @mysql_databases, $db; 
     50    } 
    4451} 
    4552 
    46 plan tests => scalar @schemas_to_test * scalar @configured_databases * 2; 
     53my $num_tests = (scalar @schemas_to_test * scalar @configured_databases * 2) + $num_mysql_only_tests; 
     54plan tests => $num_tests; 
    4755 
    4856foreach my $database (@configured_databases) { 
     
    92100    } 
    93101} 
     102 
     103if ( $num_mysql_only_tests ) { 
     104    foreach my $database ( @mysql_databases ) { 
     105        my $setup_class = $database->{setup_class}; 
     106        my $current_schema; 
     107        { 
     108            no strict 'refs'; 
     109            $current_schema = eval ${$setup_class . '::SCHEMA_VERSION'}; 
     110        } 
     111        # Set up database with old schema 
     112        my $params = $database->{params}; 
     113        $params->{wanted_schema} = 9; 
     114 
     115        { 
     116            no strict 'refs'; 
     117            eval &{$setup_class . '::cleardb'} ( $params ); 
     118            eval &{$setup_class . '::setup'} ( $params ); 
     119        } 
     120 
     121        my $class = $database->{class}; 
     122        eval "require $class"; 
     123 
     124        my $dsn = $database->{dsn}; 
     125 
     126        my $dbh = DBI->connect($dsn, $params->{dbuser}, $params->{dbpass}); 
     127         
     128        # Manually create index that the upgrade also wants to create 
     129        eval { $dbh->do('CREATE UNIQUE INDEX node_name ON node (name);') }; 
     130        is( $@, '', "Manually creating confusing index didn't die" ); 
     131 
     132        # Now upgrade 
     133        delete $params->{wanted_schema}; 
     134        { 
     135            no strict 'refs'; 
     136            eval &{$setup_class . '::setup'} ( $params ); 
     137            is( $@, '', "Upgrade didn't die even though node_name index had been created manually" ); 
     138        } 
     139    } 
     140} 
     141