Changeset 440 for wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
- Timestamp:
- 05/12/08 01:21:15 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
r438 r440 16 16 17 17 my $create_sql = { 18 8 => { 19 schema_info => [ qq| 20 CREATE TABLE schema_info ( 21 version int(10) NOT NULL default 0 22 ) 23 |, qq| 24 INSERT INTO schema_info VALUES (8) 25 | ], 26 27 node => [ qq| 28 CREATE 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| 39 CREATE 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| 49 CREATE 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| 56 CREATE 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| 63 CREATE INDEX metadata_index ON metadata(node_id, version, metadata_type, metadata_value(10)) 64 | ] 65 }, 18 66 9 => { 19 67 schema_info => [ qq| … … 119 167 my $wanted_schema = _get_wanted_schema( @args ) || $SCHEMA_VERSION; 120 168 169 die "No schema information for requested schema version $wanted_schema\n" 170 unless $create_sql->{$wanted_schema}; 171 121 172 # Check whether tables exist 122 my %tables = fetch_tables_listing($dbh );173 my %tables = fetch_tables_listing($dbh, $wanted_schema); 123 174 124 175 # Do we need to upgrade the schema of existing tables? … … 127 178 my @cur_data; 128 179 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); 130 181 } 131 182 if($upgrade_schema) { … … 146 197 147 198 # Grab new list of tables 148 %tables = fetch_tables_listing($dbh );199 %tables = fetch_tables_listing($dbh, $wanted_schema); 149 200 } 150 201 151 202 # Set up tables if not found 152 foreach my $required ( keys %{$create_sql->{$ SCHEMA_VERSION}} ) {203 foreach my $required ( keys %{$create_sql->{$wanted_schema}} ) { 153 204 if ( $tables{$required} ) { 154 205 print "Table $required already exists... skipping...\n"; 155 206 } else { 156 207 print "Creating table $required... done\n"; 157 foreach my $sql ( @{$create_sql->{$ SCHEMA_VERSION}->{$required}} ) {208 foreach my $sql ( @{$create_sql->{$wanted_schema}->{$required}} ) { 158 209 $dbh->do($sql) or croak $dbh->errstr; 159 210 } … … 173 224 sub fetch_tables_listing { 174 225 my $dbh = shift; 226 my $wanted_schema = shift; 175 227 176 228 # Check what tables exist … … 179 231 my %tables; 180 232 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; 182 234 } 183 235 return %tables; … … 264 316 return $args{wanted_schema}; 265 317 } 266 267 # Args passed as list of connection details.268 return $_[1];269 318 } 270 319
