##// END OF EJS Templates
migrations: fix old hook values...
marcink -
r2779:d0d31588 beta
parent child Browse files
Show More
@@ -40,7 +40,6 b' from rhodecode.model.db import User, Per'
40 UserRepoGroupToPerm
40 UserRepoGroupToPerm
41
41
42 from sqlalchemy.engine import create_engine
42 from sqlalchemy.engine import create_engine
43 from sqlalchemy.schema import MetaData
44 from rhodecode.model.repos_group import ReposGroupModel
43 from rhodecode.model.repos_group import ReposGroupModel
45 #from rhodecode.model import meta
44 #from rhodecode.model import meta
46 from rhodecode.model.meta import Session, Base
45 from rhodecode.model.meta import Session, Base
@@ -49,6 +48,14 b' from rhodecode.model.meta import Session'
49 log = logging.getLogger(__name__)
48 log = logging.getLogger(__name__)
50
49
51
50
51 def notify(msg):
52 """
53 Notification for migrations messages
54 """
55 ml = len(msg) + (4 * 2)
56 print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper()
57
58
52 class DbManage(object):
59 class DbManage(object):
53 def __init__(self, log_sql, dbconf, root, tests=False):
60 def __init__(self, log_sql, dbconf, root, tests=False):
54 self.dbname = dbconf.split('/')[-1]
61 self.dbname = dbconf.split('/')[-1]
@@ -130,7 +137,7 b' class DbManage(object):'
130 ' as version %s' % curr_version)
137 ' as version %s' % curr_version)
131 api.version_control(db_uri, repository_path, curr_version)
138 api.version_control(db_uri, repository_path, curr_version)
132
139
133 print (msg)
140 notify(msg)
134
141
135 if curr_version == __dbversion__:
142 if curr_version == __dbversion__:
136 sys.exit('This database is already at the newest version')
143 sys.exit('This database is already at the newest version')
@@ -138,6 +145,7 b' class DbManage(object):'
138 #======================================================================
145 #======================================================================
139 # UPGRADE STEPS
146 # UPGRADE STEPS
140 #======================================================================
147 #======================================================================
148
141 class UpgradeSteps(object):
149 class UpgradeSteps(object):
142 """
150 """
143 Those steps follow schema versions so for example schema
151 Those steps follow schema versions so for example schema
@@ -149,32 +157,32 b' class DbManage(object):'
149
157
150 def step_0(self):
158 def step_0(self):
151 # step 0 is the schema upgrade, and than follow proper upgrades
159 # step 0 is the schema upgrade, and than follow proper upgrades
152 print ('attempting to do database upgrade to version %s' \
160 notify('attempting to do database upgrade to version %s' \
153 % __dbversion__)
161 % __dbversion__)
154 api.upgrade(db_uri, repository_path, __dbversion__)
162 api.upgrade(db_uri, repository_path, __dbversion__)
155 print ('Schema upgrade completed')
163 notify('Schema upgrade completed')
156
164
157 def step_1(self):
165 def step_1(self):
158 pass
166 pass
159
167
160 def step_2(self):
168 def step_2(self):
161 print ('Patching repo paths for newer version of RhodeCode')
169 notify('Patching repo paths for newer version of RhodeCode')
162 self.klass.fix_repo_paths()
170 self.klass.fix_repo_paths()
163
171
164 print ('Patching default user of RhodeCode')
172 notify('Patching default user of RhodeCode')
165 self.klass.fix_default_user()
173 self.klass.fix_default_user()
166
174
167 log.info('Changing ui settings')
175 log.info('Changing ui settings')
168 self.klass.create_ui_settings()
176 self.klass.create_ui_settings()
169
177
170 def step_3(self):
178 def step_3(self):
171 print ('Adding additional settings into RhodeCode db')
179 notify('Adding additional settings into RhodeCode db')
172 self.klass.fix_settings()
180 self.klass.fix_settings()
173 print ('Adding ldap defaults')
181 notify('Adding ldap defaults')
174 self.klass.create_ldap_options(skip_existing=True)
182 self.klass.create_ldap_options(skip_existing=True)
175
183
176 def step_4(self):
184 def step_4(self):
177 print ('create permissions and fix groups')
185 notify('create permissions and fix groups')
178 self.klass.create_permissions()
186 self.klass.create_permissions()
179 self.klass.fixup_groups()
187 self.klass.fixup_groups()
180
188
@@ -182,23 +190,37 b' class DbManage(object):'
182 pass
190 pass
183
191
184 def step_6(self):
192 def step_6(self):
185 print ('re-checking permissions')
193
194 notify('re-checking permissions')
186 self.klass.create_permissions()
195 self.klass.create_permissions()
187
196
188 print ('installing new hooks')
197 notify('fixing old PULL hook')
198 _pull = RhodeCodeUi.get_by_key('preoutgoing.pull_logger')
199 if _pull:
200 _pull.ui_key = RhodeCodeUi.HOOK_PULL
201 Session().add(_pull)
202
203 notify('fixing old PUSH hook')
204 _push = RhodeCodeUi.get_by_key('pretxnchangegroup.push_logger')
205 if _push:
206 _push.ui_key = RhodeCodeUi.HOOK_PUSH
207 Session().add(_push)
208
209 notify('installing new pre-push hook')
189 hooks4 = RhodeCodeUi()
210 hooks4 = RhodeCodeUi()
190 hooks4.ui_section = 'hooks'
211 hooks4.ui_section = 'hooks'
191 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
212 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
192 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
213 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
193 Session().add(hooks4)
214 Session().add(hooks4)
194
215
216 notify('installing new pre-pull hook')
195 hooks6 = RhodeCodeUi()
217 hooks6 = RhodeCodeUi()
196 hooks6.ui_section = 'hooks'
218 hooks6.ui_section = 'hooks'
197 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
219 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
198 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
220 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
199 Session().add(hooks6)
221 Session().add(hooks6)
200
222
201 print ('installing hgsubversion option')
223 notify('installing hgsubversion option')
202 # enable hgsubversion disabled by default
224 # enable hgsubversion disabled by default
203 hgsubversion = RhodeCodeUi()
225 hgsubversion = RhodeCodeUi()
204 hgsubversion.ui_section = 'extensions'
226 hgsubversion.ui_section = 'extensions'
@@ -207,7 +229,7 b' class DbManage(object):'
207 hgsubversion.ui_active = False
229 hgsubversion.ui_active = False
208 Session().add(hgsubversion)
230 Session().add(hgsubversion)
209
231
210 print ('installing hg git option')
232 notify('installing hg git option')
211 # enable hggit disabled by default
233 # enable hggit disabled by default
212 hggit = RhodeCodeUi()
234 hggit = RhodeCodeUi()
213 hggit.ui_section = 'extensions'
235 hggit.ui_section = 'extensions'
@@ -216,16 +238,20 b' class DbManage(object):'
216 hggit.ui_active = False
238 hggit.ui_active = False
217 Session().add(hggit)
239 Session().add(hggit)
218
240
219 print ('re-check default permissions')
241 notify('re-check default permissions')
220 self.klass.populate_default_permissions()
242 self.klass.populate_default_permissions()
221
243
222 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
244 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
223
245
224 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
246 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
247 _step = None
225 for step in upgrade_steps:
248 for step in upgrade_steps:
226 print ('performing upgrade step %s' % step)
249 notify('performing upgrade step %s' % step)
227 getattr(UpgradeSteps(self), 'step_%s' % step)()
250 getattr(UpgradeSteps(self), 'step_%s' % step)()
228 self.sa.commit()
251 self.sa.commit()
252 _step = step
253
254 notify('upgrade to version %s successful' % _step)
229
255
230 def fix_repo_paths(self):
256 def fix_repo_paths(self):
231 """
257 """
General Comments 0
You need to be logged in to leave comments. Login now