source: weekplanplugin/trunk/weekplan/upgrades/db2.py

Last change on this file was 16115, checked in by lucid, 7 years ago

WeekPlanPlugin: Trac 1.3 compatible DB upgrades.
Since trac:ticket:11901 we would have to use get_connector instead of _get_connector.
Since trac:ticket:11512 we can use create_tables helper to simplify this.

File size: 1.1 KB
Line 
1from trac.db import Table, Column, Index, DatabaseManager
2
3new_table = Table('weekplan', key='id')[
4        Column('id', auto_increment=True),
5        Column('plan'),
6        Column('title'),
7        Column('start', type='int64'),
8        Column('end', type='int64'),
9        Index(['plan', 'start', 'end']),
10    ]
11
12
13def do_upgrade(env, ver, cursor):
14    cursor.execute("CREATE TEMPORARY TABLE weekplan_old AS SELECT * FROM weekplan")
15    cursor.execute("DROP TABLE weekplan")
16
17    DatabaseManager(env).create_tables([new_table])
18
19    # Round start and end to full days (integer division is truncate, so add half a day to get rounding instead)
20    # Add one day to end as this is now "exclusive"
21    cursor.execute("""
22        INSERT INTO weekplan (id, plan, title, start, end)
23        SELECT o.id, o.plan, o.title,
24            ((o.start + 12*60*60*1000*1000)/(24*60*60*1000*1000))*(24*60*60*1000*1000),
25            ((o.end   + 12*60*60*1000*1000)/(24*60*60*1000*1000)+1)*(24*60*60*1000*1000)
26        FROM weekplan_old o
27        """)
28    cursor.execute("DROP TABLE weekplan_old")
Note: See TracBrowser for help on using the repository browser.