alembic 1.13.0__py3-none-any.whl → 1.13.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alembic/__init__.py +1 -1
- alembic/autogenerate/__init__.py +10 -10
- alembic/autogenerate/api.py +6 -4
- alembic/autogenerate/compare.py +5 -4
- alembic/autogenerate/render.py +9 -9
- alembic/autogenerate/rewriter.py +26 -13
- alembic/command.py +3 -1
- alembic/config.py +20 -9
- alembic/context.pyi +10 -5
- alembic/ddl/__init__.py +1 -1
- alembic/ddl/_autogen.py +4 -2
- alembic/ddl/base.py +12 -9
- alembic/ddl/impl.py +5 -2
- alembic/ddl/mssql.py +4 -1
- alembic/ddl/mysql.py +5 -3
- alembic/ddl/oracle.py +4 -1
- alembic/ddl/postgresql.py +16 -9
- alembic/ddl/sqlite.py +8 -6
- alembic/op.pyi +46 -8
- alembic/operations/base.py +70 -14
- alembic/operations/batch.py +7 -8
- alembic/operations/ops.py +52 -30
- alembic/operations/schemaobj.py +5 -4
- alembic/operations/toimpl.py +3 -0
- alembic/runtime/environment.py +15 -6
- alembic/runtime/migration.py +27 -11
- alembic/script/base.py +13 -15
- alembic/script/revision.py +30 -17
- alembic/script/write_hooks.py +3 -0
- alembic/util/__init__.py +31 -31
- alembic/util/compat.py +25 -8
- alembic/util/langhelpers.py +78 -33
- alembic/util/messaging.py +6 -3
- alembic/util/pyfiles.py +7 -3
- alembic/util/sqla_compat.py +43 -14
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/METADATA +1 -1
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/RECORD +41 -41
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/LICENSE +0 -0
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/WHEEL +0 -0
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/entry_points.txt +0 -0
- {alembic-1.13.0.dist-info → alembic-1.13.1.dist-info}/top_level.txt +0 -0
alembic/ddl/postgresql.py
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
2
|
+
# mypy: no-warn-return-any, allow-any-generics
|
3
|
+
|
1
4
|
from __future__ import annotations
|
2
5
|
|
3
6
|
import logging
|
@@ -30,7 +33,6 @@ from .base import alter_column
|
|
30
33
|
from .base import alter_table
|
31
34
|
from .base import AlterColumn
|
32
35
|
from .base import ColumnComment
|
33
|
-
from .base import compiles
|
34
36
|
from .base import format_column_name
|
35
37
|
from .base import format_table_name
|
36
38
|
from .base import format_type
|
@@ -45,6 +47,7 @@ from ..operations import schemaobj
|
|
45
47
|
from ..operations.base import BatchOperations
|
46
48
|
from ..operations.base import Operations
|
47
49
|
from ..util import sqla_compat
|
50
|
+
from ..util.sqla_compat import compiles
|
48
51
|
|
49
52
|
if TYPE_CHECKING:
|
50
53
|
from typing import Literal
|
@@ -136,7 +139,9 @@ class PostgresqlImpl(DefaultImpl):
|
|
136
139
|
metadata_default = literal_column(metadata_default)
|
137
140
|
|
138
141
|
# run a real compare against the server
|
139
|
-
|
142
|
+
conn = self.connection
|
143
|
+
assert conn is not None
|
144
|
+
return not conn.scalar(
|
140
145
|
sqla_compat._select(
|
141
146
|
literal_column(conn_col_default) == metadata_default
|
142
147
|
)
|
@@ -623,9 +628,8 @@ class CreateExcludeConstraintOp(ops.AddConstraintOp):
|
|
623
628
|
return cls(
|
624
629
|
constraint.name,
|
625
630
|
constraint_table.name,
|
626
|
-
[
|
627
|
-
(expr, op)
|
628
|
-
for expr, name, op in constraint._render_exprs # type:ignore[attr-defined] # noqa
|
631
|
+
[ # type: ignore
|
632
|
+
(expr, op) for expr, name, op in constraint._render_exprs
|
629
633
|
],
|
630
634
|
where=cast("ColumnElement[bool] | None", constraint.where),
|
631
635
|
schema=constraint_table.schema,
|
@@ -652,7 +656,7 @@ class CreateExcludeConstraintOp(ops.AddConstraintOp):
|
|
652
656
|
expr,
|
653
657
|
name,
|
654
658
|
oper,
|
655
|
-
) in excl._render_exprs:
|
659
|
+
) in excl._render_exprs:
|
656
660
|
t.append_column(Column(name, NULLTYPE))
|
657
661
|
t.append_constraint(excl)
|
658
662
|
return excl
|
@@ -710,7 +714,7 @@ class CreateExcludeConstraintOp(ops.AddConstraintOp):
|
|
710
714
|
constraint_name: str,
|
711
715
|
*elements: Any,
|
712
716
|
**kw: Any,
|
713
|
-
):
|
717
|
+
) -> Optional[Table]:
|
714
718
|
"""Issue a "create exclude constraint" instruction using the
|
715
719
|
current batch migration context.
|
716
720
|
|
@@ -782,10 +786,13 @@ def _exclude_constraint(
|
|
782
786
|
args = [
|
783
787
|
"(%s, %r)"
|
784
788
|
% (
|
785
|
-
_render_potential_column(
|
789
|
+
_render_potential_column(
|
790
|
+
sqltext, # type:ignore[arg-type]
|
791
|
+
autogen_context,
|
792
|
+
),
|
786
793
|
opstring,
|
787
794
|
)
|
788
|
-
for sqltext, name, opstring in constraint._render_exprs
|
795
|
+
for sqltext, name, opstring in constraint._render_exprs
|
789
796
|
]
|
790
797
|
if constraint.where is not None:
|
791
798
|
args.append(
|
alembic/ddl/sqlite.py
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
2
|
+
# mypy: no-warn-return-any, allow-any-generics
|
3
|
+
|
1
4
|
from __future__ import annotations
|
2
5
|
|
3
6
|
import re
|
@@ -11,13 +14,13 @@ from sqlalchemy import cast
|
|
11
14
|
from sqlalchemy import JSON
|
12
15
|
from sqlalchemy import schema
|
13
16
|
from sqlalchemy import sql
|
14
|
-
from sqlalchemy.ext.compiler import compiles
|
15
17
|
|
16
18
|
from .base import alter_table
|
17
19
|
from .base import format_table_name
|
18
20
|
from .base import RenameTable
|
19
21
|
from .impl import DefaultImpl
|
20
22
|
from .. import util
|
23
|
+
from ..util.sqla_compat import compiles
|
21
24
|
|
22
25
|
if TYPE_CHECKING:
|
23
26
|
from sqlalchemy.engine.reflection import Inspector
|
@@ -71,13 +74,13 @@ class SQLiteImpl(DefaultImpl):
|
|
71
74
|
def add_constraint(self, const: Constraint):
|
72
75
|
# attempt to distinguish between an
|
73
76
|
# auto-gen constraint and an explicit one
|
74
|
-
if const._create_rule is None:
|
77
|
+
if const._create_rule is None:
|
75
78
|
raise NotImplementedError(
|
76
79
|
"No support for ALTER of constraints in SQLite dialect. "
|
77
80
|
"Please refer to the batch mode feature which allows for "
|
78
81
|
"SQLite migrations using a copy-and-move strategy."
|
79
82
|
)
|
80
|
-
elif const._create_rule(self):
|
83
|
+
elif const._create_rule(self):
|
81
84
|
util.warn(
|
82
85
|
"Skipping unsupported ALTER for "
|
83
86
|
"creation of implicit constraint. "
|
@@ -86,7 +89,7 @@ class SQLiteImpl(DefaultImpl):
|
|
86
89
|
)
|
87
90
|
|
88
91
|
def drop_constraint(self, const: Constraint):
|
89
|
-
if const._create_rule is None:
|
92
|
+
if const._create_rule is None:
|
90
93
|
raise NotImplementedError(
|
91
94
|
"No support for ALTER of constraints in SQLite dialect. "
|
92
95
|
"Please refer to the batch mode feature which allows for "
|
@@ -177,8 +180,7 @@ class SQLiteImpl(DefaultImpl):
|
|
177
180
|
new_type: TypeEngine,
|
178
181
|
) -> None:
|
179
182
|
if (
|
180
|
-
existing.type._type_affinity
|
181
|
-
is not new_type._type_affinity # type:ignore[attr-defined]
|
183
|
+
existing.type._type_affinity is not new_type._type_affinity
|
182
184
|
and not isinstance(new_type, JSON)
|
183
185
|
):
|
184
186
|
existing_transfer["expr"] = cast(
|
alembic/op.pyi
CHANGED
@@ -12,6 +12,7 @@ from typing import List
|
|
12
12
|
from typing import Literal
|
13
13
|
from typing import Mapping
|
14
14
|
from typing import Optional
|
15
|
+
from typing import overload
|
15
16
|
from typing import Sequence
|
16
17
|
from typing import Tuple
|
17
18
|
from typing import Type
|
@@ -35,12 +36,28 @@ if TYPE_CHECKING:
|
|
35
36
|
from sqlalchemy.sql.type_api import TypeEngine
|
36
37
|
from sqlalchemy.util import immutabledict
|
37
38
|
|
38
|
-
from .operations.
|
39
|
+
from .operations.base import BatchOperations
|
40
|
+
from .operations.ops import AddColumnOp
|
41
|
+
from .operations.ops import AddConstraintOp
|
42
|
+
from .operations.ops import AlterColumnOp
|
43
|
+
from .operations.ops import AlterTableOp
|
44
|
+
from .operations.ops import BulkInsertOp
|
45
|
+
from .operations.ops import CreateIndexOp
|
46
|
+
from .operations.ops import CreateTableCommentOp
|
47
|
+
from .operations.ops import CreateTableOp
|
48
|
+
from .operations.ops import DropColumnOp
|
49
|
+
from .operations.ops import DropConstraintOp
|
50
|
+
from .operations.ops import DropIndexOp
|
51
|
+
from .operations.ops import DropTableCommentOp
|
52
|
+
from .operations.ops import DropTableOp
|
53
|
+
from .operations.ops import ExecuteSQLOp
|
39
54
|
from .operations.ops import MigrateOperation
|
40
55
|
from .runtime.migration import MigrationContext
|
41
56
|
from .util.sqla_compat import _literal_bindparam
|
42
57
|
|
43
58
|
_T = TypeVar("_T")
|
59
|
+
_C = TypeVar("_C", bound=Callable[..., Any])
|
60
|
+
|
44
61
|
### end imports ###
|
45
62
|
|
46
63
|
def add_column(
|
@@ -132,8 +149,8 @@ def alter_column(
|
|
132
149
|
comment: Union[str, Literal[False], None] = False,
|
133
150
|
server_default: Any = False,
|
134
151
|
new_column_name: Optional[str] = None,
|
135
|
-
type_: Union[TypeEngine, Type[TypeEngine], None] = None,
|
136
|
-
existing_type: Union[TypeEngine, Type[TypeEngine], None] = None,
|
152
|
+
type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
|
153
|
+
existing_type: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
|
137
154
|
existing_server_default: Union[
|
138
155
|
str, bool, Identity, Computed, None
|
139
156
|
] = False,
|
@@ -230,7 +247,7 @@ def batch_alter_table(
|
|
230
247
|
table_name: str,
|
231
248
|
schema: Optional[str] = None,
|
232
249
|
recreate: Literal["auto", "always", "never"] = "auto",
|
233
|
-
partial_reordering: Optional[
|
250
|
+
partial_reordering: Optional[Tuple[Any, ...]] = None,
|
234
251
|
copy_from: Optional[Table] = None,
|
235
252
|
table_args: Tuple[Any, ...] = (),
|
236
253
|
table_kwargs: Mapping[str, Any] = immutabledict({}),
|
@@ -377,7 +394,7 @@ def batch_alter_table(
|
|
377
394
|
|
378
395
|
def bulk_insert(
|
379
396
|
table: Union[Table, TableClause],
|
380
|
-
rows: List[
|
397
|
+
rows: List[Dict[str, Any]],
|
381
398
|
*,
|
382
399
|
multiinsert: bool = True,
|
383
400
|
) -> None:
|
@@ -1162,7 +1179,7 @@ def get_context() -> MigrationContext:
|
|
1162
1179
|
|
1163
1180
|
"""
|
1164
1181
|
|
1165
|
-
def implementation_for(op_cls: Any) -> Callable[
|
1182
|
+
def implementation_for(op_cls: Any) -> Callable[[_C], _C]:
|
1166
1183
|
"""Register an implementation for a given :class:`.MigrateOperation`.
|
1167
1184
|
|
1168
1185
|
This is part of the operation extensibility API.
|
@@ -1174,7 +1191,7 @@ def implementation_for(op_cls: Any) -> Callable[..., Any]:
|
|
1174
1191
|
"""
|
1175
1192
|
|
1176
1193
|
def inline_literal(
|
1177
|
-
value: Union[str, int], type_: Optional[TypeEngine] = None
|
1194
|
+
value: Union[str, int], type_: Optional[TypeEngine[Any]] = None
|
1178
1195
|
) -> _literal_bindparam:
|
1179
1196
|
r"""Produce an 'inline literal' expression, suitable for
|
1180
1197
|
using in an INSERT, UPDATE, or DELETE statement.
|
@@ -1218,6 +1235,27 @@ def inline_literal(
|
|
1218
1235
|
|
1219
1236
|
"""
|
1220
1237
|
|
1238
|
+
@overload
|
1239
|
+
def invoke(operation: CreateTableOp) -> Table: ...
|
1240
|
+
@overload
|
1241
|
+
def invoke(
|
1242
|
+
operation: Union[
|
1243
|
+
AddConstraintOp,
|
1244
|
+
DropConstraintOp,
|
1245
|
+
CreateIndexOp,
|
1246
|
+
DropIndexOp,
|
1247
|
+
AddColumnOp,
|
1248
|
+
AlterColumnOp,
|
1249
|
+
AlterTableOp,
|
1250
|
+
CreateTableCommentOp,
|
1251
|
+
DropTableCommentOp,
|
1252
|
+
DropColumnOp,
|
1253
|
+
BulkInsertOp,
|
1254
|
+
DropTableOp,
|
1255
|
+
ExecuteSQLOp,
|
1256
|
+
]
|
1257
|
+
) -> None: ...
|
1258
|
+
@overload
|
1221
1259
|
def invoke(operation: MigrateOperation) -> Any:
|
1222
1260
|
"""Given a :class:`.MigrateOperation`, invoke it in terms of
|
1223
1261
|
this :class:`.Operations` instance.
|
@@ -1226,7 +1264,7 @@ def invoke(operation: MigrateOperation) -> Any:
|
|
1226
1264
|
|
1227
1265
|
def register_operation(
|
1228
1266
|
name: str, sourcename: Optional[str] = None
|
1229
|
-
) -> Callable[[_T], _T]:
|
1267
|
+
) -> Callable[[Type[_T]], Type[_T]]:
|
1230
1268
|
"""Register a new operation for this class.
|
1231
1269
|
|
1232
1270
|
This method is normally used to add new operations
|
alembic/operations/base.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# mypy: allow-untyped-calls
|
2
|
+
|
1
3
|
from __future__ import annotations
|
2
4
|
|
3
5
|
from contextlib import contextmanager
|
@@ -10,7 +12,9 @@ from typing import Dict
|
|
10
12
|
from typing import Iterator
|
11
13
|
from typing import List # noqa
|
12
14
|
from typing import Mapping
|
15
|
+
from typing import NoReturn
|
13
16
|
from typing import Optional
|
17
|
+
from typing import overload
|
14
18
|
from typing import Sequence # noqa
|
15
19
|
from typing import Tuple
|
16
20
|
from typing import Type # noqa
|
@@ -47,12 +51,28 @@ if TYPE_CHECKING:
|
|
47
51
|
from sqlalchemy.types import TypeEngine
|
48
52
|
|
49
53
|
from .batch import BatchOperationsImpl
|
54
|
+
from .ops import AddColumnOp
|
55
|
+
from .ops import AddConstraintOp
|
56
|
+
from .ops import AlterColumnOp
|
57
|
+
from .ops import AlterTableOp
|
58
|
+
from .ops import BulkInsertOp
|
59
|
+
from .ops import CreateIndexOp
|
60
|
+
from .ops import CreateTableCommentOp
|
61
|
+
from .ops import CreateTableOp
|
62
|
+
from .ops import DropColumnOp
|
63
|
+
from .ops import DropConstraintOp
|
64
|
+
from .ops import DropIndexOp
|
65
|
+
from .ops import DropTableCommentOp
|
66
|
+
from .ops import DropTableOp
|
67
|
+
from .ops import ExecuteSQLOp
|
50
68
|
from .ops import MigrateOperation
|
51
69
|
from ..ddl import DefaultImpl
|
52
70
|
from ..runtime.migration import MigrationContext
|
53
71
|
__all__ = ("Operations", "BatchOperations")
|
54
72
|
_T = TypeVar("_T")
|
55
73
|
|
74
|
+
_C = TypeVar("_C", bound=Callable[..., Any])
|
75
|
+
|
56
76
|
|
57
77
|
class AbstractOperations(util.ModuleClsProxy):
|
58
78
|
"""Base class for Operations and BatchOperations.
|
@@ -86,7 +106,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
86
106
|
@classmethod
|
87
107
|
def register_operation(
|
88
108
|
cls, name: str, sourcename: Optional[str] = None
|
89
|
-
) -> Callable[[_T], _T]:
|
109
|
+
) -> Callable[[Type[_T]], Type[_T]]:
|
90
110
|
"""Register a new operation for this class.
|
91
111
|
|
92
112
|
This method is normally used to add new operations
|
@@ -103,7 +123,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
103
123
|
|
104
124
|
"""
|
105
125
|
|
106
|
-
def register(op_cls):
|
126
|
+
def register(op_cls: Type[_T]) -> Type[_T]:
|
107
127
|
if sourcename is None:
|
108
128
|
fn = getattr(op_cls, name)
|
109
129
|
source_name = fn.__name__
|
@@ -122,8 +142,11 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
122
142
|
*spec, formatannotation=formatannotation_fwdref
|
123
143
|
)
|
124
144
|
num_defaults = len(spec[3]) if spec[3] else 0
|
145
|
+
|
146
|
+
defaulted_vals: Tuple[Any, ...]
|
147
|
+
|
125
148
|
if num_defaults:
|
126
|
-
defaulted_vals = name_args[0 - num_defaults :]
|
149
|
+
defaulted_vals = tuple(name_args[0 - num_defaults :])
|
127
150
|
else:
|
128
151
|
defaulted_vals = ()
|
129
152
|
|
@@ -164,7 +187,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
164
187
|
|
165
188
|
globals_ = dict(globals())
|
166
189
|
globals_.update({"op_cls": op_cls})
|
167
|
-
lcl = {}
|
190
|
+
lcl: Dict[str, Any] = {}
|
168
191
|
|
169
192
|
exec(func_text, globals_, lcl)
|
170
193
|
setattr(cls, name, lcl[name])
|
@@ -180,7 +203,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
180
203
|
return register
|
181
204
|
|
182
205
|
@classmethod
|
183
|
-
def implementation_for(cls, op_cls: Any) -> Callable[
|
206
|
+
def implementation_for(cls, op_cls: Any) -> Callable[[_C], _C]:
|
184
207
|
"""Register an implementation for a given :class:`.MigrateOperation`.
|
185
208
|
|
186
209
|
This is part of the operation extensibility API.
|
@@ -191,7 +214,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
191
214
|
|
192
215
|
"""
|
193
216
|
|
194
|
-
def decorate(fn):
|
217
|
+
def decorate(fn: _C) -> _C:
|
195
218
|
cls._to_impl.dispatch_for(op_cls)(fn)
|
196
219
|
return fn
|
197
220
|
|
@@ -213,7 +236,7 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
213
236
|
table_name: str,
|
214
237
|
schema: Optional[str] = None,
|
215
238
|
recreate: Literal["auto", "always", "never"] = "auto",
|
216
|
-
partial_reordering: Optional[
|
239
|
+
partial_reordering: Optional[Tuple[Any, ...]] = None,
|
217
240
|
copy_from: Optional[Table] = None,
|
218
241
|
table_args: Tuple[Any, ...] = (),
|
219
242
|
table_kwargs: Mapping[str, Any] = util.immutabledict(),
|
@@ -382,6 +405,35 @@ class AbstractOperations(util.ModuleClsProxy):
|
|
382
405
|
|
383
406
|
return self.migration_context
|
384
407
|
|
408
|
+
@overload
|
409
|
+
def invoke(self, operation: CreateTableOp) -> Table:
|
410
|
+
...
|
411
|
+
|
412
|
+
@overload
|
413
|
+
def invoke(
|
414
|
+
self,
|
415
|
+
operation: Union[
|
416
|
+
AddConstraintOp,
|
417
|
+
DropConstraintOp,
|
418
|
+
CreateIndexOp,
|
419
|
+
DropIndexOp,
|
420
|
+
AddColumnOp,
|
421
|
+
AlterColumnOp,
|
422
|
+
AlterTableOp,
|
423
|
+
CreateTableCommentOp,
|
424
|
+
DropTableCommentOp,
|
425
|
+
DropColumnOp,
|
426
|
+
BulkInsertOp,
|
427
|
+
DropTableOp,
|
428
|
+
ExecuteSQLOp,
|
429
|
+
],
|
430
|
+
) -> None:
|
431
|
+
...
|
432
|
+
|
433
|
+
@overload
|
434
|
+
def invoke(self, operation: MigrateOperation) -> Any:
|
435
|
+
...
|
436
|
+
|
385
437
|
def invoke(self, operation: MigrateOperation) -> Any:
|
386
438
|
"""Given a :class:`.MigrateOperation`, invoke it in terms of
|
387
439
|
this :class:`.Operations` instance.
|
@@ -659,8 +711,10 @@ class Operations(AbstractOperations):
|
|
659
711
|
comment: Union[str, Literal[False], None] = False,
|
660
712
|
server_default: Any = False,
|
661
713
|
new_column_name: Optional[str] = None,
|
662
|
-
type_: Union[TypeEngine, Type[TypeEngine], None] = None,
|
663
|
-
existing_type: Union[
|
714
|
+
type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
|
715
|
+
existing_type: Union[
|
716
|
+
TypeEngine[Any], Type[TypeEngine[Any]], None
|
717
|
+
] = None,
|
664
718
|
existing_server_default: Union[
|
665
719
|
str, bool, Identity, Computed, None
|
666
720
|
] = False,
|
@@ -756,7 +810,7 @@ class Operations(AbstractOperations):
|
|
756
810
|
def bulk_insert(
|
757
811
|
self,
|
758
812
|
table: Union[Table, TableClause],
|
759
|
-
rows: List[
|
813
|
+
rows: List[Dict[str, Any]],
|
760
814
|
*,
|
761
815
|
multiinsert: bool = True,
|
762
816
|
) -> None:
|
@@ -1560,7 +1614,7 @@ class BatchOperations(AbstractOperations):
|
|
1560
1614
|
|
1561
1615
|
impl: BatchOperationsImpl
|
1562
1616
|
|
1563
|
-
def _noop(self, operation):
|
1617
|
+
def _noop(self, operation: Any) -> NoReturn:
|
1564
1618
|
raise NotImplementedError(
|
1565
1619
|
"The %s method does not apply to a batch table alter operation."
|
1566
1620
|
% operation
|
@@ -1596,8 +1650,10 @@ class BatchOperations(AbstractOperations):
|
|
1596
1650
|
comment: Union[str, Literal[False], None] = False,
|
1597
1651
|
server_default: Any = False,
|
1598
1652
|
new_column_name: Optional[str] = None,
|
1599
|
-
type_: Union[TypeEngine, Type[TypeEngine], None] = None,
|
1600
|
-
existing_type: Union[
|
1653
|
+
type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
|
1654
|
+
existing_type: Union[
|
1655
|
+
TypeEngine[Any], Type[TypeEngine[Any]], None
|
1656
|
+
] = None,
|
1601
1657
|
existing_server_default: Union[
|
1602
1658
|
str, bool, Identity, Computed, None
|
1603
1659
|
] = False,
|
@@ -1652,7 +1708,7 @@ class BatchOperations(AbstractOperations):
|
|
1652
1708
|
|
1653
1709
|
def create_exclude_constraint(
|
1654
1710
|
self, constraint_name: str, *elements: Any, **kw: Any
|
1655
|
-
):
|
1711
|
+
) -> Optional[Table]:
|
1656
1712
|
"""Issue a "create exclude constraint" instruction using the
|
1657
1713
|
current batch migration context.
|
1658
1714
|
|
alembic/operations/batch.py
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
2
|
+
# mypy: no-warn-return-any, allow-any-generics
|
3
|
+
|
1
4
|
from __future__ import annotations
|
2
5
|
|
3
6
|
from typing import Any
|
@@ -17,7 +20,7 @@ from sqlalchemy import PrimaryKeyConstraint
|
|
17
20
|
from sqlalchemy import schema as sql_schema
|
18
21
|
from sqlalchemy import Table
|
19
22
|
from sqlalchemy import types as sqltypes
|
20
|
-
from sqlalchemy.
|
23
|
+
from sqlalchemy.sql.schema import SchemaEventTarget
|
21
24
|
from sqlalchemy.util import OrderedDict
|
22
25
|
from sqlalchemy.util import topological
|
23
26
|
|
@@ -374,7 +377,7 @@ class ApplyBatchImpl:
|
|
374
377
|
for idx_existing in self.indexes.values():
|
375
378
|
# this is a lift-and-move from Table.to_metadata
|
376
379
|
|
377
|
-
if idx_existing._column_flag:
|
380
|
+
if idx_existing._column_flag:
|
378
381
|
continue
|
379
382
|
|
380
383
|
idx_copy = Index(
|
@@ -403,9 +406,7 @@ class ApplyBatchImpl:
|
|
403
406
|
def _setup_referent(
|
404
407
|
self, metadata: MetaData, constraint: ForeignKeyConstraint
|
405
408
|
) -> None:
|
406
|
-
spec = constraint.elements[
|
407
|
-
0
|
408
|
-
]._get_colspec() # type:ignore[attr-defined]
|
409
|
+
spec = constraint.elements[0]._get_colspec()
|
409
410
|
parts = spec.split(".")
|
410
411
|
tname = parts[-2]
|
411
412
|
if len(parts) == 3:
|
@@ -546,9 +547,7 @@ class ApplyBatchImpl:
|
|
546
547
|
else:
|
547
548
|
sql_schema.DefaultClause(
|
548
549
|
server_default # type: ignore[arg-type]
|
549
|
-
)._set_parent(
|
550
|
-
existing
|
551
|
-
)
|
550
|
+
)._set_parent(existing)
|
552
551
|
if autoincrement is not None:
|
553
552
|
existing.autoincrement = bool(autoincrement)
|
554
553
|
|