Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/__init__.py @ 838:12eb1a018199 beta
db migrations:
Added patch for default user
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 11 Dec 2010 04:39:13 +0100 |
parents | 60cbde084047 |
children | ad66bd0e5601 |
rev | line source |
---|---|
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.lib.dbmigrate.__init__ |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Database migration modules |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Dec 11, 2010 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software; you can redistribute it and/or |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # modify it under the terms of the GNU General Public License |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # as published by the Free Software Foundation; version 2 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # of the License or (at your opinion) any later version of the license. |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # along with this program; if not, write to the Free Software |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 # MA 02110-1301, USA. |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
28 import logging |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
29 from sqlalchemy import engine_from_config |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
30 |
836 | 31 from rhodecode import __dbversion__ |
32 from rhodecode.lib.dbmigrate.migrate.versioning import api | |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
33 from rhodecode.lib.dbmigrate.migrate.exceptions import \ |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
34 DatabaseNotControlledError |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
36 from rhodecode.lib.db_manage import DbManage |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
38 log = logging.getLogger(__name__) |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 class UpgradeDb(BasePasterCommand): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 """Command used for paster to upgrade our database to newer version |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 """ |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 max_args = 1 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 min_args = 1 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 usage = "CONFIG_FILE" |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 summary = "Upgrades current db to newer version given configuration file" |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 group_name = "RhodeCode" |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 parser = Command.standard_parser(verbose=True) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 def command(self): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 from pylons import config |
836 | 55 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 add_cache(config) |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
57 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
58 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
59 |
836 | 60 repository_path = 'rhodecode/lib/dbmigrate' |
61 db_uri = config['sqlalchemy.db1.url'] | |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
63 try: |
836 | 64 curr_version = api.db_version(db_uri, repository_path) |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
65 msg = ('Found current database under version' |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
66 ' control with version %s' % curr_version) |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
67 |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
68 except (RuntimeError, DatabaseNotControlledError), e: |
836 | 69 curr_version = 1 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
70 msg = ('Current database is not under version control setting' |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
71 ' as version %s' % curr_version) |
836 | 72 api.version_control(db_uri, repository_path, curr_version) |
73 | |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
74 self.notify_msg(msg) |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
75 |
836 | 76 #now we have our dbversion we can do upgrade |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
77 self.notify_msg('attempting to do database upgrade to version %s' \ |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
78 % __dbversion__) |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
79 |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
80 api.upgrade(db_uri, repository_path, __dbversion__) |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
81 self.notify_msg('Schema upgrade completed') |
836 | 82 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
83 #we need to make now some extra operations into database |
838 | 84 self.notify_msg('Propagating database updates') |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
85 |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
86 dbmanage = DbManage(log_sql=True, dbconf=db_uri, |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
87 root=config['here'], tests=False) |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
88 |
838 | 89 self.notify_msg('Patching repo paths for newer version of RhodeCode') |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
90 dbmanage.fix_repo_paths() |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
91 |
838 | 92 self.notify_msg('Patching default user of RhodeCode') |
93 dbmanage.fix_default_user() | |
94 | |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
95 self.notify_msg('Changing ui settings') |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
96 dbmanage.create_ui_settings() |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
97 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 def update_parser(self): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 self.parser.add_option('--sql', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 action='store_true', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 dest='just_sql', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 help="Prints upgrade sql for further investigation", |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 default=False) |