Skip to content

Commit

Permalink
Changed revision as a string in order to use Git repository. Table da…
Browse files Browse the repository at this point in the history
…ta migration. Fixes trac-hacks#13
  • Loading branch information
ntesteca committed Sep 10, 2012
1 parent fce63fb commit a5a87f7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions code_comments/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from trac.db.api import DatabaseManager

# Database version identifier for upgrades.
db_version = 1
db_version = 2

# Database schema
schema = {
Expand All @@ -13,7 +13,7 @@
Column('version', type='int'),
Column('text'),
Column('path'),
Column('revision', type='int'),
Column('revision'),
Column('line', type='int'),
Column('author'),
Column('time', type='int'),
Expand All @@ -36,7 +36,23 @@ def create_tables(env, db):
str(db_version))
# Upgrades
def upgrade_from_1_to_2(env, db):
pass
columns = [c.name for c in schema['code_comments'].columns]
cursor = db.cursor()
values = cursor.execute('PRAGMA INDEX_LIST(`code_comments`)')
indexes = values.fetchall()
for index in indexes:
if index[1].startswith('code_comments'):
cursor.execute('DROP INDEX IF EXISTS %s' % index[1])
values = cursor.execute('SELECT %s FROM code_comments' % ','.join(columns))
lines = values.fetchall()
cursor.execute('ALTER TABLE code_comments RENAME TO tmp_code_comments')
for stmt in to_sql(env, schema['code_comments']):
cursor.execute(stmt)
for line in lines:
ins = 'INSERT INTO code_comments (%s) VALUES (%s)' % (','.join(columns), ','.join(['\'%s\'' % str(v).replace('\'','\'\'') for v in line]))
print ins
cursor.execute(ins)
cursor.execute('DROP TABLE tmp_code_comments')

upgrade_map = {
2: upgrade_from_1_to_2
Expand Down

1 comment on commit a5a87f7

@rjollos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the plugin isn't maintained anymore, so I made a fork with improvements: https://github.com/trac-hacks/trac-code-comments-plugin. If you rebase your patch and open a pull request against the fork I will review it.

Please sign in to comment.