Ticket #46111: PortIndex2MySQL.tcl.diff

File PortIndex2MySQL.tcl.diff, 8.5 KB (added by nerdling (Jeremy Lavergne), 10 years ago)
  • portmgr/jobs/PortIndex2MySQL.tcl

     
    244244    terminate 1
    245245}
    246246
    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.
     248puts $sqlfile_fd "DROP TABLE IF EXISTS log_new;"
     249puts $sqlfile_fd "CREATE TABLE log_new (activity VARCHAR(255), activity_time TIMESTAMP(14)) DEFAULT CHARSET=utf8;"
    270250
    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 }
     251puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles_new;"
     252puts $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
     254puts $sqlfile_fd "DROP TABLE IF EXISTS categories_new;"
     255puts $sqlfile_fd "CREATE TABLE categories_new (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
     256
     257puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers_new;"
     258puts $sqlfile_fd "CREATE TABLE maintainers_new (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
     259
     260puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies_new;"
     261puts $sqlfile_fd "CREATE TABLE dependencies_new (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;"
     262
     263puts $sqlfile_fd "DROP TABLE IF EXISTS variants_new;"
     264puts $sqlfile_fd "CREATE TABLE variants_new (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;"
     265
     266puts $sqlfile_fd "DROP TABLE IF EXISTS platforms_new;"
     267puts $sqlfile_fd "CREATE TABLE platforms_new (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;"
     268
     269puts $sqlfile_fd "DROP TABLE IF EXISTS licenses_new;"
     270puts $sqlfile_fd "CREATE TABLE licenses_new (portfile VARCHAR(255), license VARCHAR(255)) DEFAULT CHARSET=utf8;"
    284271 
    285272# Iterate over each matching port, extracting its information from the
    286273# portinfo array.
    287274foreach {name array} $ports {
     275    puts $sqlfile_fd "START TRANSACTION;"
    288276
    289277    array unset portinfo
    290278    array set portinfo $array
     
    352340        set licenses ""
    353341    }
    354342
    355     puts $sqlfile_fd "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description');"
     343    puts $sqlfile_fd "INSERT INTO portfiles_new VALUES ('$portname', '$portdir', '$portversion', '$description');"
    356344
    357345    set primary 1
    358346    foreach category $categories {
    359347        set category [sql_escape $category]
    360         puts $sqlfile_fd "INSERT INTO categories VALUES ('$portname', '$category', $primary);"
     348        puts $sqlfile_fd "INSERT INTO categories_new VALUES ('$portname', '$category', $primary);"
    361349        set primary 0
    362350    }
    363351   
    364352    set primary 1
    365353    foreach maintainer $maintainers {
    366354        set maintainer [sql_escape $maintainer]
    367         puts $sqlfile_fd "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary);"
     355        puts $sqlfile_fd "INSERT INTO maintainers_new VALUES ('$portname', '$maintainer', $primary);"
    368356        set primary 0
    369357    }
    370358
    371359    foreach fetch_dep $depends_fetch {
    372360        set fetch_dep [sql_escape $fetch_dep]
    373         puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$fetch_dep');"
     361        puts $sqlfile_fd "INSERT INTO dependencies_new VALUES ('$portname', '$fetch_dep');"
    374362    }
    375363   
    376364    foreach extract_dep $depends_extract {
    377365        set extract_dep [sql_escape $extract_dep]
    378         puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$extract_dep');"
     366        puts $sqlfile_fd "INSERT INTO dependencies_new VALUES ('$portname', '$extract_dep');"
    379367    }
    380368
    381369    foreach build_dep $depends_build {
    382370        set build_dep [sql_escape $build_dep]
    383         puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$build_dep');"
     371        puts $sqlfile_fd "INSERT INTO dependencies_new VALUES ('$portname', '$build_dep');"
    384372    }
    385373
    386374    foreach lib $depends_lib {
    387375        set lib [sql_escape $lib]
    388         puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$lib');"
     376        puts $sqlfile_fd "INSERT INTO dependencies_new VALUES ('$portname', '$lib');"
    389377    }
    390378
    391379    foreach run_dep $depends_run {
    392380        set run_dep [sql_escape $run_dep]
    393         puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$run_dep');"
     381        puts $sqlfile_fd "INSERT INTO dependencies_new VALUES ('$portname', '$run_dep');"
    394382    }
    395383
    396384    foreach variant $variants {
    397385        set variant [sql_escape $variant]
    398         puts $sqlfile_fd "INSERT INTO variants VALUES ('$portname', '$variant');"
     386        puts $sqlfile_fd "INSERT INTO variants_new VALUES ('$portname', '$variant');"
    399387    }
    400388
    401389    foreach platform $platforms {
    402390        set platform [sql_escape $platform]
    403         puts $sqlfile_fd "INSERT INTO platforms VALUES ('$portname', '$platform');"
     391        puts $sqlfile_fd "INSERT INTO platforms_new VALUES ('$portname', '$platform');"
    404392    }
    405393
    406394    foreach license $licenses {
    407395        set license [sql_escape $license]
    408         puts $sqlfile_fd "INSERT INTO licenses VALUES ('$portname', '$license');"
     396        puts $sqlfile_fd "INSERT INTO licenses_new VALUES ('$portname', '$license');"
    409397    }
     398    puts $sqlfile_fd "COMMIT;"
    410399
    411400}
    412401
     402if {$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
     432puts $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
    413442# Mark the db regen as done only once we're done processing all ports:
    414443puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW());"
    415444