Show
Ignore:
Timestamp:
05/26/08 19:44:26 (4 years ago)
Author:
dom
Message:

Move to new schema version 10, including some missing indexes
and support for deletion flags and verified flags. Note that
the code using these columns has not yet been written (closes #25, #34).

Files:
1 modified

Legend:

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

    r440 r441  
    55use vars qw( $VERSION @SUPPORTED_SCHEMAS); 
    66 
    7 $VERSION = 0.08; 
    8 @SUPPORTED_SCHEMAS = qw(8 9); 
     7$VERSION = 0.09; 
     8@SUPPORTED_SCHEMAS = qw(8 9 10); 
    99 
    1010=head1 NAME 
     
    1515=cut 
    1616 
    17 # Fetch from the old style database, ready for an upgrade to db version 8 
    1817sub fetch_upgrade_old_to_8 { 
    19     # Compatible with old_to_9 
    20     fetch_upgrade_old_to_9(@_); 
    21 } 
    22  
    23 # Fetch from the old style database, ready for an upgrade to db version 9 
     18    # Compatible with old_to_10 
     19    fetch_upgrade_old_to_10(@_); 
     20} 
     21 
    2422sub fetch_upgrade_old_to_9 { 
     23    # Compatible with old_to_10 
     24    fetch_upgrade_old_to_10(@_); 
     25} 
     26 
     27# Fetch from the old style database, ready for an upgrade to db version 10 
     28sub fetch_upgrade_old_to_10 { 
    2529    my $dbh = shift; 
    2630    my %nodes; 
     
    104108} 
    105109 
    106 # Fetch from schema version 8, and upgrade to version 9 
    107110sub fetch_upgrade_8_to_9 { 
     111    # Compatible with 8_to_10  
     112    fetch_upgrade_8_to_10(@_); 
     113} 
     114 
     115# Fetch from schema version 8, and upgrade to version 10 
     116sub fetch_upgrade_8_to_10 { 
    108117    my $dbh = shift; 
    109118    my %nodes; 
     
    139148        $content{'comment'} = $comment; 
    140149        $content{'moderated'} = 1; 
     150        $contents{$node_id."-".$version} = \%content; 
     151    } 
     152 
     153    # Grab all the metadata 
     154    $sth = $dbh->prepare("SELECT node_id,version,metadata_type,metadata_value FROM metadata"); 
     155    $sth->execute; 
     156    my $i = 0; 
     157    while( my($node_id,$version,$metadata_type,$metadata_value) = $sth->fetchrow_array) { 
     158        my %metadata; 
     159        $metadata{'node_id'} = $node_id; 
     160        $metadata{'version'} = $version; 
     161        $metadata{'metadata_type'} = $metadata_type; 
     162        $metadata{'metadata_value'} = $metadata_value; 
     163        $metadatas{$node_id."-".($i++)} = \%metadata; 
     164    } 
     165 
     166    # Grab all the internal links 
     167    $sth = $dbh->prepare("SELECT link_from,link_to FROM internal_links"); 
     168    $sth->execute; 
     169    while( my($link_from,$link_to) = $sth->fetchrow_array) { 
     170        my %il; 
     171        $il{'link_from'} = $link_from; 
     172        $il{'link_to'} = $link_to; 
     173        push @internal_links, \%il; 
     174    } 
     175 
     176    print "done\n"; 
     177 
     178    # Return it all 
     179    return (\%nodes,\%contents,\%metadatas,\@internal_links); 
     180} 
     181 
     182# Fetch from schema version 9, and upgrade to version 10 
     183sub fetch_upgrade_9_to_10 { 
     184    my $dbh = shift; 
     185    my %nodes; 
     186    my %metadatas; 
     187    my %contents; 
     188    my @internal_links; 
     189 
     190    print "Grabbing and upgrading old data... "; 
     191 
     192    # Grab all the nodes 
     193    my $sth = $dbh->prepare("SELECT id,name,version,text,modified,moderate FROM node"); 
     194    $sth->execute; 
     195    while( my($id,$name,$version,$text,$modified,$moderate) = $sth->fetchrow_array) { 
     196        my %node; 
     197        $node{'name'} = $name; 
     198        $node{'version'} = $version; 
     199        $node{'text'} = $text; 
     200        $node{'modified'} = $modified; 
     201        $node{'id'} = $id; 
     202        $node{'moderate'} = $moderate; 
     203        $nodes{$name} = \%node; 
     204    } 
     205 
     206    # Grab all the content 
     207    $sth = $dbh->prepare("SELECT node_id,version,text,modified,comment,moderated FROM content"); 
     208    $sth->execute; 
     209    while ( my($node_id,$version,$text,$modified,$comment,$moderated) = $sth->fetchrow_array) { 
     210        my %content; 
     211        $content{'node_id'} = $node_id; 
     212        $content{'version'} = $version; 
     213        $content{'text'} = $text; 
     214        $content{'modified'} = $modified; 
     215        $content{'comment'} = $comment; 
     216        $content{'moderated'} = $moderated; 
    141217        $contents{$node_id."-".$version} = \%content; 
    142218    }