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

    r440 r441  
    88 
    99@ISA = qw( Wiki::Toolkit::Setup::Database ); 
    10 $VERSION = '0.09'; 
     10$VERSION = '0.10'; 
    1111 
    1212use DBI; 
     
    105105| ] 
    106106    }, 
     107    10 => { 
     108        schema_info => [ qq| 
     109CREATE TABLE schema_info ( 
     110  version   integer      NOT NULL default 0 
     111);  
     112|, qq| 
     113INSERT INTO schema_info VALUES (10) 
     114| ], 
     115 
     116        node => [ qq| 
     117CREATE TABLE node ( 
     118  id        integer      NOT NULL PRIMARY KEY AUTOINCREMENT, 
     119  name      varchar(200) NOT NULL DEFAULT '', 
     120  version   integer      NOT NULL default 0, 
     121  text      mediumtext   NOT NULL default '', 
     122  modified  datetime     default NULL, 
     123  moderate  boolean      NOT NULL default '0', 
     124  deleted   boolean      NOT NULL default '0' 
     125)  
     126|, qq| 
     127CREATE UNIQUE INDEX node_name ON node (name) 
     128|, qq| 
     129CREATE INDEX node_deleted_index ON node (deleted) 
     130| ], 
     131        content => [ qq| 
     132CREATE TABLE content ( 
     133  node_id   integer      NOT NULL, 
     134  version   integer      NOT NULL default 0, 
     135  text      mediumtext   NOT NULL default '', 
     136  modified  datetime     default NULL, 
     137  comment   mediumtext   NOT NULL default '', 
     138  moderated boolean      NOT NULL default '1', 
     139  deleted   boolean      NOT NULL default '0', 
     140  verified  datetime     default NULL, 
     141  PRIMARY KEY (node_id, version) 
     142)  
     143|, qq| 
     144CREATE INDEX content_deleted_index ON content (deleted) 
     145| ], 
     146        internal_links => [ qq| 
     147CREATE TABLE internal_links ( 
     148  link_from varchar(200) NOT NULL default '', 
     149  link_to   varchar(200) NOT NULL default '', 
     150  deleted   boolean      NOT NULL default '0', 
     151  PRIMARY KEY (link_from, link_to) 
     152)  
     153|, qq| 
     154CREATE INDEX internal_links_deleted_index ON internal_links (deleted) 
     155| ], 
     156        metadata => [ qq| 
     157CREATE TABLE metadata ( 
     158  node_id        integer      NOT NULL, 
     159  version        integer      NOT NULL default 0, 
     160  metadata_type  varchar(200) NOT NULL DEFAULT '', 
     161  metadata_value mediumtext   NOT NULL DEFAULT '', 
     162  deleted        boolean      NOT NULL DEFAULT '0' 
     163)  
     164|, qq| 
     165CREATE INDEX metadata_deleted_index ON metadata (deleted) 
     166| ]  
     167    }, 
    107168}; 
     169 
     170my %fetch_upgrades = ( 
     171    old_to_8  => 1, 
     172    old_to_9  => 1, 
     173    old_to_10 => 1, 
     174    '8_to_9'  => 1, 
     175    '8_to_10' => 1, 
     176    '9_to_10' => 1, 
     177); 
     178 
     179my %upgrades = (); 
    108180 
    109181=head1 NAME 
     
    169241    } 
    170242    if($upgrade_schema) { 
    171         # Grab current data 
    172         print "Upgrading: $upgrade_schema\n"; 
    173         @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)"); 
    174  
    175         # Drop the current tables 
    176         cleardb($dbh); 
    177  
    178         # Grab new list of tables 
    179         %tables = fetch_tables_listing($dbh, $wanted_schema); 
     243        if ($fetch_upgrades{$upgrade_schema}) { 
     244            # Grab current data 
     245            print "Upgrading: $upgrade_schema\n"; 
     246            @cur_data = eval("&Wiki::Toolkit::Setup::Database::fetch_upgrade_".$upgrade_schema."(\$dbh)"); 
     247 
     248            # Drop the current tables 
     249            cleardb($dbh); 
     250 
     251            # Grab new list of tables 
     252            %tables = fetch_tables_listing($dbh, $wanted_schema); 
     253        } 
    180254    } 
    181255 
     
    194268    # If upgrading, load in the new data 
    195269    if($upgrade_schema) { 
    196         Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data); 
     270        if ($fetch_upgrades{$upgrade_schema}) { 
     271            Wiki::Toolkit::Setup::Database::bulk_data_insert($dbh,@cur_data); 
     272        } else { 
     273            print "Upgrading schema: $upgrade_schema\n"; 
     274            my @updates = @{$upgrades{$upgrade_schema}}; 
     275            foreach my $update (@updates) { 
     276                if(ref($update) eq "CODE") { 
     277                    &$update($dbh); 
     278                } elsif(ref($update) eq "ARRAY") { 
     279                    foreach my $nupdate (@$update) { 
     280                        $dbh->do($nupdate); 
     281                    } 
     282                } else { 
     283                    $dbh->do($update); 
     284                } 
     285            }  
     286        } 
    197287    } 
    198288