Show More
@@ -126,7 +126,7 b' class DbManage(object):' | |||
|
126 | 126 | log.info("Deleting (%s) cache keys now...", total) |
|
127 | 127 | CacheKey.delete_all_cache() |
|
128 | 128 | |
|
129 | def upgrade(self): | |
|
129 | def upgrade(self, version=None): | |
|
130 | 130 | """ |
|
131 | 131 | Upgrades given database schema to given revision following |
|
132 | 132 | all needed steps, to perform the upgrade |
@@ -157,9 +157,9 b' class DbManage(object):' | |||
|
157 | 157 | db_uri = self.dburi |
|
158 | 158 | |
|
159 | 159 | try: |
|
160 | curr_version = api.db_version(db_uri, repository_path) | |
|
161 | msg = ('Found current database under version ' | |
|
162 |
'control with version |
|
|
160 | curr_version = version or api.db_version(db_uri, repository_path) | |
|
161 | msg = ('Found current database db_uri under version ' | |
|
162 | 'control with version {}'.format(curr_version)) | |
|
163 | 163 | |
|
164 | 164 | except (RuntimeError, DatabaseNotControlledError): |
|
165 | 165 | curr_version = 1 |
@@ -86,7 +86,8 b' class DBBackend(object):' | |||
|
86 | 86 | _store = os.path.dirname(os.path.abspath(__file__)) |
|
87 | 87 | _type = None |
|
88 | 88 | _base_ini_config = [{'app:main': {'vcs.start_server': 'false', |
|
89 |
'startup.import_repos': 'false' |
|
|
89 | 'startup.import_repos': 'false', | |
|
90 | 'is_test': 'False'}}] | |
|
90 | 91 | _db_url = [{'app:main': {'sqlalchemy.db1.url': ''}}] |
|
91 | 92 | _base_db_name = 'rhodecode_test_db_backend' |
|
92 | 93 | |
@@ -152,6 +153,9 b' class DBBackend(object):' | |||
|
152 | 153 | print(self.stderr) |
|
153 | 154 | raise AssertionError('non 0 retcode:{}'.format(self.p.returncode)) |
|
154 | 155 | |
|
156 | def assert_correct_output(self, stdout, version): | |
|
157 | assert 'UPGRADE FOR STEP {} COMPLETED'.format(version) in stdout | |
|
158 | ||
|
155 | 159 | def setup_rhodecode_db(self, ini_params=None, env=None): |
|
156 | 160 | if not ini_params: |
|
157 | 161 | ini_params = self._base_ini_config |
@@ -167,7 +171,7 b' class DBBackend(object):' | |||
|
167 | 171 | if not os.path.isdir(self._repos_git_lfs_store): |
|
168 | 172 | os.makedirs(self._repos_git_lfs_store) |
|
169 | 173 | |
|
170 | self.execute( | |
|
174 | return self.execute( | |
|
171 | 175 | "rc-setup-app {0} --user=marcink " |
|
172 | 176 | "--email=marcin@rhodeocode.com --password={1} " |
|
173 | 177 | "--repos={2} --force-yes".format( |
@@ -183,7 +187,8 b' class DBBackend(object):' | |||
|
183 | 187 | with test_ini as ini_file: |
|
184 | 188 | if not os.path.isdir(self._repos_location): |
|
185 | 189 | os.makedirs(self._repos_location) |
|
186 | self.execute( | |
|
190 | ||
|
191 | return self.execute( | |
|
187 | 192 | "rc-upgrade-db {0} --force-yes".format(ini_file)) |
|
188 | 193 | |
|
189 | 194 | def setup_db(self): |
@@ -226,12 +231,11 b' class SQLiteDBBackend(DBBackend):' | |||
|
226 | 231 | |
|
227 | 232 | def import_dump(self, dumpname): |
|
228 | 233 | dump = os.path.join(self.fixture_store, dumpname) |
|
229 | shutil.copy( | |
|
230 | dump, | |
|
231 | os.path.join(self._basetemp, '{0.db_name}.sqlite'.format(self))) | |
|
234 | target = os.path.join(self._basetemp, '{0.db_name}.sqlite'.format(self)) | |
|
235 | return self.execute('cp -v {} {}'.format(dump, target)) | |
|
232 | 236 | |
|
233 | 237 | def teardown_db(self): |
|
234 | self.execute("rm -rf {}.sqlite".format( | |
|
238 | return self.execute("rm -rf {}.sqlite".format( | |
|
235 | 239 | os.path.join(self._basetemp, self.db_name))) |
|
236 | 240 | |
|
237 | 241 | |
@@ -246,16 +250,16 b' class MySQLDBBackend(DBBackend):' | |||
|
246 | 250 | # mysqldump -uroot -pqweqwe $TEST_DB_NAME |
|
247 | 251 | self._db_url = [{'app:main': { |
|
248 | 252 | 'sqlalchemy.db1.url': self.connection_string}}] |
|
249 | self.execute("mysql -v -u{} -p{} -e 'create database '{}';'".format( | |
|
253 | return self.execute("mysql -v -u{} -p{} -e 'create database '{}';'".format( | |
|
250 | 254 | self.user, self.password, self.db_name)) |
|
251 | 255 | |
|
252 | 256 | def import_dump(self, dumpname): |
|
253 | 257 | dump = os.path.join(self.fixture_store, dumpname) |
|
254 | self.execute("mysql -u{} -p{} {} < {}".format( | |
|
258 | return self.execute("mysql -u{} -p{} {} < {}".format( | |
|
255 | 259 | self.user, self.password, self.db_name, dump)) |
|
256 | 260 | |
|
257 | 261 | def teardown_db(self): |
|
258 | self.execute("mysql -v -u{} -p{} -e 'drop database '{}';'".format( | |
|
262 | return self.execute("mysql -v -u{} -p{} -e 'drop database '{}';'".format( | |
|
259 | 263 | self.user, self.password, self.db_name)) |
|
260 | 264 | |
|
261 | 265 | |
@@ -271,18 +275,18 b' class PostgresDBBackend(DBBackend):' | |||
|
271 | 275 | self._db_url = [{'app:main': { |
|
272 | 276 | 'sqlalchemy.db1.url': |
|
273 | 277 | self.connection_string}}] |
|
274 | self.execute("PGPASSWORD={} psql -U {} -h localhost " | |
|
278 | return self.execute("PGPASSWORD={} psql -U {} -h localhost " | |
|
275 | 279 | "-c 'create database '{}';'".format( |
|
276 | 280 | self.password, self.user, self.db_name)) |
|
277 | 281 | |
|
278 | 282 | def teardown_db(self): |
|
279 | self.execute("PGPASSWORD={} psql -U {} -h localhost " | |
|
283 | return self.execute("PGPASSWORD={} psql -U {} -h localhost " | |
|
280 | 284 | "-c 'drop database if exists '{}';'".format( |
|
281 | 285 | self.password, self.user, self.db_name)) |
|
282 | 286 | |
|
283 | 287 | def import_dump(self, dumpname): |
|
284 | 288 | dump = os.path.join(self.fixture_store, dumpname) |
|
285 | self.execute( | |
|
289 | return self.execute( | |
|
286 | 290 | "PGPASSWORD={} psql -U {} -h localhost -d {} -1 " |
|
287 | 291 | "-f {}".format( |
|
288 | 292 | self.password, self.user, self.db_name, dump)) |
@@ -59,5 +59,7 b' def _run_migration_test(db_backend, dump' | |||
|
59 | 59 | db_backend.assert_returncode_success() |
|
60 | 60 | |
|
61 | 61 | db_backend.import_dump(dumpname) |
|
62 | db_backend.upgrade_database() | |
|
62 | stdout, stderr = db_backend.upgrade_database() | |
|
63 | ||
|
64 | db_backend.assert_correct_output(stdout+stderr, version='16') | |
|
63 | 65 | db_backend.assert_returncode_success() |
General Comments 0
You need to be logged in to leave comments.
Login now