##// END OF EJS Templates
db-migrate: backport some changes for py3 compat.
marcink -
r4343:2ba995a1 default
parent child
Show More
@@ -12,10 +12,11 from sqlalchemy import __version__ as _s
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))
15 _sa_version = tuple(int(re.match("\d+", x).group(0)) for x in _sa_version.split("."))
16 for x in _sa_version.split("."))
17 SQLA_07 = _sa_version >= (0, 7)
16 SQLA_07 = _sa_version >= (0, 7)
18 SQLA_08 = _sa_version >= (0, 8)
17 SQLA_08 = _sa_version >= (0, 8)
18 SQLA_09 = _sa_version >= (0, 9)
19 SQLA_10 = _sa_version >= (1, 0)
19
20
20 del re
21 del re
21 del _sa_version
22 del _sa_version
@@ -23,8 +24,8 del _sa_version
23 from rhodecode.lib.dbmigrate.migrate.changeset.schema import *
24 from rhodecode.lib.dbmigrate.migrate.changeset.schema import *
24 from rhodecode.lib.dbmigrate.migrate.changeset.constraint import *
25 from rhodecode.lib.dbmigrate.migrate.changeset.constraint import *
25
26
26 sqlalchemy.schema.Table.__bases__ += (ChangesetTable,)
27 sqlalchemy.schema.Table.__bases__ += (ChangesetTable, )
27 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn,)
28 sqlalchemy.schema.Column.__bases__ += (ChangesetColumn, )
28 sqlalchemy.schema.Index.__bases__ += (ChangesetIndex,)
29 sqlalchemy.schema.Index.__bases__ += (ChangesetIndex, )
29
30
30 sqlalchemy.schema.DefaultClause.__bases__ += (ChangesetDefaultClause,)
31 sqlalchemy.schema.DefaultClause.__bases__ += (ChangesetDefaultClause, )
@@ -97,7 +97,6 class ANSIColumnGenerator(AlterTableVisi
97
97
98 table = self.start_alter_table(column)
98 table = self.start_alter_table(column)
99 self.append("ADD ")
99 self.append("ADD ")
100
101 self.append(self.get_column_specification(column))
100 self.append(self.get_column_specification(column))
102
101
103 for cons in column.constraints:
102 for cons in column.constraints:
@@ -111,7 +111,7 class ForeignKeyConstraint(ConstraintCha
111 refcolnames, reftable = self._normalize_columns(refcolumns,
111 refcolnames, reftable = self._normalize_columns(refcolumns,
112 table_name=True)
112 table_name=True)
113 super(ForeignKeyConstraint, self).__init__(
113 super(ForeignKeyConstraint, self).__init__(
114 colnames, refcolnames, *args,**kwargs
114 colnames, refcolnames, *args, **kwargs
115 )
115 )
116 if table is not None:
116 if table is not None:
117 self._set_parent(table)
117 self._set_parent(table)
@@ -3,11 +3,15
3
3
4 .. _`SQLite`: http://www.sqlite.org/
4 .. _`SQLite`: http://www.sqlite.org/
5 """
5 """
6 from UserDict import DictMixin
6 try: # Python 3
7 from collections.abc import MutableMapping as DictMixin
8 except ImportError: # Python 2
9 from UserDict import DictMixin
7 from copy import copy
10 from copy import copy
8 import re
11 import re
9
12
10 from sqlalchemy.databases import sqlite as sa_base
13 from sqlalchemy.databases import sqlite as sa_base
14 from sqlalchemy.schema import ForeignKeyConstraint
11 from sqlalchemy.schema import UniqueConstraint
15 from sqlalchemy.schema import UniqueConstraint
12
16
13 from rhodecode.lib.dbmigrate.migrate import exceptions
17 from rhodecode.lib.dbmigrate.migrate import exceptions
@@ -1,10 +1,13
1 """
1 """
2 Schema module providing common schema operations.
2 Schema module providing common schema operations.
3 """
3 """
4 import abc
5 try: # Python 3
6 from collections.abc import MutableMapping as DictMixin
7 except ImportError: # Python 2
8 from UserDict import DictMixin
4 import warnings
9 import warnings
5
10
6 from UserDict import DictMixin
7
8 import sqlalchemy
11 import sqlalchemy
9
12
10 from sqlalchemy.schema import ForeignKeyConstraint
13 from sqlalchemy.schema import ForeignKeyConstraint
@@ -1,6 +1,17
1 """
1 """
2 Safe quoting method
2 Safe quoting method
3 """
3 """
4 from rhodecode.lib.dbmigrate.migrate.changeset import SQLA_10
5
6
7 def fk_column_names(constraint):
8 if SQLA_10:
9 return [
10 constraint.columns[key].name for key in constraint.column_keys]
11 else:
12 return [
13 element.parent.name for element in constraint.elements]
14
4
15
5 def safe_quote(obj):
16 def safe_quote(obj):
6 # this is the SQLA 0.9 approach
17 # this is the SQLA 0.9 approach
@@ -27,6 +27,10 class InvalidVersionError(ControlledSche
27 """Invalid version number."""
27 """Invalid version number."""
28
28
29
29
30 class VersionNotFoundError(KeyError):
31 """Specified version is not present."""
32
33
30 class DatabaseNotControlledError(ControlledSchemaError):
34 class DatabaseNotControlledError(ControlledSchemaError):
31 """Database should be under version control, but it's not."""
35 """Database should be under version control, but it's not."""
32
36
General Comments 0
You need to be logged in to leave comments. Login now