| 1 | from trac.db import Table, Column, Index, DatabaseManager |
|---|
| 2 | |
|---|
| 3 | def do_upgrade(env, cursor): |
|---|
| 4 | |
|---|
| 5 | """Add 'description' column to the iteration table. |
|---|
| 6 | """ |
|---|
| 7 | cursor.execute("CREATE TEMPORARY TABLE iteration_old AS SELECT * FROM iteration") |
|---|
| 8 | cursor.execute("DROP TABLE iteration") |
|---|
| 9 | |
|---|
| 10 | # Milestone with 'after' |
|---|
| 11 | iteration_table = Table('iteration', key='id')[ |
|---|
| 12 | Column('id', auto_increment=True), |
|---|
| 13 | Column('summary'), |
|---|
| 14 | Column('description'), |
|---|
| 15 | Column('start_date', type='int'), |
|---|
| 16 | Column('end_date', type='int'), |
|---|
| 17 | Column('tickets'), |
|---|
| 18 | Index(['start_date']), |
|---|
| 19 | Index(['end_date'])] |
|---|
| 20 | |
|---|
| 21 | db_connector, _ = DatabaseManager(env)._get_connector() |
|---|
| 22 | for stmt in db_connector.to_sql(iteration_table): |
|---|
| 23 | cursor.execute(stmt) |
|---|
| 24 | |
|---|
| 25 | cursor.execute("INSERT INTO iteration " |
|---|
| 26 | "(id,summary,start_date,end_date,tickets) " |
|---|
| 27 | "SELECT id,summary,start_date,end_date,tickets " |
|---|
| 28 | "FROM iteration_old") |
|---|
| 29 | |
|---|
| 30 | cursor.execute("UPDATE iteration SET description=''") |
|---|
| 31 | |
|---|
| 32 | cursor.execute("DROP TABLE iteration_old") |
|---|
| 33 | |
|---|
| 34 | # Set database schema version. |
|---|
| 35 | cursor.execute("INSERT INTO system (name, value) VALUES" |
|---|
| 36 | " ('agiletrac_version', '2')") |
|---|