| 1 | from trac.db import Table, Column, Index, DatabaseManager |
|---|
| 2 | |
|---|
| 3 | new_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 | |
|---|
| 13 | def 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") |
|---|