Changeset 440 for wiki-toolkit/trunk/lib/Wiki/Toolkit/Setup/SQLite.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/SQLite.pm
r438 r440 16 16 17 17 my $create_sql = { 18 8 => { 19 schema_info => [ qq| 20 CREATE TABLE schema_info ( 21 version integer NOT NULL default 0 22 ); 23 |, qq| 24 INSERT INTO schema_info VALUES (8) 25 | ], 26 node => [ qq| 27 CREATE 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| 36 CREATE 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| 46 CREATE 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| 53 CREATE 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 }, 18 61 9 => { 19 62 schema_info => [ qq| … … 112 155 my $wanted_schema = _get_wanted_schema( @args ) || $SCHEMA_VERSION; 113 156 157 die "No schema information for requested schema version $wanted_schema\n" 158 unless $create_sql->{$wanted_schema}; 159 114 160 # 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); 116 162 117 163 # Do we need to upgrade the schema? … … 131 177 132 178 # Grab new list of tables 133 %tables = fetch_tables_listing($dbh );179 %tables = fetch_tables_listing($dbh, $wanted_schema); 134 180 } 135 181 136 182 # Set up tables if not found 137 foreach my $required ( keys %{$create_sql->{$ SCHEMA_VERSION}} ) {183 foreach my $required ( keys %{$create_sql->{$wanted_schema}} ) { 138 184 if ( $tables{$required} ) { 139 185 print "Table $required already exists... skipping...\n"; 140 186 } else { 141 187 print "Creating table $required... done\n"; 142 foreach my $sql (@{$create_sql->{$ SCHEMA_VERSION}->{$required}} ) {188 foreach my $sql (@{$create_sql->{$wanted_schema}->{$required}} ) { 143 189 $dbh->do($sql) or croak $dbh->errstr; 144 190 } … … 158 204 sub fetch_tables_listing { 159 205 my $dbh = shift; 206 my $wanted_schema = shift; 160 207 161 208 # Check whether tables exist, set them up if not. 162 209 my $sql = "SELECT name FROM sqlite_master 163 210 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}} ) . ")"; 165 212 my $sth = $dbh->prepare($sql) or croak $dbh->errstr; 166 213 $sth->execute; … … 245 292 return $args{wanted_schema}; 246 293 } 247 248 # Args passed as list of connection details.249 return $_[1];250 294 } 251 295
