Skip to content

Commit 3ee0741

Browse files
committed
Migrate existing changeset comments
Remove the bogus line numbers and leave an explanation in the text of the comment.
1 parent fdaff49 commit 3ee0741

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

code_comments/db.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from trac.versioncontrol.api import RepositoryManager
88

99
# Database version identifier for upgrades.
10-
db_version = 4
10+
db_version = 5
1111
db_version_key = 'code_comments_schema_version'
1212

1313
# Database schema
@@ -104,10 +104,37 @@ def upgrade_from_3_to_4(env):
104104
""")
105105

106106

107+
def upgrade_from_4_to_5(env):
108+
with env.db_transaction as db:
109+
# The line numbers of all present comments on changesets are bogus,
110+
# see https://github.com/trac-hacks/trac-code-comments-plugin/issues/67
111+
# We therefore set them to 0 detaching the comment from the line. We leave a note in
112+
# the text of the comment explaining this.
113+
114+
notice = '\n\nThis comment was created by a previous version of the '\
115+
"code-comments plugin and '''is not properly attached to a line of code'''. "\
116+
'See [https://github.com/trac-hacks/trac-code-comments-plugin/issues/67 '\
117+
'issue #67].\n\nThe comment was originally placed on line $oldLineNumber$ of '\
118+
'the diff as it was displayed when the comment was created.'
119+
notice = notice.replace("'", "''")
120+
sql = """
121+
UPDATE code_comments
122+
SET
123+
line = 0,
124+
text = text || REPLACE('{0}', '$oldLineNumber$', line)
125+
WHERE
126+
type = 'changeset'
127+
AND
128+
line != 0
129+
"""
130+
db(sql.format(notice))
131+
132+
107133
upgrade_map = {
108134
2: upgrade_from_1_to_2,
109135
3: upgrade_from_2_to_3,
110136
4: upgrade_from_3_to_4,
137+
5: upgrade_from_4_to_5
111138
}
112139

113140

0 commit comments

Comments
 (0)