Skip to content

Commit 80142bd

Browse files
committed
Migrate existing changeset comments
Remove the bogus line numbers and leave an explanation in the text of the comment.
1 parent 5db945f commit 80142bd

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
@@ -105,10 +105,37 @@ def upgrade_from_3_to_4(env):
105105
""")
106106

107107

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

114141

0 commit comments

Comments
 (0)