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

     
    11#!/opt/local/bin/tclsh
    22# -*- 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
    33#
    4 # PortIndex2MySQL.tcl
     4# PortIndex2PGSQL.tcl
    55# Kevin Van Vechten | kevin@opendarwin.org
    66# 3-Oct-2002
    77# Juan Manuel Palacios | jmpp@macports.org
    88# 22-Nov-2007
     9# Eric Le Lay | elelay@macports.org
     10# 24-sept-2013
    911# $Id$
    1012#
     13# Copyright (c) 2013 Eric Le Lay, The Macports Project
    1114# Copyright (c) 2007 Juan Manuel Palacios, The MacPorts Project.
    1215# Copyright (c) 2003 Apple Inc.
    1316# Copyright (c) 2002 Kevin Van Vechten.
     
    3942
    4043
    4144#####
    42 # The PortIndex2MySQL script populates a database with key information extracted
     45# The PortIndex2PGSQL script populates a database with key information extracted
    4346# from the Portfiles in the ports tree pointed to by the sources.conf file in a
    4447# MacPorts installation, found by loading its macports1.0 tcl package and initializing
    4548# it with 'mportinit' below. Main use of the resulting database is providing live
     
    6871
    6972#set SPAM_LOVERS example@hostname.com
    7073
    71 set SUBJECT "PortIndex2MySQL run failure on $DATE"
     74set SUBJECT "PortIndex2PGSQL run failure on $DATE"
    7275set FROM macports-mgr@lists.macosforge.org
    7376set HEADERS "To: $SPAM_LOVERS\r\nFrom: $FROM\r\nSubject: $SUBJECT\r\n\r\n"
    7477
     
    160163
    161164# SQL string escaping.
    162165proc 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
    166167    return $str
    167168}
    168169
     
    171172
    172173# Check if there are any stray sibling jobs before moving on, bail in such case.
    173174if {[file exists $lockfile]} {
    174     puts $runlog_fd "PortIndex2MySQL lock file found, is another job running?"
     175    puts $runlog_fd "PortIndex2PGSQL lock file found, is another job running?"
    175176    terminate 1
    176177} else {
    177178    set lockfile_fd [open $lockfile a]
     
    210211set portsdb_user macports
    211212set passwdfile "/opt/local/share/macports/resources/portmgr/password_file"
    212213set portsdb_passwd [getpasswd $passwdfile]
    213 set portsdb_cmd [macports::findBinary mysql5]
     214set portsdb_cmd [macports::findBinary psql]
    214215
    215216
    216217# Flat text file to which sql statements are written.
     
    241242    # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
    242243    # Do we need any other?
    243244    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);"
    245246   
    246247    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);"
    248249   
    249250    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);"
    251252   
    252253    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);"
    254255   
    255256    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));"
    257258   
    258259    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));"
    260261   
    261262    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));"
    263264
    264265    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));"
    266267} else {
    267268    # if we are not creating tables from scratch, remove the old data
    268269    puts $sqlfile_fd "TRUNCATE log;"
     
    414415    terminate 1
    415416}
    416417
    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...
     419global env
     420set env(PGPASSFILE) $passwdfile
     421if {[catch {exec -- $portsdb_cmd -q --host=$portsdb_host $portsdb_name $portsdb_user <@ $sqlfile_fd} errstr]} {
    418422    ui_error "${::errorCode}: $errstr"
    419423    cleanup sqlfile lockfile
    420424    terminate 1