Show
Ignore:
Timestamp:
05/12/08 01:21:15 (4 years ago)
Author:
dom
Message:

Add more pieces to support schema upgrade testing (including support for
setting up version 8 schemas) and add actual test script

Files:
1 modified

Legend:

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

    r438 r440  
    1616 
    1717my $create_sql = { 
     18    8 => { 
     19        schema_info => [ qq| 
     20CREATE TABLE schema_info ( 
     21  version   int(10)      NOT NULL default 0 
     22) 
     23|, qq| 
     24INSERT INTO schema_info VALUES (8) 
     25| ], 
     26 
     27        node => [ qq| 
     28CREATE TABLE node ( 
     29  id        integer      NOT NULL AUTO_INCREMENT, 
     30  name      varchar(200) NOT NULL DEFAULT '', 
     31  version   int(10)      NOT NULL default 0, 
     32  text      mediumtext   NOT NULL default '', 
     33  modified  datetime     default NULL, 
     34  PRIMARY KEY (id) 
     35) 
     36| ], 
     37 
     38        content => [ qq| 
     39CREATE TABLE content ( 
     40  node_id   integer      NOT NULL, 
     41  version   int(10)      NOT NULL default 0, 
     42  text      mediumtext   NOT NULL default '', 
     43  modified  datetime     default NULL, 
     44  comment   mediumtext   NOT NULL default '', 
     45  PRIMARY KEY (node_id, version) 
     46) 
     47| ], 
     48        internal_links => [ qq| 
     49CREATE TABLE internal_links ( 
     50  link_from varchar(200) NOT NULL default '', 
     51  link_to   varchar(200) NOT NULL default '', 
     52  PRIMARY KEY (link_from, link_to) 
     53) 
     54| ], 
     55        metadata => [ qq| 
     56CREATE TABLE metadata ( 
     57  node_id        integer      NOT NULL, 
     58  version        int(10)      NOT NULL default 0, 
     59  metadata_type  varchar(200) NOT NULL DEFAULT '', 
     60  metadata_value mediumtext   NOT NULL DEFAULT '' 
     61) 
     62|, qq| 
     63CREATE INDEX metadata_index ON metadata(node_id, version, metadata_type, metadata_value(10)) 
     64| ] 
     65    }, 
    1866    9 => { 
    1967        schema_info => [ qq| 
     
    119167    my $wanted_schema = _get_wanted_schema( @args ) || $SCHEMA_VERSION; 
    120168 
     169    die "No schema information for requested schema version $wanted_schema\n" 
     170        unless $create_sql->{$wanted_schema}; 
     171 
    121172    # Check whether tables exist 
    122     my %tables = fetch_tables_listing($dbh); 
     173    my %tables = fetch_tables_listing($dbh, $wanted_schema); 
    123174 
    124175    # Do we need to upgrade the schema of existing tables? 
     
    127178    my @cur_data; 
    128179    if(scalar keys %tables > 0) { 
    129         $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$SCHEMA_VERSION); 
     180        $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$wanted_schema); 
    130181    } 
    131182    if($upgrade_schema) { 
     
    146197 
    147198        # Grab new list of tables 
    148         %tables = fetch_tables_listing($dbh); 
     199        %tables = fetch_tables_listing($dbh, $wanted_schema); 
    149200    } 
    150201 
    151202    # Set up tables if not found 
    152     foreach my $required ( keys %{$create_sql->{$SCHEMA_VERSION}} ) { 
     203    foreach my $required ( keys %{$create_sql->{$wanted_schema}} ) { 
    153204        if ( $tables{$required} ) { 
    154205            print "Table $required already exists... skipping...\n"; 
    155206        } else { 
    156207            print "Creating table $required... done\n"; 
    157             foreach my $sql ( @{$create_sql->{$SCHEMA_VERSION}->{$required}} ) { 
     208            foreach my $sql ( @{$create_sql->{$wanted_schema}->{$required}} ) { 
    158209                $dbh->do($sql) or croak $dbh->errstr; 
    159210            } 
     
    173224sub fetch_tables_listing { 
    174225    my $dbh = shift; 
     226    my $wanted_schema = shift; 
    175227 
    176228    # Check what tables exist 
     
    179231    my %tables; 
    180232    while ( my $table = $sth->fetchrow_array ) { 
    181         exists $create_sql->{$SCHEMA_VERSION}->{$table} and $tables{$table} = 1; 
     233        exists $create_sql->{$wanted_schema}->{$table} and $tables{$table} = 1; 
    182234    } 
    183235    return %tables; 
     
    264316        return $args{wanted_schema}; 
    265317    } 
    266  
    267     # Args passed as list of connection details. 
    268     return $_[1]; 
    269318} 
    270319