Ticket #40579: convert_to_postgresql.patch
File convert_to_postgresql.patch, 5.5 KB (added by elelay (Eric Le Lay), 11 years ago) |
---|
-
jobs/PortIndex2PGSQL.tcl
1 1 #!/opt/local/bin/tclsh 2 2 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4 3 3 # 4 # PortIndex2 MySQL.tcl4 # PortIndex2PGSQL.tcl 5 5 # Kevin Van Vechten | kevin@opendarwin.org 6 6 # 3-Oct-2002 7 7 # Juan Manuel Palacios | jmpp@macports.org 8 8 # 22-Nov-2007 9 # Eric Le Lay | elelay@macports.org 10 # 24-sept-2013 9 11 # $Id$ 10 12 # 13 # Copyright (c) 2013 Eric Le Lay, The Macports Project 11 14 # Copyright (c) 2007 Juan Manuel Palacios, The MacPorts Project. 12 15 # Copyright (c) 2003 Apple Inc. 13 16 # Copyright (c) 2002 Kevin Van Vechten. … … 39 42 40 43 41 44 ##### 42 # The PortIndex2 MySQL script populates a database with key information extracted45 # The PortIndex2PGSQL script populates a database with key information extracted 43 46 # from the Portfiles in the ports tree pointed to by the sources.conf file in a 44 47 # MacPorts installation, found by loading its macports1.0 tcl package and initializing 45 48 # it with 'mportinit' below. Main use of the resulting database is providing live … … 68 71 69 72 #set SPAM_LOVERS example@hostname.com 70 73 71 set SUBJECT "PortIndex2 MySQL run failure on $DATE"74 set SUBJECT "PortIndex2PGSQL run failure on $DATE" 72 75 set FROM macports-mgr@lists.macosforge.org 73 76 set HEADERS "To: $SPAM_LOVERS\r\nFrom: $FROM\r\nSubject: $SUBJECT\r\n\r\n" 74 77 … … 160 163 161 164 # SQL string escaping. 162 165 proc sql_escape {str} { 163 regsub -all -- {'} $str {\\'} str 164 regsub -all -- {"} $str {\\"} str 165 regsub -all -- {\n} $str {\\n} str 166 regsub -all -- {'} $str {''} str 166 167 return $str 167 168 } 168 169 … … 171 172 172 173 # Check if there are any stray sibling jobs before moving on, bail in such case. 173 174 if {[file exists $lockfile]} { 174 puts $runlog_fd "PortIndex2 MySQL lock file found, is another job running?"175 puts $runlog_fd "PortIndex2PGSQL lock file found, is another job running?" 175 176 terminate 1 176 177 } else { 177 178 set lockfile_fd [open $lockfile a] … … 210 211 set portsdb_user macports 211 212 set passwdfile "/opt/local/share/macports/resources/portmgr/password_file" 212 213 set portsdb_passwd [getpasswd $passwdfile] 213 set portsdb_cmd [macports::findBinary mysql5]214 set portsdb_cmd [macports::findBinary psql] 214 215 215 216 216 217 # Flat text file to which sql statements are written. … … 241 242 # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms. 242 243 # Do we need any other? 243 244 puts $sqlfile_fd "DROP TABLE IF EXISTS log;" 244 puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP (14)) DEFAULT CHARSET=utf8;"245 puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP);" 245 246 246 247 puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;" 247 puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255), description TEXT) DEFAULT CHARSET=utf8;"248 puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255), description TEXT);" 248 249 249 250 puts $sqlfile_fd "DROP TABLE IF EXISTS categories;" 250 puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"251 puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER);" 251 252 252 253 puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;" 253 puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"254 puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER);" 254 255 255 256 puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;" 256 puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;"257 puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255));" 257 258 258 259 puts $sqlfile_fd "DROP TABLE IF EXISTS variants;" 259 puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;"260 puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255));" 260 261 261 262 puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;" 262 puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;"263 puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255));" 263 264 264 265 puts $sqlfile_fd "DROP TABLE IF EXISTS licenses;" 265 puts $sqlfile_fd "CREATE TABLE licenses (portfile VARCHAR(255), license VARCHAR(255)) DEFAULT CHARSET=utf8;"266 puts $sqlfile_fd "CREATE TABLE licenses (portfile VARCHAR(255), license VARCHAR(255));" 266 267 } else { 267 268 # if we are not creating tables from scratch, remove the old data 268 269 puts $sqlfile_fd "TRUNCATE log;" … … 414 415 terminate 1 415 416 } 416 417 417 if {[catch {exec -- $portsdb_cmd --host=$portsdb_host --user=$portsdb_user --password=$portsdb_passwd --database=$portsdb_name <@ $sqlfile_fd} errstr]} { 418 # psql will read the password from the file all by itself... 419 global env 420 set env(PGPASSFILE) $passwdfile 421 if {[catch {exec -- $portsdb_cmd -q --host=$portsdb_host $portsdb_name $portsdb_user <@ $sqlfile_fd} errstr]} { 418 422 ui_error "${::errorCode}: $errstr" 419 423 cleanup sqlfile lockfile 420 424 terminate 1