Changeset 3063

Show
Ignore:
Timestamp:
01/15/08 18:15:28 (1 year ago)
Author:
coling
Message:

Hopefully fix #2418 by renaming the column 'user' to 'worker'. This requires some jiggery pokery in the db upgrade/install script in order to remain cross db-backend compatible (if it even is in the first place.... ;))

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • worklogplugin/0.11/worklog/api.py

    r2734 r3063  
    2929    def __init__(self): 
    3030        self.db_version_key = 'WorklogPlugin_Db_Version' 
    31         self.db_version = 2 
     31        self.db_version = 3 
    3232        self.db_installed_version = None 
    3333 
     
    7373        # Do the staged updates 
    7474        try: 
     75            # This var is to deal with a problem case with pgsql and the "user" 
     76            # keyword. We need to skip over new installations but not upgrades 
     77            # for other db backends. 
     78            skip = False 
     79             
    7580            if self.db_installed_version < 1: 
    7681                print 'Creating work_log table' 
    7782                cursor.execute('CREATE TABLE work_log (' 
    78                                'user       TEXT,' 
     83                               'worker     TEXT,' 
    7984                               'ticket     INTEGER,' 
    8085                               'lastchange INTEGER,' 
     
    8287                               'endtime    INTEGER' 
    8388                               ')') 
     89                skip = True 
    8490 
    8591            if self.db_installed_version < 2: 
     
    8894                               'ADD COLUMN comment TEXT') 
    8995 
    90             #if self.db_installed_version < 3: 
    91             #    print 'Updating work_log table (v3)' 
     96            if self.db_installed_version < 3: 
     97                print 'Updating work_log table (v3)' 
     98                if not skip: 
     99                    # This whole section is just to rename the "user" column to "worker" 
     100                    # This column used to be created in step 1 above, but we 
     101                    # can no longer do this in order to support pgsql. 
     102                    # This step is skipped if step 1 was also run (e.g. new installs) 
     103                    # The below seems to be the only way to rename (or drop) a column on sqlite *sigh* 
     104                    cursor.execute('CREATE TABLE work_log_tmp (' 
     105                                   'worker     TEXT,' 
     106                                   'ticket     INTEGER,' 
     107                                   'lastchange INTEGER,' 
     108                                   'starttime  INTEGER,' 
     109                                   'endtime    INTEGER,' 
     110                                   'comment    TEXT' 
     111                                   ')') 
     112                    cursor.execute('INSERT INTO work_log_tmp (worker, ticket, lastchange, starttime, endtime, comment) ' 
     113                                   'SELECT user, ticket, lastchange, starttime, endtime, comment FROM work_log') 
     114                    cursor.execute('DROP TABLE work_log') 
     115                    cursor.execute('ALTER TABLE work_log_tmp RENAME TO work_log') 
     116 
     117            #if self.db_installed_version < 4: 
     118            #    print 'Updating work_log table (v4)' 
    92119            #    cursor.execute('...') 
    93120             
  • worklogplugin/0.11/worklog/manager.py

    r2679 r3063  
    143143  
    144144        cursor = db.cursor() 
    145         cursor.execute('INSERT INTO work_log (user, ticket, lastchange, starttime, endtime) ' 
     145        cursor.execute('INSERT INTO work_log (worker, ticket, lastchange, starttime, endtime) ' 
    146146                       'VALUES (%s, %s, %s, %s, %s)', 
    147147                       (self.authname, ticket, self.now, self.now, 0)) 
     
    172172        cursor.execute('UPDATE work_log ' 
    173173                       'SET endtime=%s, lastchange=%s, comment=%s ' 
    174                        'WHERE user=%s AND lastchange=%s AND endtime=0', 
     174                       'WHERE worker=%s AND lastchange=%s AND endtime=0', 
    175175                       (stoptime, stoptime, comment, self.authname, active['lastchange'])) 
    176176        db.commit() 
     
    222222        db = self.env.get_db_cnx() 
    223223        cursor = db.cursor() 
    224         cursor.execute('SELECT user,starttime FROM work_log WHERE ticket=%s AND endtime=0', (ticket,)) 
     224        cursor.execute('SELECT worker,starttime FROM work_log WHERE ticket=%s AND endtime=0', (ticket,)) 
    225225        try: 
    226226            who,since = cursor.fetchone() 
     
    239239        db = self.env.get_db_cnx() 
    240240        cursor = db.cursor() 
    241         cursor.execute('SELECT MAX(lastchange) FROM work_log WHERE user=%s', (self.authname,)) 
     241        cursor.execute('SELECT MAX(lastchange) FROM work_log WHERE worker=%s', (self.authname,)) 
    242242        row = cursor.fetchone() 
    243243        if not row or not row[0]: 
     
    247247     
    248248        task = {} 
    249         cursor.execute('SELECT wl.user, wl.ticket, t.summary, wl.lastchange, wl.starttime, wl.endtime, wl.comment ' 
     249        cursor.execute('SELECT wl.worker, wl.ticket, t.summary, wl.lastchange, wl.starttime, wl.endtime, wl.comment ' 
    250250                       'FROM work_log wl ' 
    251251                       'LEFT JOIN ticket t ON wl.ticket=t.id ' 
    252                        'WHERE wl.user=%s AND wl.lastchange=%s', (self.authname, lastchange)) 
     252                       'WHERE wl.worker=%s AND wl.lastchange=%s', (self.authname, lastchange)) 
    253253 
    254254        for user,ticket,summary,lastchange,starttime,endtime,comment in cursor: 
     
    281281        cursor = db.cursor() 
    282282        if mode == 'user': 
    283             cursor.execute('SELECT wl.user, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
     283            cursor.execute('SELECT wl.worker, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
    284284                           'FROM work_log wl ' 
    285285                           'INNER JOIN ticket t ON wl.ticket=t.id ' 
    286                            'LEFT JOIN session_attribute s ON wl.user=s.sid AND s.name=\'name\' ' 
    287                            'WHERE wl.user=%s ' 
     286                           'LEFT JOIN session_attribute s ON wl.worker=s.sid AND s.name=\'name\' ' 
     287                           'WHERE wl.worker=%s ' 
    288288                           'ORDER BY wl.lastchange DESC', (self.authname,)) 
    289289        elif mode == 'summary': 
    290             cursor.execute('SELECT wl.user, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
    291                            'FROM (SELECT user,MAX(lastchange) lastchange FROM work_log GROUP BY user) wlt ' 
    292                            'INNER JOIN work_log wl ON wlt.user=wl.user AND wlt.lastchange=wl.lastchange ' 
     290            cursor.execute('SELECT wl.worker, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
     291                           'FROM (SELECT worker,MAX(lastchange) lastchange FROM work_log GROUP BY worker) wlt ' 
     292                           'INNER JOIN work_log wl ON wlt.worker=wl.worker AND wlt.lastchange=wl.lastchange ' 
    293293                           'INNER JOIN ticket t ON wl.ticket=t.id ' 
    294                            'LEFT JOIN session_attribute s ON wl.user=s.sid AND s.name=\'name\' ' 
    295                            'ORDER BY wl.lastchange DESC, wl.user') 
     294                           'LEFT JOIN session_attribute s ON wl.worker=s.sid AND s.name=\'name\' ' 
     295                           'ORDER BY wl.lastchange DESC, wl.worker') 
    296296        else: 
    297             cursor.execute('SELECT wl.user, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
     297            cursor.execute('SELECT wl.worker, s.value, wl.starttime, wl.endtime, wl.ticket, t.summary, t.status, wl.comment ' 
    298298                           'FROM work_log wl ' 
    299299                           'INNER JOIN ticket t ON wl.ticket=t.id ' 
    300                            'LEFT JOIN session_attribute s ON wl.user=s.sid AND s.name=\'name\' ' 
    301                            'ORDER BY wl.lastchange DESC, wl.user') 
     300                           'LEFT JOIN session_attribute s ON wl.worker=s.sid AND s.name=\'name\' ' 
     301                           'ORDER BY wl.lastchange DESC, wl.worker') 
    302302         
    303303        rv = [] 
  • worklogplugin/0.11/worklog/timeline_hook.py

    r3062 r3063  
    3434            cursor = db.cursor() 
    3535 
    36             cursor.execute("""SELECT wl.user,wl.ticket,wl.time,wl.starttime,wl.comment,wl.kind,t.summary,t.status,t.resolution,t.type 
     36            cursor.execute("""SELECT wl.worker,wl.ticket,wl.time,wl.starttime,wl.comment,wl.kind,t.summary,t.status,t.resolution,t.type 
    3737                             FROM ( 
    3838                              
    39                              SELECT user, ticket, starttime AS time, starttime, comment, 'start' AS kind 
     39                             SELECT worker, ticket, starttime AS time, starttime, comment, 'start' AS kind 
    4040                             FROM work_log 
    4141 
    4242                             UNION 
    4343 
    44                              SELECT user, ticket, endtime AS time, starttime, comment, 'stop' AS kind 
     44                             SELECT worker, ticket, endtime AS time, starttime, comment, 'stop' AS kind 
    4545                             FROM work_log 
    4646