247 | | if {$create_tables} { |
248 | | # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms. |
249 | | # Do we need any other? |
250 | | puts $sqlfile_fd "DROP TABLE IF EXISTS log;" |
251 | | puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP(14)) DEFAULT CHARSET=utf8;" |
252 | | |
253 | | puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;" |
254 | | puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255), description TEXT) DEFAULT CHARSET=utf8;" |
255 | | |
256 | | puts $sqlfile_fd "DROP TABLE IF EXISTS categories;" |
257 | | puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;" |
258 | | |
259 | | puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;" |
260 | | puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;" |
261 | | |
262 | | puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;" |
263 | | puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;" |
264 | | |
265 | | puts $sqlfile_fd "DROP TABLE IF EXISTS variants;" |
266 | | puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;" |
267 | | |
268 | | puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;" |
269 | | puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;" |
| 247 | # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms. |
| 248 | puts $sqlfile_fd "DROP TABLE IF EXISTS log_new;" |
| 249 | puts $sqlfile_fd "CREATE TABLE log_new (activity VARCHAR(255), activity_time TIMESTAMP(14)) DEFAULT CHARSET=utf8;" |
271 | | puts $sqlfile_fd "DROP TABLE IF EXISTS licenses;" |
272 | | puts $sqlfile_fd "CREATE TABLE licenses (portfile VARCHAR(255), license VARCHAR(255)) DEFAULT CHARSET=utf8;" |
273 | | } else { |
274 | | # if we are not creating tables from scratch, remove the old data |
275 | | puts $sqlfile_fd "TRUNCATE log;" |
276 | | puts $sqlfile_fd "TRUNCATE portfiles;" |
277 | | puts $sqlfile_fd "TRUNCATE categories;" |
278 | | puts $sqlfile_fd "TRUNCATE maintainers;" |
279 | | puts $sqlfile_fd "TRUNCATE dependencies;" |
280 | | puts $sqlfile_fd "TRUNCATE variants;" |
281 | | puts $sqlfile_fd "TRUNCATE platforms;" |
282 | | puts $sqlfile_fd "TRUNCATE licenses;" |
283 | | } |
| 251 | puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles_new;" |
| 252 | puts $sqlfile_fd "CREATE TABLE portfiles_new (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255), description TEXT) DEFAULT CHARSET=utf8;" |
| 253 | |
| 254 | puts $sqlfile_fd "DROP TABLE IF EXISTS categories_new;" |
| 255 | puts $sqlfile_fd "CREATE TABLE categories_new (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;" |
| 256 | |
| 257 | puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers_new;" |
| 258 | puts $sqlfile_fd "CREATE TABLE maintainers_new (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;" |
| 259 | |
| 260 | puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies_new;" |
| 261 | puts $sqlfile_fd "CREATE TABLE dependencies_new (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;" |
| 262 | |
| 263 | puts $sqlfile_fd "DROP TABLE IF EXISTS variants_new;" |
| 264 | puts $sqlfile_fd "CREATE TABLE variants_new (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;" |
| 265 | |
| 266 | puts $sqlfile_fd "DROP TABLE IF EXISTS platforms_new;" |
| 267 | puts $sqlfile_fd "CREATE TABLE platforms_new (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;" |
| 268 | |
| 269 | puts $sqlfile_fd "DROP TABLE IF EXISTS licenses_new;" |
| 270 | puts $sqlfile_fd "CREATE TABLE licenses_new (portfile VARCHAR(255), license VARCHAR(255)) DEFAULT CHARSET=utf8;" |
| 402 | if {$create_tables} { |
| 403 | puts $sqlfile_fd "RENAME TABLE \ |
| 404 | portfiles_new TO portfiles, \ |
| 405 | categories_new TO categories, \ |
| 406 | maintainers_new TO maintainers, \ |
| 407 | dependencies_new TO dependencies, \ |
| 408 | variants_new TO variants, \ |
| 409 | platforms_new TO platforms, \ |
| 410 | licenses_new TO licenses_old, \ |
| 411 | log_new TO log;" |
| 412 | } else { |
| 413 | puts $sqlfile_fd "RENAME TABLE \ |
| 414 | portfiles TO portfiles_old, \ |
| 415 | portfiles_new TO portfiles, \ |
| 416 | categories TO categories_old, \ |
| 417 | categories_new TO categories, \ |
| 418 | maintainers TO maintainers_old, \ |
| 419 | maintainers_new TO maintainers, \ |
| 420 | dependencies TO dependencies_old, \ |
| 421 | dependencies_new TO dependencies, \ |
| 422 | variants TO variants_old, \ |
| 423 | variants_new TO variants, \ |
| 424 | platforms TO platforms_old, \ |
| 425 | platforms_new TO platforms, \ |
| 426 | licenses TO licenses_old, \ |
| 427 | licenses_new TO licenses_old, \ |
| 428 | log TO log_old, \ |
| 429 | log_new TO log;" |
| 430 | } |
| 431 | |
| 432 | puts $sqlfile_fd "DROP TABLES IF EXISTS \ |
| 433 | portfiles_old, \ |
| 434 | categories_old, \ |
| 435 | maintainers_old, \ |
| 436 | dependencies_old, \ |
| 437 | variants_old, \ |
| 438 | platforms_old, \ |
| 439 | licenses_old, \ |
| 440 | log_old;" |
| 441 | |