Changeset 437 for wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
- Timestamp:
- 05/11/08 20:24:34 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/MySQL.pm
r432 r437 13 13 use Carp; 14 14 15 my %create_sql = ( 16 schema_info => [ qq| 15 my $SCHEMA_VERSION = $VERSION*100; 16 17 my $create_sql = { 18 9 => { 19 schema_info => [ qq| 17 20 CREATE TABLE schema_info ( 18 21 version int(10) NOT NULL default 0 19 22 ) 20 23 |, qq| 21 INSERT INTO schema_info VALUES ( |.($VERSION*100).qq|)24 INSERT INTO schema_info VALUES (9) 22 25 | ], 23 26 24 node => [ qq|27 node => [ qq| 25 28 CREATE TABLE node ( 26 29 id integer NOT NULL AUTO_INCREMENT, … … 34 37 | ], 35 38 36 content => [ qq|39 content => [ qq| 37 40 CREATE TABLE content ( 38 41 node_id integer NOT NULL, … … 45 48 ) 46 49 | ], 47 internal_links => [ qq|50 internal_links => [ qq| 48 51 CREATE TABLE internal_links ( 49 52 link_from varchar(200) NOT NULL default '', … … 52 55 ) 53 56 | ], 54 metadata => [ qq|57 metadata => [ qq| 55 58 CREATE TABLE metadata ( 56 59 node_id integer NOT NULL, … … 62 65 CREATE INDEX metadata_index ON metadata(node_id, version, metadata_type, metadata_value(10)) 63 66 | ] 64 ); 67 }, 68 }; 65 69 66 70 =head1 NAME … … 113 117 my $dbh = _get_dbh( @args ); 114 118 my $disconnect_required = _disconnect_required( @args ); 119 my $wanted_schema = _get_wanted_schema( @args ) || $SCHEMA_VERSION; 115 120 116 121 # Check whether tables exist … … 122 127 my @cur_data; 123 128 if(scalar keys %tables > 0) { 124 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$ VERSION);129 $upgrade_schema = Wiki::Toolkit::Setup::Database::get_database_upgrade_required($dbh,$SCHEMA_VERSION); 125 130 } 126 131 if($upgrade_schema) { … … 145 150 146 151 # Set up tables if not found 147 foreach my $required ( keys % create_sql) {152 foreach my $required ( keys %{$create_sql->{$SCHEMA_VERSION}} ) { 148 153 if ( $tables{$required} ) { 149 154 print "Table $required already exists... skipping...\n"; 150 155 } else { 151 156 print "Creating table $required... done\n"; 152 foreach my $sql ( @{ $create_sql{$required}} ) {157 foreach my $sql ( @{$create_sql->{$SCHEMA_VERSION}->{$required}} ) { 153 158 $dbh->do($sql) or croak $dbh->errstr; 154 159 } … … 174 179 my %tables; 175 180 while ( my $table = $sth->fetchrow_array ) { 176 exists $create_sql {$table} and $tables{$table} = 1;181 exists $create_sql->{$SCHEMA_VERSION}->{$table} and $tables{$table} = 1; 177 182 } 178 183 return %tables; … … 215 220 216 221 print "Dropping tables... "; 217 $dbh->do("DROP TABLE IF EXISTS " . join( ",", keys % create_sql) )222 $dbh->do("DROP TABLE IF EXISTS " . join( ",", keys %{$create_sql->{$SCHEMA_VERSION}} ) ) 218 223 or croak $dbh->errstr; 219 224 print "done\n"; … … 246 251 dbhost => $_[3], 247 252 ); 253 } 254 255 sub _get_wanted_schema { 256 # Database handle passed in. 257 if ( ref $_[0] and ref $_[0] eq 'DBI::db' ) { 258 return undef; 259 } 260 261 # Args passed as hashref. 262 if ( ref $_[0] and ref $_[0] eq 'HASH' ) { 263 my %args = %{$_[0]}; 264 return $args{wanted_schema}; 265 } 266 267 # Args passed as list of connection details. 268 return $_[1]; 248 269 } 249 270
