Mercurial > kallithea
annotate rhodecode/lib/dbmigrate/__init__.py @ 1512:bf263968da47
merge beta in stable branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Oct 2011 01:08:50 +0200 |
parents | a3b2b4b4e440 3bd2e94cbfc8 |
children | 82a88013a3fd |
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
5 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 Database migration modules |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
7 |
833
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 |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
833
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 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
17 # |
833
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. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
22 # |
833
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 |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
26 import logging |
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
27 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
|
28 |
839
ad66bd0e5601
moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
838
diff
changeset
|
29 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 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
|
31 from rhodecode.lib.db_manage import DbManage |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
835
08d2dcd71666
fixed imports on migrate, added getting current version from database
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
33 log = logging.getLogger(__name__) |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
1210 | 35 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 class UpgradeDb(BasePasterCommand): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 """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
|
38 """ |
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 max_args = 1 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 min_args = 1 |
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 usage = "CONFIG_FILE" |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 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
|
45 group_name = "RhodeCode" |
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 parser = Command.standard_parser(verbose=True) |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 def command(self): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 from pylons import config |
836 | 51 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 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
|
53 |
836 | 54 db_uri = config['sqlalchemy.db1.url'] |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
56 dbmanage = DbManage(log_sql=True, dbconf=db_uri, |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
57 root=config['here'], tests=False) |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
58 |
839
ad66bd0e5601
moved db migration do db manage script, added my cycles for upgrades
Marcin Kuzminski <marcin@python-works.com>
parents:
838
diff
changeset
|
59 dbmanage.upgrade() |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
836
diff
changeset
|
60 |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 def update_parser(self): |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 self.parser.add_option('--sql', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 action='store_true', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 dest='just_sql', |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 help="Prints upgrade sql for further investigation", |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 default=False) |