File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77from trac .versioncontrol .api import RepositoryManager
88
99# Database version identifier for upgrades.
10- db_version = 4
10+ db_version = 5
1111db_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 \n This 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 \n The 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+
107133upgrade_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
You can’t perform that action at this time.
0 commit comments