##// END OF EJS Templates
pep8ify
marcink -
r1210:3bd2e94c beta
parent child Browse files
Show More
@@ -1,67 +1,66 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.lib.dbmigrate.__init__
3 rhodecode.lib.dbmigrate.__init__
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Database migration modules
6 Database migration modules
7
7
8 :created_on: Dec 11, 2010
8 :created_on: Dec 11, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
16 # (at your option) any later version.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25
25
26 import logging
26 import logging
27 from sqlalchemy import engine_from_config
27 from sqlalchemy import engine_from_config
28
28
29
29
30 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
30 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
31 from rhodecode.lib.db_manage import DbManage
31 from rhodecode.lib.db_manage import DbManage
32
32
33 log = logging.getLogger(__name__)
33 log = logging.getLogger(__name__)
34
34
35
35 class UpgradeDb(BasePasterCommand):
36 class UpgradeDb(BasePasterCommand):
36 """Command used for paster to upgrade our database to newer version
37 """Command used for paster to upgrade our database to newer version
37 """
38 """
38
39
39 max_args = 1
40 max_args = 1
40 min_args = 1
41 min_args = 1
41
42
42 usage = "CONFIG_FILE"
43 usage = "CONFIG_FILE"
43 summary = "Upgrades current db to newer version given configuration file"
44 summary = "Upgrades current db to newer version given configuration file"
44 group_name = "RhodeCode"
45 group_name = "RhodeCode"
45
46
46 parser = Command.standard_parser(verbose=True)
47 parser = Command.standard_parser(verbose=True)
47
48
48 def command(self):
49 def command(self):
49 from pylons import config
50 from pylons import config
50
51
51 add_cache(config)
52 add_cache(config)
52
53
53 db_uri = config['sqlalchemy.db1.url']
54 db_uri = config['sqlalchemy.db1.url']
54
55
55 dbmanage = DbManage(log_sql=True, dbconf=db_uri,
56 dbmanage = DbManage(log_sql=True, dbconf=db_uri,
56 root=config['here'], tests=False)
57 root=config['here'], tests=False)
57
58
58 dbmanage.upgrade()
59 dbmanage.upgrade()
59
60
60
61
62 def update_parser(self):
61 def update_parser(self):
63 self.parser.add_option('--sql',
62 self.parser.add_option('--sql',
64 action='store_true',
63 action='store_true',
65 dest='just_sql',
64 dest='just_sql',
66 help="Prints upgrade sql for further investigation",
65 help="Prints upgrade sql for further investigation",
67 default=False)
66 default=False)
@@ -1,28 +1,29 b''
1 """
1 """
2 This module extends SQLAlchemy and provides additional DDL [#]_
2 This module extends SQLAlchemy and provides additional DDL [#]_
3 support.
3 support.
4
4
5 .. [#] SQL Data Definition Language
5 .. [#] SQL Data Definition Language
6 """
6 """
7 import re
7 import re
8 import warnings
8 import warnings
9
9
10 import sqlalchemy
10 import sqlalchemy
11 from sqlalchemy import __version__ as _sa_version
11 from sqlalchemy import __version__ as _sa_version
12
12
13 warnings.simplefilter('always', DeprecationWarning)
13 warnings.simplefilter('always', DeprecationWarning)
14
14
15 _sa_version = tuple(int(re.match("\d+", x).group(0)) for x in _sa_version.split("."))
15 _sa_version = tuple(int(re.match("\d+", x).group(0))
16 for x in _sa_version.split("."))
16 SQLA_06 = _sa_version >= (0, 6)
17 SQLA_06 = _sa_version >= (0, 6)
17
18
18 del re
19 del re
19 del _sa_version
20 del _sa_version
20
21
21 from rhodecode.lib.dbmigrate.migrate.changeset.schema import *
22 from rhodecode.lib.dbmigrate.migrate.changeset.schema import *
22 from rhodecode.lib.dbmigrate.migrate.changeset.constraint import *
23 from rhodecode.lib.dbmigrate.migrate.changeset.constraint import *
23
24
24 sqlalchemy.schema.Table.__bases__ += (ChangesetTable, )
25 sqlalchemy.schema.Table.__bases__ += (ChangesetTable,)
25 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn, )
26 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn,)
26 sqlalchemy.schema.Index.__bases__ += (ChangesetIndex, )
27 sqlalchemy.schema.Index.__bases__ += (ChangesetIndex,)
27
28
28 sqlalchemy.schema.DefaultClause.__bases__ += (ChangesetDefaultClause, )
29 sqlalchemy.schema.DefaultClause.__bases__ += (ChangesetDefaultClause,)
@@ -1,87 +1,83 b''
1 """
1 """
2 Provide exception classes for :mod:`migrate`
2 Provide exception classes for :mod:`migrate`
3 """
3 """
4
4
5
5
6 class Error(Exception):
6 class Error(Exception):
7 """Error base class."""
7 """Error base class."""
8
8
9
9
10 class ApiError(Error):
10 class ApiError(Error):
11 """Base class for API errors."""
11 """Base class for API errors."""
12
12
13
13
14 class KnownError(ApiError):
14 class KnownError(ApiError):
15 """A known error condition."""
15 """A known error condition."""
16
16
17
17
18 class UsageError(ApiError):
18 class UsageError(ApiError):
19 """A known error condition where help should be displayed."""
19 """A known error condition where help should be displayed."""
20
20
21
21
22 class ControlledSchemaError(Error):
22 class ControlledSchemaError(Error):
23 """Base class for controlled schema errors."""
23 """Base class for controlled schema errors."""
24
24
25
25
26 class InvalidVersionError(ControlledSchemaError):
26 class InvalidVersionError(ControlledSchemaError):
27 """Invalid version number."""
27 """Invalid version number."""
28
28
29
29
30 class DatabaseNotControlledError(ControlledSchemaError):
30 class DatabaseNotControlledError(ControlledSchemaError):
31 """Database should be under version control, but it's not."""
31 """Database should be under version control, but it's not."""
32
32
33
33
34 class DatabaseAlreadyControlledError(ControlledSchemaError):
34 class DatabaseAlreadyControlledError(ControlledSchemaError):
35 """Database shouldn't be under version control, but it is"""
35 """Database shouldn't be under version control, but it is"""
36
36
37
37
38 class WrongRepositoryError(ControlledSchemaError):
38 class WrongRepositoryError(ControlledSchemaError):
39 """This database is under version control by another repository."""
39 """This database is under version control by another repository."""
40
40
41
41
42 class NoSuchTableError(ControlledSchemaError):
42 class NoSuchTableError(ControlledSchemaError):
43 """The table does not exist."""
43 """The table does not exist."""
44
44
45
45
46 class PathError(Error):
46 class PathError(Error):
47 """Base class for path errors."""
47 """Base class for path errors."""
48
48
49
49
50 class PathNotFoundError(PathError):
50 class PathNotFoundError(PathError):
51 """A path with no file was required; found a file."""
51 """A path with no file was required; found a file."""
52
52
53
53
54 class PathFoundError(PathError):
54 class PathFoundError(PathError):
55 """A path with a file was required; found no file."""
55 """A path with a file was required; found no file."""
56
56
57
57
58 class RepositoryError(Error):
58 class RepositoryError(Error):
59 """Base class for repository errors."""
59 """Base class for repository errors."""
60
60
61
61
62 class InvalidRepositoryError(RepositoryError):
62 class InvalidRepositoryError(RepositoryError):
63 """Invalid repository error."""
63 """Invalid repository error."""
64
64
65
65
66 class ScriptError(Error):
66 class ScriptError(Error):
67 """Base class for script errors."""
67 """Base class for script errors."""
68
68
69
69
70 class InvalidScriptError(ScriptError):
70 class InvalidScriptError(ScriptError):
71 """Invalid script error."""
71 """Invalid script error."""
72
72
73
73
74 class InvalidVersionError(Error):
75 """Invalid version error."""
76
77 # migrate.changeset
78
79 class NotSupportedError(Error):
74 class NotSupportedError(Error):
80 """Not supported error"""
75 """Not supported error"""
81
76
82
77
83 class InvalidConstraintError(Error):
78 class InvalidConstraintError(Error):
84 """Invalid constraint error"""
79 """Invalid constraint error"""
85
80
81
86 class MigrateDeprecationWarning(DeprecationWarning):
82 class MigrateDeprecationWarning(DeprecationWarning):
87 """Warning for deprecated features in Migrate"""
83 """Warning for deprecated features in Migrate"""
General Comments 0
You need to be logged in to leave comments. Login now