| 57 | | sql = """ |
|---|
| 58 | | CREATE TABLE trac_unread ( |
|---|
| 59 | | username text, |
|---|
| 60 | | last_read_on integer, |
|---|
| 61 | | type text, |
|---|
| 62 | | id text, |
|---|
| 63 | | UNIQUE (type, id, username) |
|---|
| 64 | | ); |
|---|
| 65 | | """ |
|---|
| | 58 | |
|---|
| | 59 | unread_table = Table('trac_unread', key=('type', 'id', 'username'))[ |
|---|
| | 60 | Column('username'), |
|---|
| | 61 | Column('last_read_on', type='int'), |
|---|
| | 62 | Column('type'), |
|---|
| | 63 | Column('id'), |
|---|
| | 64 | Index(['type']), |
|---|
| | 65 | Index(['id']), |
|---|
| | 66 | Index(['username'])] |
|---|
| | 67 | |
|---|
| | 68 | db_backend, _ = DatabaseManager(self.env)._get_connector() |
|---|
| | 69 | |
|---|
| | 70 | for stmt in db_backend.to_sql(unread_table): |
|---|
| | 71 | try: |
|---|
| | 72 | cur.execute(stmt) |
|---|
| | 73 | except Exception, e: |
|---|
| | 74 | print "Upgrade failed\nSQL:\n%s\nError message: %s" % (stmt, e) |
|---|
| | 75 | db.rollback(); |
|---|
| | 76 | return |
|---|
| | 77 | |
|---|
| | 78 | # This statement block always goes at the end this method |
|---|
| 67 | | cur.execute(sql) |
|---|
| 68 | | |
|---|
| 69 | | # This statement block always goes at the end this method |
|---|
| 70 | | try: |
|---|
| 71 | | cur.execute("UPDATE system SET value=%s WHERE name=%s", |
|---|
| 72 | | (self.db_version, self.db_version_key)) |
|---|
| 73 | | except: |
|---|
| 74 | | cur.execute("INSERT INTO system (value, name) VALUES (%s, %s)", |
|---|
| 75 | | (self.db_version, self.db_version_key)) |
|---|
| | 80 | cur.execute("UPDATE system SET value=%s WHERE name=%s", |
|---|
| | 81 | (self.db_version, self.db_version_key)) |
|---|
| | 82 | except: |
|---|
| | 83 | cur.execute("INSERT INTO system (value, name) VALUES (%s, %s)", |
|---|
| | 84 | (self.db_version, self.db_version_key)) |
|---|