~ubuntu-branches/ubuntu/quantal/griffith/quantal

« back to all changes in this revision

Viewing changes to lib/dbupgrade.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2011-12-18 21:15:25 UTC
  • mfrom: (1.1.17) (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111218211525-endbgt82m3jh9gde
Tags: 0.13-1
* New upstream release
* VCS-* fields removed (berlios will be shutdown)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: UTF-8 -*-
2
2
# vim: fdm=marker
3
3
 
4
 
__revision__ = '$Id: dbupgrade.py 1473 2010-10-18 20:24:43Z mikej06 $'
 
4
__revision__ = '$Id: dbupgrade.py 1596 2011-10-04 18:41:03Z piotrek $'
5
5
 
6
6
# Copyright (c) 2005-2009 Vasco Nunes, Piotr Ożarowski
7
7
#
162
162
            try:
163
163
                self.session.bind.execute(query)
164
164
            except OperationalError, e:
165
 
                if e.message.find(b'(OperationalError) duplicate column name:') > -1:
 
165
                if e.message.lower().find('duplicate column name') > -1:
166
166
                    log.warn("Cannot add '%s' column because it exists already: %s", key, e)
167
167
                    continue
168
168
                else:
265
265
    if version == 5:    # fix changes between v5 and v6
266
266
        version += 1
267
267
        log.info("Upgrading database to version %d...", version)
268
 
        
 
268
 
269
269
        # common SQL statements
270
 
        queries = {'created': 'ALTER TABLE movies ADD created DATETIME;',
271
 
                   'updated': 'ALTER TABLE movies ADD updated DATETIME;'}
 
270
        if self.session.bind.name in ['postgres', 'postgresql']:
 
271
            queries = {'created': 'ALTER TABLE movies ADD created TIMESTAMP;',
 
272
                       'updated': 'ALTER TABLE movies ADD updated TIMESTAMP;'}
 
273
        else:
 
274
            queries = {'created': 'ALTER TABLE movies ADD created DATETIME;',
 
275
                       'updated': 'ALTER TABLE movies ADD updated DATETIME;'}
272
276
        for key, query in queries.items():
273
277
            try:
274
278
                self.session.bind.execute(query)