Show More
@@ -26,6 +26,7 b'' | |||||
26 |
|
26 | |||
27 | import os |
|
27 | import os | |
28 | import sys |
|
28 | import sys | |
|
29 | import time | |||
29 | import uuid |
|
30 | import uuid | |
30 | import logging |
|
31 | import logging | |
31 | from os.path import dirname as dn, join as jn |
|
32 | from os.path import dirname as dn, join as jn | |
@@ -56,7 +57,164 b' def notify(msg):' | |||||
56 | Notification for migrations messages |
|
57 | Notification for migrations messages | |
57 | """ |
|
58 | """ | |
58 | ml = len(msg) + (4 * 2) |
|
59 | ml = len(msg) + (4 * 2) | |
59 |
print |
|
60 | print('\n%s\n*** %s ***\n%s' % ('*' * ml, msg, '*' * ml)).upper() | |
|
61 | ||||
|
62 | ||||
|
63 | class UpgradeSteps(object): | |||
|
64 | """ | |||
|
65 | Those steps follow schema versions so for example schema | |||
|
66 | for example schema with seq 002 == step_2 and so on. | |||
|
67 | """ | |||
|
68 | ||||
|
69 | def __init__(self, klass): | |||
|
70 | self.klass = klass | |||
|
71 | ||||
|
72 | def step_1(self): | |||
|
73 | pass | |||
|
74 | ||||
|
75 | def step_2(self): | |||
|
76 | notify('Patching repo paths for newer version of RhodeCode') | |||
|
77 | self.klass.fix_repo_paths() | |||
|
78 | ||||
|
79 | notify('Patching default user of RhodeCode') | |||
|
80 | self.klass.fix_default_user() | |||
|
81 | ||||
|
82 | log.info('Changing ui settings') | |||
|
83 | self.klass.create_ui_settings() | |||
|
84 | ||||
|
85 | def step_3(self): | |||
|
86 | notify('Adding additional settings into RhodeCode db') | |||
|
87 | self.klass.fix_settings() | |||
|
88 | notify('Adding ldap defaults') | |||
|
89 | self.klass.create_ldap_options(skip_existing=True) | |||
|
90 | ||||
|
91 | def step_4(self): | |||
|
92 | notify('create permissions and fix groups') | |||
|
93 | self.klass.create_permissions() | |||
|
94 | self.klass.fixup_groups() | |||
|
95 | ||||
|
96 | def step_5(self): | |||
|
97 | pass | |||
|
98 | ||||
|
99 | def step_6(self): | |||
|
100 | ||||
|
101 | notify('re-checking permissions') | |||
|
102 | self.klass.create_permissions() | |||
|
103 | ||||
|
104 | notify('installing new UI options') | |||
|
105 | sett4 = RhodeCodeSetting('show_public_icon', True) | |||
|
106 | Session().add(sett4) | |||
|
107 | sett5 = RhodeCodeSetting('show_private_icon', True) | |||
|
108 | Session().add(sett5) | |||
|
109 | sett6 = RhodeCodeSetting('stylify_metatags', False) | |||
|
110 | Session().add(sett6) | |||
|
111 | ||||
|
112 | notify('fixing old PULL hook') | |||
|
113 | _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger') | |||
|
114 | if _pull: | |||
|
115 | _pull.ui_key = RhodeCodeUi.HOOK_PULL | |||
|
116 | Session().add(_pull) | |||
|
117 | ||||
|
118 | notify('fixing old PUSH hook') | |||
|
119 | _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger') | |||
|
120 | if _push: | |||
|
121 | _push.ui_key = RhodeCodeUi.HOOK_PUSH | |||
|
122 | Session().add(_push) | |||
|
123 | ||||
|
124 | notify('installing new pre-push hook') | |||
|
125 | hooks4 = RhodeCodeUi() | |||
|
126 | hooks4.ui_section = 'hooks' | |||
|
127 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH | |||
|
128 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' | |||
|
129 | Session().add(hooks4) | |||
|
130 | ||||
|
131 | notify('installing new pre-pull hook') | |||
|
132 | hooks6 = RhodeCodeUi() | |||
|
133 | hooks6.ui_section = 'hooks' | |||
|
134 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL | |||
|
135 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' | |||
|
136 | Session().add(hooks6) | |||
|
137 | ||||
|
138 | notify('installing hgsubversion option') | |||
|
139 | # enable hgsubversion disabled by default | |||
|
140 | hgsubversion = RhodeCodeUi() | |||
|
141 | hgsubversion.ui_section = 'extensions' | |||
|
142 | hgsubversion.ui_key = 'hgsubversion' | |||
|
143 | hgsubversion.ui_value = '' | |||
|
144 | hgsubversion.ui_active = False | |||
|
145 | Session().add(hgsubversion) | |||
|
146 | ||||
|
147 | notify('installing hg git option') | |||
|
148 | # enable hggit disabled by default | |||
|
149 | hggit = RhodeCodeUi() | |||
|
150 | hggit.ui_section = 'extensions' | |||
|
151 | hggit.ui_key = 'hggit' | |||
|
152 | hggit.ui_value = '' | |||
|
153 | hggit.ui_active = False | |||
|
154 | Session().add(hggit) | |||
|
155 | ||||
|
156 | notify('re-check default permissions') | |||
|
157 | default_user = User.get_by_username(User.DEFAULT_USER) | |||
|
158 | perm = Permission.get_by_key('hg.fork.repository') | |||
|
159 | reg_perm = UserToPerm() | |||
|
160 | reg_perm.user = default_user | |||
|
161 | reg_perm.permission = perm | |||
|
162 | Session().add(reg_perm) | |||
|
163 | ||||
|
164 | def step_7(self): | |||
|
165 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) | |||
|
166 | Session().commit() | |||
|
167 | if perm_fixes: | |||
|
168 | notify('There was an inconsistent state of permissions ' | |||
|
169 | 'detected for default user. Permissions are now ' | |||
|
170 | 'reset to the default value for default user. ' | |||
|
171 | 'Please validate and check default permissions ' | |||
|
172 | 'in admin panel') | |||
|
173 | ||||
|
174 | def step_8(self): | |||
|
175 | self.klass.create_permissions() | |||
|
176 | self.klass.populate_default_permissions() | |||
|
177 | self.klass.create_default_options(skip_existing=True) | |||
|
178 | Session().commit() | |||
|
179 | ||||
|
180 | def step_9(self): | |||
|
181 | pass | |||
|
182 | ||||
|
183 | def step_10(self): | |||
|
184 | pass | |||
|
185 | ||||
|
186 | def step_11(self): | |||
|
187 | self.klass.update_repo_info() | |||
|
188 | ||||
|
189 | def step_12(self): | |||
|
190 | self.klass.create_permissions() | |||
|
191 | Session().commit() | |||
|
192 | ||||
|
193 | self.klass.populate_default_permissions() | |||
|
194 | Session().commit() | |||
|
195 | ||||
|
196 | #fix all usergroups | |||
|
197 | ug_model = UserGroupModel() | |||
|
198 | for ug in UserGroup.get_all(): | |||
|
199 | perm_obj = ug_model._create_default_perms(ug) | |||
|
200 | Session().add(perm_obj) | |||
|
201 | Session().commit() | |||
|
202 | ||||
|
203 | adm = User.get_first_admin() | |||
|
204 | # fix owners of UserGroup | |||
|
205 | for ug in Session().query(UserGroup).all(): | |||
|
206 | ug.user_id = adm.user_id | |||
|
207 | Session().add(ug) | |||
|
208 | Session().commit() | |||
|
209 | ||||
|
210 | # fix owners of RepoGroup | |||
|
211 | for ug in Session().query(RepoGroup).all(): | |||
|
212 | ug.user_id = adm.user_id | |||
|
213 | Session().add(ug) | |||
|
214 | Session().commit() | |||
|
215 | ||||
|
216 | def step_13(self): | |||
|
217 | pass | |||
60 |
|
218 | |||
61 |
|
219 | |||
62 | class DbManage(object): |
|
220 | class DbManage(object): | |
@@ -155,173 +313,6 b' class DbManage(object):' | |||||
155 | log.info("Clearing cache keys now...") |
|
313 | log.info("Clearing cache keys now...") | |
156 | CacheInvalidation.clear_cache() |
|
314 | CacheInvalidation.clear_cache() | |
157 |
|
315 | |||
158 | #====================================================================== |
|
|||
159 | # UPGRADE STEPS |
|
|||
160 | #====================================================================== |
|
|||
161 |
|
||||
162 | class UpgradeSteps(object): |
|
|||
163 | """ |
|
|||
164 | Those steps follow schema versions so for example schema |
|
|||
165 | for example schema with seq 002 == step_2 and so on. |
|
|||
166 | """ |
|
|||
167 |
|
||||
168 | def __init__(self, klass): |
|
|||
169 | self.klass = klass |
|
|||
170 |
|
||||
171 | def step_1(self): |
|
|||
172 | pass |
|
|||
173 |
|
||||
174 | def step_2(self): |
|
|||
175 | notify('Patching repo paths for newer version of RhodeCode') |
|
|||
176 | self.klass.fix_repo_paths() |
|
|||
177 |
|
||||
178 | notify('Patching default user of RhodeCode') |
|
|||
179 | self.klass.fix_default_user() |
|
|||
180 |
|
||||
181 | log.info('Changing ui settings') |
|
|||
182 | self.klass.create_ui_settings() |
|
|||
183 |
|
||||
184 | def step_3(self): |
|
|||
185 | notify('Adding additional settings into RhodeCode db') |
|
|||
186 | self.klass.fix_settings() |
|
|||
187 | notify('Adding ldap defaults') |
|
|||
188 | self.klass.create_ldap_options(skip_existing=True) |
|
|||
189 |
|
||||
190 | def step_4(self): |
|
|||
191 | notify('create permissions and fix groups') |
|
|||
192 | self.klass.create_permissions() |
|
|||
193 | self.klass.fixup_groups() |
|
|||
194 |
|
||||
195 | def step_5(self): |
|
|||
196 | pass |
|
|||
197 |
|
||||
198 | def step_6(self): |
|
|||
199 |
|
||||
200 | notify('re-checking permissions') |
|
|||
201 | self.klass.create_permissions() |
|
|||
202 |
|
||||
203 | notify('installing new UI options') |
|
|||
204 | sett4 = RhodeCodeSetting('show_public_icon', True) |
|
|||
205 | Session().add(sett4) |
|
|||
206 | sett5 = RhodeCodeSetting('show_private_icon', True) |
|
|||
207 | Session().add(sett5) |
|
|||
208 | sett6 = RhodeCodeSetting('stylify_metatags', False) |
|
|||
209 | Session().add(sett6) |
|
|||
210 |
|
||||
211 | notify('fixing old PULL hook') |
|
|||
212 | _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger') |
|
|||
213 | if _pull: |
|
|||
214 | _pull.ui_key = RhodeCodeUi.HOOK_PULL |
|
|||
215 | Session().add(_pull) |
|
|||
216 |
|
||||
217 | notify('fixing old PUSH hook') |
|
|||
218 | _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger') |
|
|||
219 | if _push: |
|
|||
220 | _push.ui_key = RhodeCodeUi.HOOK_PUSH |
|
|||
221 | Session().add(_push) |
|
|||
222 |
|
||||
223 | notify('installing new pre-push hook') |
|
|||
224 | hooks4 = RhodeCodeUi() |
|
|||
225 | hooks4.ui_section = 'hooks' |
|
|||
226 | hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH |
|
|||
227 | hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push' |
|
|||
228 | Session().add(hooks4) |
|
|||
229 |
|
||||
230 | notify('installing new pre-pull hook') |
|
|||
231 | hooks6 = RhodeCodeUi() |
|
|||
232 | hooks6.ui_section = 'hooks' |
|
|||
233 | hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL |
|
|||
234 | hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull' |
|
|||
235 | Session().add(hooks6) |
|
|||
236 |
|
||||
237 | notify('installing hgsubversion option') |
|
|||
238 | # enable hgsubversion disabled by default |
|
|||
239 | hgsubversion = RhodeCodeUi() |
|
|||
240 | hgsubversion.ui_section = 'extensions' |
|
|||
241 | hgsubversion.ui_key = 'hgsubversion' |
|
|||
242 | hgsubversion.ui_value = '' |
|
|||
243 | hgsubversion.ui_active = False |
|
|||
244 | Session().add(hgsubversion) |
|
|||
245 |
|
||||
246 | notify('installing hg git option') |
|
|||
247 | # enable hggit disabled by default |
|
|||
248 | hggit = RhodeCodeUi() |
|
|||
249 | hggit.ui_section = 'extensions' |
|
|||
250 | hggit.ui_key = 'hggit' |
|
|||
251 | hggit.ui_value = '' |
|
|||
252 | hggit.ui_active = False |
|
|||
253 | Session().add(hggit) |
|
|||
254 |
|
||||
255 | notify('re-check default permissions') |
|
|||
256 | default_user = User.get_by_username(User.DEFAULT_USER) |
|
|||
257 | perm = Permission.get_by_key('hg.fork.repository') |
|
|||
258 | reg_perm = UserToPerm() |
|
|||
259 | reg_perm.user = default_user |
|
|||
260 | reg_perm.permission = perm |
|
|||
261 | Session().add(reg_perm) |
|
|||
262 |
|
||||
263 | def step_7(self): |
|
|||
264 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) |
|
|||
265 | Session().commit() |
|
|||
266 | if perm_fixes: |
|
|||
267 | notify('There was an inconsistent state of permissions ' |
|
|||
268 | 'detected for default user. Permissions are now ' |
|
|||
269 | 'reset to the default value for default user. ' |
|
|||
270 | 'Please validate and check default permissions ' |
|
|||
271 | 'in admin panel') |
|
|||
272 |
|
||||
273 | def step_8(self): |
|
|||
274 | self.klass.create_permissions() |
|
|||
275 | self.klass.populate_default_permissions() |
|
|||
276 | self.klass.create_default_options(skip_existing=True) |
|
|||
277 | Session().commit() |
|
|||
278 |
|
||||
279 | def step_9(self): |
|
|||
280 | perm_fixes = self.klass.reset_permissions(User.DEFAULT_USER) |
|
|||
281 | Session().commit() |
|
|||
282 | if perm_fixes: |
|
|||
283 | notify('There was an inconsistent state of permissions ' |
|
|||
284 | 'detected for default user. Permissions are now ' |
|
|||
285 | 'reset to the default value for default user. ' |
|
|||
286 | 'Please validate and check default permissions ' |
|
|||
287 | 'in admin panel') |
|
|||
288 |
|
||||
289 | def step_10(self): |
|
|||
290 | pass |
|
|||
291 |
|
||||
292 | def step_11(self): |
|
|||
293 | self.klass.update_repo_info() |
|
|||
294 |
|
||||
295 | def step_12(self): |
|
|||
296 | self.klass.create_permissions() |
|
|||
297 | Session().commit() |
|
|||
298 |
|
||||
299 | self.klass.populate_default_permissions() |
|
|||
300 | Session().commit() |
|
|||
301 |
|
||||
302 | #fix all usergroups |
|
|||
303 | ug_model = UserGroupModel() |
|
|||
304 | for ug in UserGroup.get_all(): |
|
|||
305 | perm_obj = ug_model._create_default_perms(ug) |
|
|||
306 | Session().add(perm_obj) |
|
|||
307 | Session().commit() |
|
|||
308 |
|
||||
309 | adm = User.get_first_admin() |
|
|||
310 | # fix owners of UserGroup |
|
|||
311 | for ug in Session().query(UserGroup).all(): |
|
|||
312 | ug.user_id = adm.user_id |
|
|||
313 | Session().add(ug) |
|
|||
314 | Session().commit() |
|
|||
315 |
|
||||
316 | # fix owners of RepoGroup |
|
|||
317 | for ug in Session().query(RepoGroup).all(): |
|
|||
318 | ug.user_id = adm.user_id |
|
|||
319 | Session().add(ug) |
|
|||
320 | Session().commit() |
|
|||
321 |
|
||||
322 | def step_13(self): |
|
|||
323 | pass |
|
|||
324 |
|
||||
325 | upgrade_steps = range(curr_version + 1, __dbversion__ + 1) |
|
316 | upgrade_steps = range(curr_version + 1, __dbversion__ + 1) | |
326 | notify('attempting to do database upgrade from ' |
|
317 | notify('attempting to do database upgrade from ' | |
327 | 'version %s to version %s' % (curr_version, __dbversion__)) |
|
318 | 'version %s to version %s' % (curr_version, __dbversion__)) | |
@@ -330,12 +321,16 b' class DbManage(object):' | |||||
330 | _step = None |
|
321 | _step = None | |
331 | for step in upgrade_steps: |
|
322 | for step in upgrade_steps: | |
332 | notify('performing upgrade step %s' % step) |
|
323 | notify('performing upgrade step %s' % step) | |
|
324 | time.sleep(2) | |||
333 |
|
325 | |||
334 | api.upgrade(db_uri, repository_path, step) |
|
326 | api.upgrade(db_uri, repository_path, step) | |
335 |
notify(' |
|
327 | notify('schema upgrade for step %s completed' % (step,)) | |
336 |
|
328 | |||
337 |
|
|
329 | fixture = 'step_%s' % step | |
|
330 | notify('performing fixture step %s' % fixture) | |||
|
331 | getattr(UpgradeSteps(self), fixture)() | |||
338 | self.sa.commit() |
|
332 | self.sa.commit() | |
|
333 | notify('fixture %s completed' % (fixture,)) | |||
339 | _step = step |
|
334 | _step = step | |
340 |
|
335 | |||
341 | notify('upgrade to version %s successful' % _step) |
|
336 | notify('upgrade to version %s successful' % _step) |
General Comments 0
You need to be logged in to leave comments.
Login now