##// END OF EJS Templates
moved db migration do db manage script, added my cycles for upgrades
marcink -
r839:ad66bd0e beta
parent child Browse files
Show More
@@ -43,6 +43,9 b' from rhodecode.model.db import User, Per'
43
43
44 from sqlalchemy.engine import create_engine
44 from sqlalchemy.engine import create_engine
45
45
46 from rhodecode.lib.dbmigrate.migrate.versioning import api
47 from rhodecode.lib.dbmigrate.migrate.exceptions import \
48 DatabaseNotControlledError
46
49
47 log = logging.getLogger(__name__)
50 log = logging.getLogger(__name__)
48
51
@@ -101,6 +104,76 b' class DbManage(object):'
101 raise
104 raise
102 log.info('db version set to: %s', __dbversion__)
105 log.info('db version set to: %s', __dbversion__)
103
106
107
108 def upgrade(self):
109 """Upgrades given database schema to given revision following
110 all needed steps,
111
112 :param revision: revision to upgrade to
113 """
114 upgrade = ask_ok('You are about to perform database upgrade, make '
115 'sure You backed up your database before. '
116 'Continue ? [y/n]')
117 if not upgrade:
118 sys.exit('Nothing done')
119
120 repository_path = 'rhodecode/lib/dbmigrate'
121 db_uri = self.dburi
122
123 try:
124 curr_version = api.db_version(db_uri, repository_path)
125 msg = ('Found current database under version'
126 ' control with version %s' % curr_version)
127
128 except (RuntimeError, DatabaseNotControlledError), e:
129 curr_version = 1
130 msg = ('Current database is not under version control. Setting'
131 ' as version %s' % curr_version)
132 api.version_control(db_uri, repository_path, curr_version)
133
134 print (msg)
135
136 if curr_version == __dbversion__:
137 sys.exit('This database is already at the newest version')
138
139 #======================================================================
140 # UPGRADE STEPS
141 #======================================================================
142 class UpgradeSteps(object):
143
144 def __init__(self, klass):
145 self.klass = klass
146
147 def step_0(self):
148 #step 0 is the schema upgrade, and than follow proper upgrades
149 print ('attempting to do database upgrade to version %s' \
150 % __dbversion__)
151 api.upgrade(db_uri, repository_path, __dbversion__)
152 print ('Schema upgrade completed')
153
154 def step_1(self):
155 pass
156
157 def step_2(self):
158 print ('Patching repo paths for newer version of RhodeCode')
159 self.klass.fix_repo_paths()
160
161 print ('Patching default user of RhodeCode')
162 self.klass.fix_default_user()
163
164 log.info('Changing ui settings')
165 self.klass.create_ui_settings()
166
167
168 upgrade_steps = [0] + range(curr_version + 1, __dbversion__ + 1)
169
170 #CALL THE PROPER ORDER OF STEPS TO PERFORM FULL UPGRADE
171 for step in upgrade_steps:
172 print ('performing upgrade step %s' % step)
173 callable = getattr(UpgradeSteps(self), 'step_%s' % step)()
174
175
176
104 def fix_repo_paths(self):
177 def fix_repo_paths(self):
105 """Fixes a old rhodecode version path into new one without a '*'
178 """Fixes a old rhodecode version path into new one without a '*'
106 """
179 """
@@ -28,10 +28,7 b''
28 import logging
28 import logging
29 from sqlalchemy import engine_from_config
29 from sqlalchemy import engine_from_config
30
30
31 from rhodecode import __dbversion__
31
32 from rhodecode.lib.dbmigrate.migrate.versioning import api
33 from rhodecode.lib.dbmigrate.migrate.exceptions import \
34 DatabaseNotControlledError
35 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
32 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
36 from rhodecode.lib.db_manage import DbManage
33 from rhodecode.lib.db_manage import DbManage
37
34
@@ -55,45 +52,13 b' class UpgradeDb(BasePasterCommand):'
55
52
56 add_cache(config)
53 add_cache(config)
57
54
58
59
60 repository_path = 'rhodecode/lib/dbmigrate'
61 db_uri = config['sqlalchemy.db1.url']
55 db_uri = config['sqlalchemy.db1.url']
62
56
63 try:
64 curr_version = api.db_version(db_uri, repository_path)
65 msg = ('Found current database under version'
66 ' control with version %s' % curr_version)
67
68 except (RuntimeError, DatabaseNotControlledError), e:
69 curr_version = 1
70 msg = ('Current database is not under version control setting'
71 ' as version %s' % curr_version)
72 api.version_control(db_uri, repository_path, curr_version)
73
74 self.notify_msg(msg)
75
76 #now we have our dbversion we can do upgrade
77 self.notify_msg('attempting to do database upgrade to version %s' \
78 % __dbversion__)
79
80 api.upgrade(db_uri, repository_path, __dbversion__)
81 self.notify_msg('Schema upgrade completed')
82
83 #we need to make now some extra operations into database
84 self.notify_msg('Propagating database updates')
85
86 dbmanage = DbManage(log_sql=True, dbconf=db_uri,
57 dbmanage = DbManage(log_sql=True, dbconf=db_uri,
87 root=config['here'], tests=False)
58 root=config['here'], tests=False)
88
59
89 self.notify_msg('Patching repo paths for newer version of RhodeCode')
60 dbmanage.upgrade()
90 dbmanage.fix_repo_paths()
91
61
92 self.notify_msg('Patching default user of RhodeCode')
93 dbmanage.fix_default_user()
94
95 self.notify_msg('Changing ui settings')
96 dbmanage.create_ui_settings()
97
62
98
63
99 def update_parser(self):
64 def update_parser(self):
General Comments 0
You need to be logged in to leave comments. Login now