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/SQLite.pm

    r438 r440  
    1616 
    1717my $create_sql = { 
     18    8 => { 
     19        schema_info => [ qq| 
     20CREATE TABLE schema_info ( 
     21  version   integer      NOT NULL default 0 
     22); 
     23|, qq| 
     24INSERT INTO schema_info VALUES (8) 
     25| ], 
     26        node => [ qq| 
     27CREATE TABLE node ( 
     28  id        integer      NOT NULL PRIMARY KEY AUTOINCREMENT, 
     29  name      varchar(200) NOT NULL DEFAULT '', 
     30  version   integer      NOT NULL default 0, 
     31  text      mediumtext   NOT NULL default '', 
     32  modified  datetime     default NULL 
     33) 
     34| ], 
     35        content => [ qq| 
     36CREATE TABLE content ( 
     37  node_id   integer      NOT NULL, 
     38  version   integer      NOT NULL default 0, 
     39  text      mediumtext   NOT NULL default '', 
     40  modified  datetime     default NULL, 
     41  comment   mediumtext   NOT NULL default '', 
     42  PRIMARY KEY (node_id, version) 
     43) 
     44| ], 
     45        internal_links => [ qq| 
     46CREATE TABLE internal_links ( 
     47  link_from varchar(200) NOT NULL default '', 
     48  link_to   varchar(200) NOT NULL default '', 
     49  PRIMARY KEY (link_from, link_to) 
     50) 
     51| ], 
     52        metadata => [ qq| 
     53CREATE TABLE metadata ( 
     54  node_id        integer      NOT NULL, 
     55  version        integer      NOT NULL default 0, 
     56  metadata_type  varchar(200) NOT NULL DEFAULT '', 
     57  metadata_value mediumtext   NOT NULL DEFAULT '' 
     58) 
     59| ] 
     60    }, 
    1861    9 => { 
    1962        schema_info => [ qq| 
     
    112155    my $wanted_schema = _get_wanted_schema( @args ) || $SCHEMA_VERSION; 
    113156 
     157    die "No schema information for requested schema version $wanted_schema\n" 
     158            unless $create_sql->{$wanted_schema}; 
     159 
    114160    # Check whether tables exist, set them up if not. 
    115     my %tables = fetch_tables_listing($dbh); 
     161    my %tables = fetch_tables_listing($dbh, $wanted_schema); 
    116162 
    117163    # Do we need to upgrade the schema? 
     
    131177 
    132178        # Grab new list of tables 
    133         %tables = fetch_tables_listing($dbh); 
     179        %tables = fetch_tables_listing($dbh, $wanted_schema); 
    134180    } 
    135181 
    136182    # Set up tables if not found 
    137     foreach my $required ( keys %{$create_sql->{$SCHEMA_VERSION}} ) { 
     183    foreach my $required ( keys %{$create_sql->{$wanted_schema}} ) { 
    138184        if ( $tables{$required} ) { 
    139185            print "Table $required already exists... skipping...\n"; 
    140186        } else { 
    141187            print "Creating table $required... done\n"; 
    142             foreach my $sql (@{$create_sql->{$SCHEMA_VERSION}->{$required}} ) { 
     188            foreach my $sql (@{$create_sql->{$wanted_schema}->{$required}} ) { 
    143189                $dbh->do($sql) or croak $dbh->errstr; 
    144190            } 
     
    158204sub fetch_tables_listing { 
    159205    my $dbh = shift; 
     206    my $wanted_schema = shift; 
    160207 
    161208    # Check whether tables exist, set them up if not. 
    162209    my $sql = "SELECT name FROM sqlite_master 
    163210               WHERE type='table' AND name in (" 
    164             . join( ",", map { $dbh->quote($_) } keys %{$create_sql->{$SCHEMA_VERSION}} ) . ")"; 
     211            . join( ",", map { $dbh->quote($_) } keys %{$create_sql->{$wanted_schema}} ) . ")"; 
    165212    my $sth = $dbh->prepare($sql) or croak $dbh->errstr; 
    166213    $sth->execute; 
     
    245292        return $args{wanted_schema}; 
    246293    } 
    247  
    248     # Args passed as list of connection details. 
    249     return $_[1]; 
    250294} 
    251295