##// END OF EJS Templates
More fixes to upgrade procedure,...
marcink -
r2767:7562f46b beta
parent child Browse files
Show More
@@ -1,582 +1,583 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.lib.db_manage
3 rhodecode.lib.db_manage
4 ~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Database creation, and setup module for RhodeCode. Used for creation
6 Database creation, and setup module for RhodeCode. Used for creation
7 of database as well as for migration operations
7 of database as well as for migration operations
8
8
9 :created_on: Apr 10, 2010
9 :created_on: Apr 10, 2010
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26
26
27 import os
27 import os
28 import sys
28 import sys
29 import uuid
29 import uuid
30 import logging
30 import logging
31 from os.path import dirname as dn, join as jn
31 from os.path import dirname as dn, join as jn
32
32
33 from rhodecode import __dbversion__
33 from rhodecode import __dbversion__
34
34
35 from rhodecode.model.user import UserModel
35 from rhodecode.model.user import UserModel
36 from rhodecode.lib.utils import ask_ok
36 from rhodecode.lib.utils import ask_ok
37 from rhodecode.model import init_model
37 from rhodecode.model import init_model
38 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
38 from rhodecode.model.db import User, Permission, RhodeCodeUi, \
39 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
39 RhodeCodeSetting, UserToPerm, DbMigrateVersion, RepoGroup, \
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
43 from sqlalchemy.schema import MetaData
44 from rhodecode.model.repos_group import ReposGroupModel
44 from rhodecode.model.repos_group import ReposGroupModel
45 #from rhodecode.model import meta
45 #from rhodecode.model import meta
46 from rhodecode.model.meta import Session, Base
46 from rhodecode.model.meta import Session, Base
47
47
48
48
49 log = logging.getLogger(__name__)
49 log = logging.getLogger(__name__)
50
50
51
51
52 class DbManage(object):
52 class DbManage(object):
53 def __init__(self, log_sql, dbconf, root, tests=False):
53 def __init__(self, log_sql, dbconf, root, tests=False):
54 self.dbname = dbconf.split('/')[-1]
54 self.dbname = dbconf.split('/')[-1]
55 self.tests = tests
55 self.tests = tests
56 self.root = root
56 self.root = root
57 self.dburi = dbconf
57 self.dburi = dbconf
58 self.log_sql = log_sql
58 self.log_sql = log_sql
59 self.db_exists = False
59 self.db_exists = False
60 self.init_db()
60 self.init_db()
61
61
62 def init_db(self):
62 def init_db(self):
63 engine = create_engine(self.dburi, echo=self.log_sql)
63 engine = create_engine(self.dburi, echo=self.log_sql)
64 init_model(engine)
64 init_model(engine)
65 self.sa = Session()
65 self.sa = Session()
66
66
67 def create_tables(self, override=False, defaults={}):
67 def create_tables(self, override=False, defaults={}):
68 """
68 """
69 Create a auth database
69 Create a auth database
70 """
70 """
71 quiet = defaults.get('quiet')
71 quiet = defaults.get('quiet')
72 log.info("Any existing database is going to be destroyed")
72 log.info("Any existing database is going to be destroyed")
73 if self.tests or quiet:
73 if self.tests or quiet:
74 destroy = True
74 destroy = True
75 else:
75 else:
76 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
76 destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
77 if not destroy:
77 if not destroy:
78 sys.exit()
78 sys.exit()
79 if destroy:
79 if destroy:
80 Base.metadata.drop_all()
80 Base.metadata.drop_all()
81
81
82 checkfirst = not override
82 checkfirst = not override
83 Base.metadata.create_all(checkfirst=checkfirst)
83 Base.metadata.create_all(checkfirst=checkfirst)
84 log.info('Created tables for %s' % self.dbname)
84 log.info('Created tables for %s' % self.dbname)
85
85
86 def set_db_version(self):
86 def set_db_version(self):
87 ver = DbMigrateVersion()
87 ver = DbMigrateVersion()
88 ver.version = __dbversion__
88 ver.version = __dbversion__
89 ver.repository_id = 'rhodecode_db_migrations'
89 ver.repository_id = 'rhodecode_db_migrations'
90 ver.repository_path = 'versions'
90 ver.repository_path = 'versions'
91 self.sa.add(ver)
91 self.sa.add(ver)
92 log.info('db version set to: %s' % __dbversion__)
92 log.info('db version set to: %s' % __dbversion__)
93
93
94 def upgrade(self):
94 def upgrade(self):
95 """
95 """
96 Upgrades given database schema to given revision following
96 Upgrades given database schema to given revision following
97 all needed steps, to perform the upgrade
97 all needed steps, to perform the upgrade
98
98
99 """
99 """
100
100
101 from rhodecode.lib.dbmigrate.migrate.versioning import api
101 from rhodecode.lib.dbmigrate.migrate.versioning import api
102 from rhodecode.lib.dbmigrate.migrate.exceptions import \
102 from rhodecode.lib.dbmigrate.migrate.exceptions import \
103 DatabaseNotControlledError
103 DatabaseNotControlledError
104
104
105 if 'sqlite' in self.dburi:
105 if 'sqlite' in self.dburi:
106 print (
106 print (
107 '********************** WARNING **********************\n'
107 '********************** WARNING **********************\n'
108 'Make sure your version of sqlite is at least 3.7.X. \n'
108 'Make sure your version of sqlite is at least 3.7.X. \n'
109 'Earlier versions are known to fail on some migrations\n'
109 'Earlier versions are known to fail on some migrations\n'
110 '*****************************************************\n'
110 '*****************************************************\n'
111 )
111 )
112 upgrade = ask_ok('You are about to perform database upgrade, make '
112 upgrade = ask_ok('You are about to perform database upgrade, make '
113 'sure You backed up your database before. '
113 'sure You backed up your database before. '
114 'Continue ? [y/n]')
114 'Continue ? [y/n]')
115 if not upgrade:
115 if not upgrade:
116 sys.exit('Nothing done')
116 sys.exit('Nothing done')
117
117
118 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
118 repository_path = jn(dn(dn(dn(os.path.realpath(__file__)))),
119 'rhodecode/lib/dbmigrate')
119 'rhodecode/lib/dbmigrate')
120 db_uri = self.dburi
120 db_uri = self.dburi
121
121
122 try:
122 try:
123 curr_version = api.db_version(db_uri, repository_path)
123 curr_version = api.db_version(db_uri, repository_path)
124 msg = ('Found current database under version'
124 msg = ('Found current database under version'
125 ' control with version %s' % curr_version)
125 ' control with version %s' % curr_version)
126
126
127 except (RuntimeError, DatabaseNotControlledError):
127 except (RuntimeError, DatabaseNotControlledError):
128 curr_version = 1
128 curr_version = 1
129 msg = ('Current database is not under version control. Setting'
129 msg = ('Current database is not under version control. Setting'
130 ' as version %s' % curr_version)
130 ' as version %s' % curr_version)
131 api.version_control(db_uri, repository_path, curr_version)
131 api.version_control(db_uri, repository_path, curr_version)
132
132
133 print (msg)
133 print (msg)
134
134
135 if curr_version == __dbversion__:
135 if curr_version == __dbversion__:
136 sys.exit('This database is already at the newest version')
136 sys.exit('This database is already at the newest version')
137
137
138 #======================================================================
138 #======================================================================
139 # UPGRADE STEPS
139 # UPGRADE STEPS
140 #======================================================================
140 #======================================================================
141 class UpgradeSteps(object):
141 class UpgradeSteps(object):
142 """
142 """
143 Those steps follow schema versions so for example schema
143 Those steps follow schema versions so for example schema
144 for example schema with seq 002 == step_2 and so on.
144 for example schema with seq 002 == step_2 and so on.
145 """
145 """
146
146
147 def __init__(self, klass):
147 def __init__(self, klass):
148 self.klass = klass
148 self.klass = klass
149
149
150 def step_0(self):
150 def step_0(self):
151 # step 0 is the schema upgrade, and than follow proper upgrades
151 # step 0 is the schema upgrade, and than follow proper upgrades
152 print ('attempting to do database upgrade to version %s' \
152 print ('attempting to do database upgrade to version %s' \
153 % __dbversion__)
153 % __dbversion__)
154 api.upgrade(db_uri, repository_path, __dbversion__)
154 api.upgrade(db_uri, repository_path, __dbversion__)
155 print ('Schema upgrade completed')
155 print ('Schema upgrade completed')
156
156
157 def step_1(self):
157 def step_1(self):
158 pass
158 pass
159
159
160 def step_2(self):
160 def step_2(self):
161 print ('Patching repo paths for newer version of RhodeCode')
161 print ('Patching repo paths for newer version of RhodeCode')
162 self.klass.fix_repo_paths()
162 self.klass.fix_repo_paths()
163
163
164 print ('Patching default user of RhodeCode')
164 print ('Patching default user of RhodeCode')
165 self.klass.fix_default_user()
165 self.klass.fix_default_user()
166
166
167 log.info('Changing ui settings')
167 log.info('Changing ui settings')
168 self.klass.create_ui_settings()
168 self.klass.create_ui_settings()
169
169
170 def step_3(self):
170 def step_3(self):
171 print ('Adding additional settings into RhodeCode db')
171 print ('Adding additional settings into RhodeCode db')
172 self.klass.fix_settings()
172 self.klass.fix_settings()
173 print ('Adding ldap defaults')
173 print ('Adding ldap defaults')
174 self.klass.create_ldap_options(skip_existing=True)
174 self.klass.create_ldap_options(skip_existing=True)
175
175
176 def step_4(self):
176 def step_4(self):
177 print ('create permissions and fix groups')
177 print ('create permissions and fix groups')
178 self.klass.create_permissions()
178 self.klass.create_permissions()
179 self.klass.fixup_groups()
179 self.klass.fixup_groups()
180
180
181 def step_5(self):
181 def step_5(self):
182 pass
182 pass
183
183
184 def step_6(self):
184 def step_6(self):
185 print ('re-checking permissions')
185 print ('re-checking permissions')
186 self.klass.create_permissions()
186 self.klass.create_permissions()
187
187
188 print ('installing new hooks')
188 print ('installing new hooks')
189 hooks4 = RhodeCodeUi()
189 hooks4 = RhodeCodeUi()
190 hooks4.ui_section = 'hooks'
190 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
191 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
191 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
192 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
192 Session().add(hooks4)
193 Session().add(hooks4)
193
194
194 hooks6 = RhodeCodeUi()
195 hooks6 = RhodeCodeUi()
195 hooks6.ui_section = 'hooks'
196 hooks6.ui_section = 'hooks'
196 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
197 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
197 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
198 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
198 Session().add(hooks6)
199 Session().add(hooks6)
199
200
200 print ('installing hgsubversion option')
201 print ('installing hgsubversion option')
201 # enable hgsubversion disabled by default
202 # enable hgsubversion disabled by default
202 hgsubversion = RhodeCodeUi()
203 hgsubversion = RhodeCodeUi()
203 hgsubversion.ui_section = 'extensions'
204 hgsubversion.ui_section = 'extensions'
204 hgsubversion.ui_key = 'hgsubversion'
205 hgsubversion.ui_key = 'hgsubversion'
205 hgsubversion.ui_value = ''
206 hgsubversion.ui_value = ''
206 hgsubversion.ui_active = False
207 hgsubversion.ui_active = False
207 Session().add(hgsubversion)
208 Session().add(hgsubversion)
208
209
209 print ('installing hg git option')
210 print ('installing hg git option')
210 # enable hggit disabled by default
211 # enable hggit disabled by default
211 hggit = RhodeCodeUi()
212 hggit = RhodeCodeUi()
212 hggit.ui_section = 'extensions'
213 hggit.ui_section = 'extensions'
213 hggit.ui_key = 'hggit'
214 hggit.ui_key = 'hggit'
214 hggit.ui_value = ''
215 hggit.ui_value = ''
215 hggit.ui_active = False
216 hggit.ui_active = False
216 Session().add(hggit)
217 Session().add(hggit)
217
218
218 print ('re-check default permissions')
219 print ('re-check default permissions')
219 self.klass.populate_default_permissions()
220 self.klass.populate_default_permissions()
220
221
221 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
222 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
222
223
223 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
224 # CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
224 for step in upgrade_steps:
225 for step in upgrade_steps:
225 print ('performing upgrade step %s' % step)
226 print ('performing upgrade step %s' % step)
226 getattr(UpgradeSteps(self), 'step_%s' % step)()
227 getattr(UpgradeSteps(self), 'step_%s' % step)()
227 self.sa.commit()
228 self.sa.commit()
228
229
229 def fix_repo_paths(self):
230 def fix_repo_paths(self):
230 """
231 """
231 Fixes a old rhodecode version path into new one without a '*'
232 Fixes a old rhodecode version path into new one without a '*'
232 """
233 """
233
234
234 paths = self.sa.query(RhodeCodeUi)\
235 paths = self.sa.query(RhodeCodeUi)\
235 .filter(RhodeCodeUi.ui_key == '/')\
236 .filter(RhodeCodeUi.ui_key == '/')\
236 .scalar()
237 .scalar()
237
238
238 paths.ui_value = paths.ui_value.replace('*', '')
239 paths.ui_value = paths.ui_value.replace('*', '')
239
240
240 try:
241 try:
241 self.sa.add(paths)
242 self.sa.add(paths)
242 self.sa.commit()
243 self.sa.commit()
243 except:
244 except:
244 self.sa.rollback()
245 self.sa.rollback()
245 raise
246 raise
246
247
247 def fix_default_user(self):
248 def fix_default_user(self):
248 """
249 """
249 Fixes a old default user with some 'nicer' default values,
250 Fixes a old default user with some 'nicer' default values,
250 used mostly for anonymous access
251 used mostly for anonymous access
251 """
252 """
252 def_user = self.sa.query(User)\
253 def_user = self.sa.query(User)\
253 .filter(User.username == 'default')\
254 .filter(User.username == 'default')\
254 .one()
255 .one()
255
256
256 def_user.name = 'Anonymous'
257 def_user.name = 'Anonymous'
257 def_user.lastname = 'User'
258 def_user.lastname = 'User'
258 def_user.email = 'anonymous@rhodecode.org'
259 def_user.email = 'anonymous@rhodecode.org'
259
260
260 try:
261 try:
261 self.sa.add(def_user)
262 self.sa.add(def_user)
262 self.sa.commit()
263 self.sa.commit()
263 except:
264 except:
264 self.sa.rollback()
265 self.sa.rollback()
265 raise
266 raise
266
267
267 def fix_settings(self):
268 def fix_settings(self):
268 """
269 """
269 Fixes rhodecode settings adds ga_code key for google analytics
270 Fixes rhodecode settings adds ga_code key for google analytics
270 """
271 """
271
272
272 hgsettings3 = RhodeCodeSetting('ga_code', '')
273 hgsettings3 = RhodeCodeSetting('ga_code', '')
273
274
274 try:
275 try:
275 self.sa.add(hgsettings3)
276 self.sa.add(hgsettings3)
276 self.sa.commit()
277 self.sa.commit()
277 except:
278 except:
278 self.sa.rollback()
279 self.sa.rollback()
279 raise
280 raise
280
281
281 def admin_prompt(self, second=False, defaults={}):
282 def admin_prompt(self, second=False, defaults={}):
282 if not self.tests:
283 if not self.tests:
283 import getpass
284 import getpass
284
285
285 # defaults
286 # defaults
286 username = defaults.get('username')
287 username = defaults.get('username')
287 password = defaults.get('password')
288 password = defaults.get('password')
288 email = defaults.get('email')
289 email = defaults.get('email')
289
290
290 def get_password():
291 def get_password():
291 password = getpass.getpass('Specify admin password '
292 password = getpass.getpass('Specify admin password '
292 '(min 6 chars):')
293 '(min 6 chars):')
293 confirm = getpass.getpass('Confirm password:')
294 confirm = getpass.getpass('Confirm password:')
294
295
295 if password != confirm:
296 if password != confirm:
296 log.error('passwords mismatch')
297 log.error('passwords mismatch')
297 return False
298 return False
298 if len(password) < 6:
299 if len(password) < 6:
299 log.error('password is to short use at least 6 characters')
300 log.error('password is to short use at least 6 characters')
300 return False
301 return False
301
302
302 return password
303 return password
303 if username is None:
304 if username is None:
304 username = raw_input('Specify admin username:')
305 username = raw_input('Specify admin username:')
305 if password is None:
306 if password is None:
306 password = get_password()
307 password = get_password()
307 if not password:
308 if not password:
308 #second try
309 #second try
309 password = get_password()
310 password = get_password()
310 if not password:
311 if not password:
311 sys.exit()
312 sys.exit()
312 if email is None:
313 if email is None:
313 email = raw_input('Specify admin email:')
314 email = raw_input('Specify admin email:')
314 self.create_user(username, password, email, True)
315 self.create_user(username, password, email, True)
315 else:
316 else:
316 log.info('creating admin and regular test users')
317 log.info('creating admin and regular test users')
317 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
318 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \
318 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
319 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \
319 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
320 TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \
320 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
321 TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \
321 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
322 TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL
322
323
323 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
324 self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS,
324 TEST_USER_ADMIN_EMAIL, True)
325 TEST_USER_ADMIN_EMAIL, True)
325
326
326 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
327 self.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
327 TEST_USER_REGULAR_EMAIL, False)
328 TEST_USER_REGULAR_EMAIL, False)
328
329
329 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
330 self.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS,
330 TEST_USER_REGULAR2_EMAIL, False)
331 TEST_USER_REGULAR2_EMAIL, False)
331
332
332 def create_ui_settings(self):
333 def create_ui_settings(self):
333 """
334 """
334 Creates ui settings, fills out hooks
335 Creates ui settings, fills out hooks
335 and disables dotencode
336 and disables dotencode
336 """
337 """
337
338
338 #HOOKS
339 #HOOKS
339 hooks1_key = RhodeCodeUi.HOOK_UPDATE
340 hooks1_key = RhodeCodeUi.HOOK_UPDATE
340 hooks1_ = self.sa.query(RhodeCodeUi)\
341 hooks1_ = self.sa.query(RhodeCodeUi)\
341 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
342 .filter(RhodeCodeUi.ui_key == hooks1_key).scalar()
342
343
343 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
344 hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_
344 hooks1.ui_section = 'hooks'
345 hooks1.ui_section = 'hooks'
345 hooks1.ui_key = hooks1_key
346 hooks1.ui_key = hooks1_key
346 hooks1.ui_value = 'hg update >&2'
347 hooks1.ui_value = 'hg update >&2'
347 hooks1.ui_active = False
348 hooks1.ui_active = False
348 self.sa.add(hooks1)
349 self.sa.add(hooks1)
349
350
350 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
351 hooks2_key = RhodeCodeUi.HOOK_REPO_SIZE
351 hooks2_ = self.sa.query(RhodeCodeUi)\
352 hooks2_ = self.sa.query(RhodeCodeUi)\
352 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
353 .filter(RhodeCodeUi.ui_key == hooks2_key).scalar()
353 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
354 hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_
354 hooks2.ui_section = 'hooks'
355 hooks2.ui_section = 'hooks'
355 hooks2.ui_key = hooks2_key
356 hooks2.ui_key = hooks2_key
356 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
357 hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size'
357 self.sa.add(hooks2)
358 self.sa.add(hooks2)
358
359
359 hooks3 = RhodeCodeUi()
360 hooks3 = RhodeCodeUi()
360 hooks3.ui_section = 'hooks'
361 hooks3.ui_section = 'hooks'
361 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
362 hooks3.ui_key = RhodeCodeUi.HOOK_PUSH
362 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
363 hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action'
363 self.sa.add(hooks3)
364 self.sa.add(hooks3)
364
365
365 hooks4 = RhodeCodeUi()
366 hooks4 = RhodeCodeUi()
366 hooks4.ui_section = 'hooks'
367 hooks4.ui_section = 'hooks'
367 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
368 hooks4.ui_key = RhodeCodeUi.HOOK_PRE_PUSH
368 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
369 hooks4.ui_value = 'python:rhodecode.lib.hooks.pre_push'
369 self.sa.add(hooks4)
370 self.sa.add(hooks4)
370
371
371 hooks5 = RhodeCodeUi()
372 hooks5 = RhodeCodeUi()
372 hooks5.ui_section = 'hooks'
373 hooks5.ui_section = 'hooks'
373 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
374 hooks5.ui_key = RhodeCodeUi.HOOK_PULL
374 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
375 hooks5.ui_value = 'python:rhodecode.lib.hooks.log_pull_action'
375 self.sa.add(hooks5)
376 self.sa.add(hooks5)
376
377
377 hooks6 = RhodeCodeUi()
378 hooks6 = RhodeCodeUi()
378 hooks6.ui_section = 'hooks'
379 hooks6.ui_section = 'hooks'
379 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
380 hooks6.ui_key = RhodeCodeUi.HOOK_PRE_PULL
380 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
381 hooks6.ui_value = 'python:rhodecode.lib.hooks.pre_pull'
381 self.sa.add(hooks6)
382 self.sa.add(hooks6)
382
383
383 # enable largefiles
384 # enable largefiles
384 largefiles = RhodeCodeUi()
385 largefiles = RhodeCodeUi()
385 largefiles.ui_section = 'extensions'
386 largefiles.ui_section = 'extensions'
386 largefiles.ui_key = 'largefiles'
387 largefiles.ui_key = 'largefiles'
387 largefiles.ui_value = ''
388 largefiles.ui_value = ''
388 self.sa.add(largefiles)
389 self.sa.add(largefiles)
389
390
390 # enable hgsubversion disabled by default
391 # enable hgsubversion disabled by default
391 hgsubversion = RhodeCodeUi()
392 hgsubversion = RhodeCodeUi()
392 hgsubversion.ui_section = 'extensions'
393 hgsubversion.ui_section = 'extensions'
393 hgsubversion.ui_key = 'hgsubversion'
394 hgsubversion.ui_key = 'hgsubversion'
394 hgsubversion.ui_value = ''
395 hgsubversion.ui_value = ''
395 hgsubversion.ui_active = False
396 hgsubversion.ui_active = False
396 self.sa.add(hgsubversion)
397 self.sa.add(hgsubversion)
397
398
398 # enable hggit disabled by default
399 # enable hggit disabled by default
399 hggit = RhodeCodeUi()
400 hggit = RhodeCodeUi()
400 hggit.ui_section = 'extensions'
401 hggit.ui_section = 'extensions'
401 hggit.ui_key = 'hggit'
402 hggit.ui_key = 'hggit'
402 hggit.ui_value = ''
403 hggit.ui_value = ''
403 hggit.ui_active = False
404 hggit.ui_active = False
404 self.sa.add(hggit)
405 self.sa.add(hggit)
405
406
406 def create_ldap_options(self, skip_existing=False):
407 def create_ldap_options(self, skip_existing=False):
407 """Creates ldap settings"""
408 """Creates ldap settings"""
408
409
409 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
410 for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
410 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
411 ('ldap_port', '389'), ('ldap_tls_kind', 'PLAIN'),
411 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
412 ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
412 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
413 ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
413 ('ldap_filter', ''), ('ldap_search_scope', ''),
414 ('ldap_filter', ''), ('ldap_search_scope', ''),
414 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
415 ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
415 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
416 ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
416
417
417 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
418 if skip_existing and RhodeCodeSetting.get_by_name(k) != None:
418 log.debug('Skipping option %s' % k)
419 log.debug('Skipping option %s' % k)
419 continue
420 continue
420 setting = RhodeCodeSetting(k, v)
421 setting = RhodeCodeSetting(k, v)
421 self.sa.add(setting)
422 self.sa.add(setting)
422
423
423 def fixup_groups(self):
424 def fixup_groups(self):
424 def_usr = User.get_by_username('default')
425 def_usr = User.get_by_username('default')
425 for g in RepoGroup.query().all():
426 for g in RepoGroup.query().all():
426 g.group_name = g.get_new_name(g.name)
427 g.group_name = g.get_new_name(g.name)
427 self.sa.add(g)
428 self.sa.add(g)
428 # get default perm
429 # get default perm
429 default = UserRepoGroupToPerm.query()\
430 default = UserRepoGroupToPerm.query()\
430 .filter(UserRepoGroupToPerm.group == g)\
431 .filter(UserRepoGroupToPerm.group == g)\
431 .filter(UserRepoGroupToPerm.user == def_usr)\
432 .filter(UserRepoGroupToPerm.user == def_usr)\
432 .scalar()
433 .scalar()
433
434
434 if default is None:
435 if default is None:
435 log.debug('missing default permission for group %s adding' % g)
436 log.debug('missing default permission for group %s adding' % g)
436 ReposGroupModel()._create_default_perms(g)
437 ReposGroupModel()._create_default_perms(g)
437
438
438 def config_prompt(self, test_repo_path='', retries=3, defaults={}):
439 def config_prompt(self, test_repo_path='', retries=3, defaults={}):
439 _path = defaults.get('repos_location')
440 _path = defaults.get('repos_location')
440 if retries == 3:
441 if retries == 3:
441 log.info('Setting up repositories config')
442 log.info('Setting up repositories config')
442
443
443 if _path is not None:
444 if _path is not None:
444 path = _path
445 path = _path
445 elif not self.tests and not test_repo_path:
446 elif not self.tests and not test_repo_path:
446 path = raw_input(
447 path = raw_input(
447 'Enter a valid absolute path to store repositories. '
448 'Enter a valid absolute path to store repositories. '
448 'All repositories in that path will be added automatically:'
449 'All repositories in that path will be added automatically:'
449 )
450 )
450 else:
451 else:
451 path = test_repo_path
452 path = test_repo_path
452 path_ok = True
453 path_ok = True
453
454
454 # check proper dir
455 # check proper dir
455 if not os.path.isdir(path):
456 if not os.path.isdir(path):
456 path_ok = False
457 path_ok = False
457 log.error('Given path %s is not a valid directory' % path)
458 log.error('Given path %s is not a valid directory' % path)
458
459
459 elif not os.path.isabs(path):
460 elif not os.path.isabs(path):
460 path_ok = False
461 path_ok = False
461 log.error('Given path %s is not an absolute path' % path)
462 log.error('Given path %s is not an absolute path' % path)
462
463
463 # check write access
464 # check write access
464 elif not os.access(path, os.W_OK) and path_ok:
465 elif not os.access(path, os.W_OK) and path_ok:
465 path_ok = False
466 path_ok = False
466 log.error('No write permission to given path %s' % path)
467 log.error('No write permission to given path %s' % path)
467
468
468 if retries == 0:
469 if retries == 0:
469 sys.exit('max retries reached')
470 sys.exit('max retries reached')
470 if path_ok is False:
471 if path_ok is False:
471 retries -= 1
472 retries -= 1
472 return self.config_prompt(test_repo_path, retries)
473 return self.config_prompt(test_repo_path, retries)
473
474
474 return path
475 return path
475
476
476 def create_settings(self, path):
477 def create_settings(self, path):
477
478
478 self.create_ui_settings()
479 self.create_ui_settings()
479
480
480 #HG UI OPTIONS
481 #HG UI OPTIONS
481 web1 = RhodeCodeUi()
482 web1 = RhodeCodeUi()
482 web1.ui_section = 'web'
483 web1.ui_section = 'web'
483 web1.ui_key = 'push_ssl'
484 web1.ui_key = 'push_ssl'
484 web1.ui_value = 'false'
485 web1.ui_value = 'false'
485
486
486 web2 = RhodeCodeUi()
487 web2 = RhodeCodeUi()
487 web2.ui_section = 'web'
488 web2.ui_section = 'web'
488 web2.ui_key = 'allow_archive'
489 web2.ui_key = 'allow_archive'
489 web2.ui_value = 'gz zip bz2'
490 web2.ui_value = 'gz zip bz2'
490
491
491 web3 = RhodeCodeUi()
492 web3 = RhodeCodeUi()
492 web3.ui_section = 'web'
493 web3.ui_section = 'web'
493 web3.ui_key = 'allow_push'
494 web3.ui_key = 'allow_push'
494 web3.ui_value = '*'
495 web3.ui_value = '*'
495
496
496 web4 = RhodeCodeUi()
497 web4 = RhodeCodeUi()
497 web4.ui_section = 'web'
498 web4.ui_section = 'web'
498 web4.ui_key = 'baseurl'
499 web4.ui_key = 'baseurl'
499 web4.ui_value = '/'
500 web4.ui_value = '/'
500
501
501 paths = RhodeCodeUi()
502 paths = RhodeCodeUi()
502 paths.ui_section = 'paths'
503 paths.ui_section = 'paths'
503 paths.ui_key = '/'
504 paths.ui_key = '/'
504 paths.ui_value = path
505 paths.ui_value = path
505
506
506 phases = RhodeCodeUi()
507 phases = RhodeCodeUi()
507 phases.ui_section = 'phases'
508 phases.ui_section = 'phases'
508 phases.ui_key = 'publish'
509 phases.ui_key = 'publish'
509 phases.ui_value = False
510 phases.ui_value = False
510
511
511 sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
512 sett1 = RhodeCodeSetting('realm', 'RhodeCode authentication')
512 sett2 = RhodeCodeSetting('title', 'RhodeCode')
513 sett2 = RhodeCodeSetting('title', 'RhodeCode')
513 sett3 = RhodeCodeSetting('ga_code', '')
514 sett3 = RhodeCodeSetting('ga_code', '')
514
515
515 sett4 = RhodeCodeSetting('show_public_icon', True)
516 sett4 = RhodeCodeSetting('show_public_icon', True)
516 sett5 = RhodeCodeSetting('show_private_icon', True)
517 sett5 = RhodeCodeSetting('show_private_icon', True)
517 sett6 = RhodeCodeSetting('stylify_metatags', False)
518 sett6 = RhodeCodeSetting('stylify_metatags', False)
518
519
519 self.sa.add(web1)
520 self.sa.add(web1)
520 self.sa.add(web2)
521 self.sa.add(web2)
521 self.sa.add(web3)
522 self.sa.add(web3)
522 self.sa.add(web4)
523 self.sa.add(web4)
523 self.sa.add(paths)
524 self.sa.add(paths)
524 self.sa.add(sett1)
525 self.sa.add(sett1)
525 self.sa.add(sett2)
526 self.sa.add(sett2)
526 self.sa.add(sett3)
527 self.sa.add(sett3)
527 self.sa.add(sett4)
528 self.sa.add(sett4)
528 self.sa.add(sett5)
529 self.sa.add(sett5)
529 self.sa.add(sett6)
530 self.sa.add(sett6)
530
531
531 self.create_ldap_options()
532 self.create_ldap_options()
532
533
533 log.info('created ui config')
534 log.info('created ui config')
534
535
535 def create_user(self, username, password, email='', admin=False):
536 def create_user(self, username, password, email='', admin=False):
536 log.info('creating user %s' % username)
537 log.info('creating user %s' % username)
537 UserModel().create_or_update(username, password, email,
538 UserModel().create_or_update(username, password, email,
538 firstname='RhodeCode', lastname='Admin',
539 firstname='RhodeCode', lastname='Admin',
539 active=True, admin=admin)
540 active=True, admin=admin)
540
541
541 def create_default_user(self):
542 def create_default_user(self):
542 log.info('creating default user')
543 log.info('creating default user')
543 # create default user for handling default permissions.
544 # create default user for handling default permissions.
544 UserModel().create_or_update(username='default',
545 UserModel().create_or_update(username='default',
545 password=str(uuid.uuid1())[:8],
546 password=str(uuid.uuid1())[:8],
546 email='anonymous@rhodecode.org',
547 email='anonymous@rhodecode.org',
547 firstname='Anonymous', lastname='User')
548 firstname='Anonymous', lastname='User')
548
549
549 def create_permissions(self):
550 def create_permissions(self):
550 # module.(access|create|change|delete)_[name]
551 # module.(access|create|change|delete)_[name]
551 # module.(none|read|write|admin)
552 # module.(none|read|write|admin)
552
553
553 for p in Permission.PERMS:
554 for p in Permission.PERMS:
554 if not Permission.get_by_key(p[0]):
555 if not Permission.get_by_key(p[0]):
555 new_perm = Permission()
556 new_perm = Permission()
556 new_perm.permission_name = p[0]
557 new_perm.permission_name = p[0]
557 new_perm.permission_longname = p[0]
558 new_perm.permission_longname = p[0]
558 self.sa.add(new_perm)
559 self.sa.add(new_perm)
559
560
560 def populate_default_permissions(self):
561 def populate_default_permissions(self):
561 log.info('creating default user permissions')
562 log.info('creating default user permissions')
562
563
563 default_user = User.get_by_username('default')
564 default_user = User.get_by_username('default')
564
565
565 for def_perm in ['hg.register.manual_activate', 'hg.create.repository',
566 for def_perm in ['hg.register.manual_activate', 'hg.create.repository',
566 'hg.fork.repository', 'repository.read']:
567 'hg.fork.repository', 'repository.read']:
567
568
568 perm = self.sa.query(Permission)\
569 perm = self.sa.query(Permission)\
569 .filter(Permission.permission_name == def_perm)\
570 .filter(Permission.permission_name == def_perm)\
570 .scalar()
571 .scalar()
571 if not perm:
572 if not perm:
572 raise Exception(
573 raise Exception(
573 'CRITICAL: permission %s not found inside database !!'
574 'CRITICAL: permission %s not found inside database !!'
574 % def_perm
575 % def_perm
575 )
576 )
576 if not UserToPerm.query()\
577 if not UserToPerm.query()\
577 .filter(UserToPerm.permission == perm)\
578 .filter(UserToPerm.permission == perm)\
578 .filter(UserToPerm.user == default_user).scalar():
579 .filter(UserToPerm.user == default_user).scalar():
579 reg_perm = UserToPerm()
580 reg_perm = UserToPerm()
580 reg_perm.user = default_user
581 reg_perm.user = default_user
581 reg_perm.permission = perm
582 reg_perm.permission = perm
582 self.sa.add(reg_perm)
583 self.sa.add(reg_perm)
@@ -1,162 +1,173 b''
1 import logging
1 import logging
2 import datetime
2 import datetime
3
3
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.exc import DatabaseError
5 from sqlalchemy.exc import DatabaseError
6 from sqlalchemy.orm import relation, backref, class_mapper
6 from sqlalchemy.orm import relation, backref, class_mapper
7 from sqlalchemy.orm.session import Session
7 from sqlalchemy.orm.session import Session
8 from sqlalchemy.ext.declarative import declarative_base
8 from sqlalchemy.ext.declarative import declarative_base
9
9
10 from rhodecode.lib.dbmigrate.migrate import *
10 from rhodecode.lib.dbmigrate.migrate import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
11 from rhodecode.lib.dbmigrate.migrate.changeset import *
12
12
13 from rhodecode.model.meta import Base
13 from rhodecode.model.meta import Base
14 from rhodecode.model import meta
14 from rhodecode.model import meta
15
15
16 log = logging.getLogger(__name__)
16 log = logging.getLogger(__name__)
17
17
18
18
19 def upgrade(migrate_engine):
19 def upgrade(migrate_engine):
20 """
20 """
21 Upgrade operations go here.
21 Upgrade operations go here.
22 Don't create your own engine; bind migrate_engine to your metadata
22 Don't create your own engine; bind migrate_engine to your metadata
23 """
23 """
24
24
25 #==========================================================================
25 #==========================================================================
26 # USEREMAILMAP
26 # USEREMAILMAP
27 #==========================================================================
27 #==========================================================================
28 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import UserEmailMap
28 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import UserEmailMap
29 tbl = UserEmailMap.__table__
29 tbl = UserEmailMap.__table__
30 tbl.create()
30 tbl.create()
31 #==========================================================================
31 #==========================================================================
32 # PULL REQUEST
32 # PULL REQUEST
33 #==========================================================================
33 #==========================================================================
34 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequest
34 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequest
35 tbl = PullRequest.__table__
35 tbl = PullRequest.__table__
36 tbl.create()
36 tbl.create()
37
37
38 #==========================================================================
38 #==========================================================================
39 # PULL REQUEST REVIEWERS
39 # PULL REQUEST REVIEWERS
40 #==========================================================================
40 #==========================================================================
41 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequestReviewers
41 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequestReviewers
42 tbl = PullRequestReviewers.__table__
42 tbl = PullRequestReviewers.__table__
43 tbl.create()
43 tbl.create()
44
44
45 #==========================================================================
45 #==========================================================================
46 # CHANGESET STATUS
46 # CHANGESET STATUS
47 #==========================================================================
47 #==========================================================================
48 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import ChangesetStatus
48 from rhodecode.lib.dbmigrate.schema.db_1_4_0 import ChangesetStatus
49 tbl = ChangesetStatus.__table__
49 tbl = ChangesetStatus.__table__
50 tbl.create()
50 tbl.create()
51
51
52 ## RESET COMPLETLY THE metadata for sqlalchemy to use the 1_3_0 Base
52 ## RESET COMPLETLY THE metadata for sqlalchemy to use the 1_3_0 Base
53 Base = declarative_base()
53 Base = declarative_base()
54 Base.metadata.clear()
54 Base.metadata.clear()
55 Base.metadata = MetaData()
55 Base.metadata = MetaData()
56 Base.metadata.bind = migrate_engine
56 Base.metadata.bind = migrate_engine
57 meta.Base = Base
57 meta.Base = Base
58
58
59 #==========================================================================
59 #==========================================================================
60 # USERS TABLE
60 # USERS TABLE
61 #==========================================================================
61 #==========================================================================
62 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User
62 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User
63 tbl = User.__table__
63 tbl = User.__table__
64
64
65 # change column name -> firstname
65 # change column name -> firstname
66 col = User.__table__.columns.name
66 col = User.__table__.columns.name
67 col.alter(index=Index('u_username_idx', 'username'))
67 col.alter(index=Index('u_username_idx', 'username'))
68 col.alter(index=Index('u_email_idx', 'email'))
68 col.alter(index=Index('u_email_idx', 'email'))
69 col.alter(name="firstname", table=tbl)
69 col.alter(name="firstname", table=tbl)
70
70
71 inherit_default_permissions = Column("inherit_default_permissions",
71 inherit_default_permissions = Column("inherit_default_permissions",
72 Boolean(), nullable=True, unique=None,
72 Boolean(), nullable=True, unique=None,
73 default=True)
73 default=True)
74 inherit_default_permissions.create(table=tbl)
74 inherit_default_permissions.create(table=tbl)
75 inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
75 inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
76
76
77 #==========================================================================
77 #==========================================================================
78 # GROUPS TABLE
79 #==========================================================================
80 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import RepoGroup
81 tbl = RepoGroup.__table__
82 inherit_default_permissions = Column("inherit_default_permissions",
83 Boolean(), nullable=True, unique=None,
84 default=True)
85 inherit_default_permissions.create(table=tbl)
86 inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
87
88 #==========================================================================
78 # REPOSITORIES
89 # REPOSITORIES
79 #==========================================================================
90 #==========================================================================
80 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Repository
91 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Repository
81 tbl = Repository.__table__
92 tbl = Repository.__table__
82
93
83 enable_locking = Column("enable_locking", Boolean(), nullable=True,
94 enable_locking = Column("enable_locking", Boolean(), nullable=True,
84 unique=None, default=False)
95 unique=None, default=False)
85 enable_locking.create(table=tbl)
96 enable_locking.create(table=tbl)
86 enable_locking.alter(nullable=False, default=False, table=tbl)
97 enable_locking.alter(nullable=False, default=False, table=tbl)
87
98
88 _locked = Column("locked", String(255), nullable=True, unique=False,
99 _locked = Column("locked", String(255), nullable=True, unique=False,
89 default=None)
100 default=None)
90 _locked.create(table=tbl)
101 _locked.create(table=tbl)
91
102
92 landing_rev = Column("landing_revision", String(255), nullable=True,
103 landing_rev = Column("landing_revision", String(255), nullable=True,
93 unique=False, default='tip')
104 unique=False, default='tip')
94 landing_rev.create(table=tbl)
105 landing_rev.create(table=tbl)
95 landing_rev.alter(nullable=False, default='tip', table=tbl)
106 landing_rev.alter(nullable=False, default='tip', table=tbl)
96
107
97 #==========================================================================
108 #==========================================================================
98 # GROUPS
109 # GROUPS
99 #==========================================================================
110 #==========================================================================
100 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import RepoGroup
111 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import RepoGroup
101 tbl = RepoGroup.__table__
112 tbl = RepoGroup.__table__
102 enable_locking = Column("enable_locking", Boolean(), nullable=True,
113 enable_locking = Column("enable_locking", Boolean(), nullable=True,
103 unique=None, default=False)
114 unique=None, default=False)
104 enable_locking.create(table=tbl)
115 enable_locking.create(table=tbl)
105 enable_locking.alter(nullable=False, default=False)
116 enable_locking.alter(nullable=False, default=False)
106
117
107 #==========================================================================
118 #==========================================================================
108 # CACHE INVALIDATION
119 # CACHE INVALIDATION
109 #==========================================================================
120 #==========================================================================
110 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import CacheInvalidation
121 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import CacheInvalidation
111 tbl = CacheInvalidation.__table__
122 tbl = CacheInvalidation.__table__
112
123
113 # change column name -> firstname
124 # change column name -> firstname
114 col = CacheInvalidation.__table__.columns.cache_key
125 col = CacheInvalidation.__table__.columns.cache_key
115 col.alter(index=Index('key_idx', 'cache_key'))
126 col.alter(index=Index('key_idx', 'cache_key'))
116
127
117 #==========================================================================
128 #==========================================================================
118 # NOTIFICATION
129 # NOTIFICATION
119 #==========================================================================
130 #==========================================================================
120 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Notification
131 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Notification
121 tbl = Notification.__table__
132 tbl = Notification.__table__
122
133
123 # change column name -> firstname
134 # change column name -> firstname
124 col = Notification.__table__.columns.type
135 col = Notification.__table__.columns.type
125 col.alter(index=Index('notification_type_idx', 'type'),)
136 col.alter(index=Index('notification_type_idx', 'type'),)
126
137
127 #==========================================================================
138 #==========================================================================
128 # CHANGESET_COMMENTS
139 # CHANGESET_COMMENTS
129 #==========================================================================
140 #==========================================================================
130 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import ChangesetComment
141 from rhodecode.lib.dbmigrate.schema.db_1_3_0 import ChangesetComment
131
142
132 tbl = ChangesetComment.__table__
143 tbl = ChangesetComment.__table__
133
144
134 col = ChangesetComment.__table__.columns.revision
145 col = ChangesetComment.__table__.columns.revision
135 col.alter(index=Index('cc_revision_idx', 'revision'),)
146 col.alter(index=Index('cc_revision_idx', 'revision'),)
136
147
137 hl_lines = Column('hl_lines', Unicode(512), nullable=True)
148 hl_lines = Column('hl_lines', Unicode(512), nullable=True)
138 hl_lines.create(table=tbl)
149 hl_lines.create(table=tbl)
139
150
140 created_on = Column('created_on', DateTime(timezone=False), nullable=True,
151 created_on = Column('created_on', DateTime(timezone=False), nullable=True,
141 default=datetime.datetime.now)
152 default=datetime.datetime.now)
142 created_on.create(table=tbl)
153 created_on.create(table=tbl)
143 created_on.alter(nullable=False, default=datetime.datetime.now)
154 created_on.alter(nullable=False, default=datetime.datetime.now)
144 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False,
155 modified_at = Column('modified_at', DateTime(timezone=False), nullable=False,
145 default=datetime.datetime.now)
156 default=datetime.datetime.now)
146 modified_at.alter(type=DateTime(timezone=False), table=tbl)
157 modified_at.alter(type=DateTime(timezone=False), table=tbl)
147
158
148 pull_request_id = Column("pull_request_id", Integer(),
159 pull_request_id = Column("pull_request_id", Integer(),
149 ForeignKey('pull_requests.pull_request_id'),
160 ForeignKey('pull_requests.pull_request_id'),
150 nullable=True)
161 nullable=True)
151 pull_request_id.create(table=tbl)
162 pull_request_id.create(table=tbl)
152 ## RESET COMPLETLY THE metadata for sqlalchemy back after using 1_3_0
163 ## RESET COMPLETLY THE metadata for sqlalchemy back after using 1_3_0
153 Base = declarative_base()
164 Base = declarative_base()
154 Base.metadata.clear()
165 Base.metadata.clear()
155 Base.metadata = MetaData()
166 Base.metadata = MetaData()
156 Base.metadata.bind = migrate_engine
167 Base.metadata.bind = migrate_engine
157 meta.Base = Base
168 meta.Base = Base
158
169
159
170
160 def downgrade(migrate_engine):
171 def downgrade(migrate_engine):
161 meta = MetaData()
172 meta = MetaData()
162 meta.bind = migrate_engine
173 meta.bind = migrate_engine
General Comments 0
You need to be logged in to leave comments. Login now