alembic 1.13.0__py3-none-any.whl → 1.13.2__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 +9 -7
- alembic/autogenerate/compare.py +6 -5
- alembic/autogenerate/render.py +34 -24
- alembic/autogenerate/rewriter.py +26 -13
- alembic/command.py +27 -16
- alembic/config.py +25 -19
- alembic/context.pyi +10 -5
- alembic/ddl/__init__.py +1 -1
- alembic/ddl/_autogen.py +19 -13
- alembic/ddl/base.py +17 -13
- alembic/ddl/impl.py +27 -19
- alembic/ddl/mssql.py +4 -1
- alembic/ddl/mysql.py +54 -34
- alembic/ddl/oracle.py +9 -4
- alembic/ddl/postgresql.py +18 -10
- alembic/ddl/sqlite.py +8 -6
- alembic/op.pyi +46 -8
- alembic/operations/base.py +69 -16
- alembic/operations/batch.py +7 -8
- alembic/operations/ops.py +57 -35
- alembic/operations/schemaobj.py +11 -8
- alembic/operations/toimpl.py +3 -0
- alembic/runtime/environment.py +20 -13
- alembic/runtime/migration.py +34 -18
- alembic/script/base.py +24 -24
- alembic/script/revision.py +53 -33
- alembic/script/write_hooks.py +3 -0
- alembic/templates/async/alembic.ini.mako +3 -3
- alembic/templates/generic/alembic.ini.mako +2 -2
- alembic/templates/multidb/alembic.ini.mako +2 -2
- alembic/testing/fixtures.py +20 -8
- alembic/testing/suite/test_autogen_computed.py +1 -0
- alembic/testing/suite/test_environment.py +3 -3
- alembic/util/__init__.py +31 -31
- alembic/util/compat.py +25 -8
- alembic/util/langhelpers.py +78 -36
- alembic/util/messaging.py +15 -6
- alembic/util/pyfiles.py +7 -3
- alembic/util/sqla_compat.py +41 -14
- {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/LICENSE +2 -2
- {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/METADATA +1 -1
- alembic-1.13.2.dist-info/RECORD +83 -0
- {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/WHEEL +1 -1
- alembic-1.13.0.dist-info/RECORD +0 -83
- {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/entry_points.txt +0 -0
- {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/top_level.txt +0 -0
alembic/__init__.py
CHANGED
alembic/autogenerate/__init__.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
from .api import _render_migration_diffs
|
2
|
-
from .api import compare_metadata
|
3
|
-
from .api import produce_migrations
|
4
|
-
from .api import render_python_code
|
5
|
-
from .api import RevisionContext
|
6
|
-
from .compare import _produce_net_changes
|
7
|
-
from .compare import comparators
|
8
|
-
from .render import render_op_text
|
9
|
-
from .render import renderers
|
10
|
-
from .rewriter import Rewriter
|
1
|
+
from .api import _render_migration_diffs as _render_migration_diffs
|
2
|
+
from .api import compare_metadata as compare_metadata
|
3
|
+
from .api import produce_migrations as produce_migrations
|
4
|
+
from .api import render_python_code as render_python_code
|
5
|
+
from .api import RevisionContext as RevisionContext
|
6
|
+
from .compare import _produce_net_changes as _produce_net_changes
|
7
|
+
from .compare import comparators as comparators
|
8
|
+
from .render import render_op_text as render_op_text
|
9
|
+
from .render import renderers as renderers
|
10
|
+
from .rewriter import Rewriter as Rewriter
|
alembic/autogenerate/api.py
CHANGED
@@ -28,6 +28,7 @@ if TYPE_CHECKING:
|
|
28
28
|
from sqlalchemy.engine import Inspector
|
29
29
|
from sqlalchemy.sql.schema import MetaData
|
30
30
|
from sqlalchemy.sql.schema import SchemaItem
|
31
|
+
from sqlalchemy.sql.schema import Table
|
31
32
|
|
32
33
|
from ..config import Config
|
33
34
|
from ..operations.ops import DowngradeOps
|
@@ -165,6 +166,7 @@ def compare_metadata(context: MigrationContext, metadata: MetaData) -> Any:
|
|
165
166
|
"""
|
166
167
|
|
167
168
|
migration_script = produce_migrations(context, metadata)
|
169
|
+
assert migration_script.upgrade_ops is not None
|
168
170
|
return migration_script.upgrade_ops.as_diffs()
|
169
171
|
|
170
172
|
|
@@ -331,7 +333,7 @@ class AutogenContext:
|
|
331
333
|
self,
|
332
334
|
migration_context: MigrationContext,
|
333
335
|
metadata: Optional[MetaData] = None,
|
334
|
-
opts: Optional[
|
336
|
+
opts: Optional[Dict[str, Any]] = None,
|
335
337
|
autogenerate: bool = True,
|
336
338
|
) -> None:
|
337
339
|
if (
|
@@ -465,7 +467,7 @@ class AutogenContext:
|
|
465
467
|
run_filters = run_object_filters
|
466
468
|
|
467
469
|
@util.memoized_property
|
468
|
-
def sorted_tables(self):
|
470
|
+
def sorted_tables(self) -> List[Table]:
|
469
471
|
"""Return an aggregate of the :attr:`.MetaData.sorted_tables`
|
470
472
|
collection(s).
|
471
473
|
|
@@ -481,7 +483,7 @@ class AutogenContext:
|
|
481
483
|
return result
|
482
484
|
|
483
485
|
@util.memoized_property
|
484
|
-
def table_key_to_table(self):
|
486
|
+
def table_key_to_table(self) -> Dict[str, Table]:
|
485
487
|
"""Return an aggregate of the :attr:`.MetaData.tables` dictionaries.
|
486
488
|
|
487
489
|
The :attr:`.MetaData.tables` collection is a dictionary of table key
|
@@ -492,7 +494,7 @@ class AutogenContext:
|
|
492
494
|
objects contain the same table key, an exception is raised.
|
493
495
|
|
494
496
|
"""
|
495
|
-
result = {}
|
497
|
+
result: Dict[str, Table] = {}
|
496
498
|
for m in util.to_list(self.metadata):
|
497
499
|
intersect = set(result).intersection(set(m.tables))
|
498
500
|
if intersect:
|
@@ -594,9 +596,9 @@ class RevisionContext:
|
|
594
596
|
migration_script = self.generated_revisions[-1]
|
595
597
|
if not getattr(migration_script, "_needs_render", False):
|
596
598
|
migration_script.upgrade_ops_list[-1].upgrade_token = upgrade_token
|
597
|
-
migration_script.downgrade_ops_list[
|
598
|
-
|
599
|
-
|
599
|
+
migration_script.downgrade_ops_list[-1].downgrade_token = (
|
600
|
+
downgrade_token
|
601
|
+
)
|
600
602
|
migration_script._needs_render = True
|
601
603
|
else:
|
602
604
|
migration_script._upgrade_ops.append(
|
alembic/autogenerate/compare.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 contextlib
|
@@ -577,9 +580,7 @@ def _compare_indexes_and_uniques(
|
|
577
580
|
# 5. index things by name, for those objects that have names
|
578
581
|
metadata_names = {
|
579
582
|
cast(str, c.md_name_to_sql_name(autogen_context)): c
|
580
|
-
for c in metadata_unique_constraints_sig.union(
|
581
|
-
metadata_indexes_sig # type:ignore[arg-type]
|
582
|
-
)
|
583
|
+
for c in metadata_unique_constraints_sig.union(metadata_indexes_sig)
|
583
584
|
if c.is_named
|
584
585
|
}
|
585
586
|
|
@@ -982,7 +983,7 @@ def _normalize_computed_default(sqltext: str) -> str:
|
|
982
983
|
|
983
984
|
"""
|
984
985
|
|
985
|
-
return re.sub(r"[ \(\)'\"`\[\]]", "", sqltext).lower()
|
986
|
+
return re.sub(r"[ \(\)'\"`\[\]\t\r\n]", "", sqltext).lower()
|
986
987
|
|
987
988
|
|
988
989
|
def _compare_computed_default(
|
@@ -1240,7 +1241,7 @@ def _compare_foreign_keys(
|
|
1240
1241
|
obj.const, obj.name, "foreign_key_constraint", False, compare_to
|
1241
1242
|
):
|
1242
1243
|
modify_table_ops.ops.append(
|
1243
|
-
ops.CreateForeignKeyOp.from_constraint(const.const)
|
1244
|
+
ops.CreateForeignKeyOp.from_constraint(const.const) # type: ignore[has-type] # noqa: E501
|
1244
1245
|
)
|
1245
1246
|
|
1246
1247
|
log.info(
|
alembic/autogenerate/render.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 io import StringIO
|
@@ -184,9 +187,11 @@ def _render_create_table_comment(
|
|
184
187
|
prefix=_alembic_autogenerate_prefix(autogen_context),
|
185
188
|
tname=op.table_name,
|
186
189
|
comment="%r" % op.comment if op.comment is not None else None,
|
187
|
-
existing=
|
188
|
-
|
189
|
-
|
190
|
+
existing=(
|
191
|
+
"%r" % op.existing_comment
|
192
|
+
if op.existing_comment is not None
|
193
|
+
else None
|
194
|
+
),
|
190
195
|
schema="'%s'" % op.schema if op.schema is not None else None,
|
191
196
|
indent=" ",
|
192
197
|
)
|
@@ -213,9 +218,11 @@ def _render_drop_table_comment(
|
|
213
218
|
return templ.format(
|
214
219
|
prefix=_alembic_autogenerate_prefix(autogen_context),
|
215
220
|
tname=op.table_name,
|
216
|
-
existing=
|
217
|
-
|
218
|
-
|
221
|
+
existing=(
|
222
|
+
"%r" % op.existing_comment
|
223
|
+
if op.existing_comment is not None
|
224
|
+
else None
|
225
|
+
),
|
219
226
|
schema="'%s'" % op.schema if op.schema is not None else None,
|
220
227
|
indent=" ",
|
221
228
|
)
|
@@ -325,9 +332,11 @@ def _add_index(autogen_context: AutogenContext, op: ops.CreateIndexOp) -> str:
|
|
325
332
|
_get_index_rendered_expressions(index, autogen_context)
|
326
333
|
),
|
327
334
|
"unique": index.unique or False,
|
328
|
-
"schema": (
|
329
|
-
|
330
|
-
|
335
|
+
"schema": (
|
336
|
+
(", schema=%r" % _ident(index.table.schema))
|
337
|
+
if index.table.schema
|
338
|
+
else ""
|
339
|
+
),
|
331
340
|
"kwargs": ", " + ", ".join(opts) if opts else "",
|
332
341
|
}
|
333
342
|
return text
|
@@ -589,9 +598,11 @@ def _get_index_rendered_expressions(
|
|
589
598
|
idx: Index, autogen_context: AutogenContext
|
590
599
|
) -> List[str]:
|
591
600
|
return [
|
592
|
-
|
593
|
-
|
594
|
-
|
601
|
+
(
|
602
|
+
repr(_ident(getattr(exp, "name", None)))
|
603
|
+
if isinstance(exp, sa_schema.Column)
|
604
|
+
else _render_potential_expr(exp, autogen_context, is_index=True)
|
605
|
+
)
|
595
606
|
for exp in idx.expressions
|
596
607
|
]
|
597
608
|
|
@@ -849,7 +860,7 @@ def _render_Variant_type(
|
|
849
860
|
) -> str:
|
850
861
|
base_type, variant_mapping = sqla_compat._get_variant_mapping(type_)
|
851
862
|
base = _repr_type(base_type, autogen_context, _skip_variants=True)
|
852
|
-
assert base is not None and base is not False
|
863
|
+
assert base is not None and base is not False # type: ignore[comparison-overlap] # noqa:E501
|
853
864
|
for dialect in sorted(variant_mapping):
|
854
865
|
typ = variant_mapping[dialect]
|
855
866
|
base += ".with_variant(%s, %r)" % (
|
@@ -946,7 +957,7 @@ def _fk_colspec(
|
|
946
957
|
won't fail if the remote table can't be resolved.
|
947
958
|
|
948
959
|
"""
|
949
|
-
colspec = fk._get_colspec()
|
960
|
+
colspec = fk._get_colspec()
|
950
961
|
tokens = colspec.split(".")
|
951
962
|
tname, colname = tokens[-2:]
|
952
963
|
|
@@ -1016,8 +1027,7 @@ def _render_foreign_key(
|
|
1016
1027
|
% {
|
1017
1028
|
"prefix": _sqlalchemy_autogenerate_prefix(autogen_context),
|
1018
1029
|
"cols": ", ".join(
|
1019
|
-
|
1020
|
-
for f in constraint.elements
|
1030
|
+
repr(_ident(f.parent.name)) for f in constraint.elements
|
1021
1031
|
),
|
1022
1032
|
"refcols": ", ".join(
|
1023
1033
|
repr(_fk_colspec(f, apply_metadata_schema, namespace_metadata))
|
@@ -1058,12 +1068,10 @@ def _render_check_constraint(
|
|
1058
1068
|
# ideally SQLAlchemy would give us more of a first class
|
1059
1069
|
# way to detect this.
|
1060
1070
|
if (
|
1061
|
-
constraint._create_rule
|
1062
|
-
and hasattr(
|
1063
|
-
constraint._create_rule, "target" # type:ignore[attr-defined]
|
1064
|
-
)
|
1071
|
+
constraint._create_rule
|
1072
|
+
and hasattr(constraint._create_rule, "target")
|
1065
1073
|
and isinstance(
|
1066
|
-
constraint._create_rule.target,
|
1074
|
+
constraint._create_rule.target,
|
1067
1075
|
sqltypes.TypeEngine,
|
1068
1076
|
)
|
1069
1077
|
):
|
@@ -1075,9 +1083,11 @@ def _render_check_constraint(
|
|
1075
1083
|
)
|
1076
1084
|
return "%(prefix)sCheckConstraint(%(sqltext)s%(opts)s)" % {
|
1077
1085
|
"prefix": _sqlalchemy_autogenerate_prefix(autogen_context),
|
1078
|
-
"opts":
|
1079
|
-
|
1080
|
-
|
1086
|
+
"opts": (
|
1087
|
+
", " + (", ".join("%s=%s" % (k, v) for k, v in opts))
|
1088
|
+
if opts
|
1089
|
+
else ""
|
1090
|
+
),
|
1081
1091
|
"sqltext": _render_potential_expr(
|
1082
1092
|
constraint.sqltext, autogen_context, wrap_in_text=False
|
1083
1093
|
),
|
alembic/autogenerate/rewriter.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Any
|
|
4
4
|
from typing import Callable
|
5
5
|
from typing import Iterator
|
6
6
|
from typing import List
|
7
|
-
from typing import
|
7
|
+
from typing import Tuple
|
8
8
|
from typing import Type
|
9
9
|
from typing import TYPE_CHECKING
|
10
10
|
from typing import Union
|
@@ -16,12 +16,18 @@ if TYPE_CHECKING:
|
|
16
16
|
from ..operations.ops import AddColumnOp
|
17
17
|
from ..operations.ops import AlterColumnOp
|
18
18
|
from ..operations.ops import CreateTableOp
|
19
|
+
from ..operations.ops import DowngradeOps
|
19
20
|
from ..operations.ops import MigrateOperation
|
20
21
|
from ..operations.ops import MigrationScript
|
21
22
|
from ..operations.ops import ModifyTableOps
|
22
23
|
from ..operations.ops import OpContainer
|
23
|
-
from ..
|
24
|
+
from ..operations.ops import UpgradeOps
|
24
25
|
from ..runtime.migration import MigrationContext
|
26
|
+
from ..script.revision import _GetRevArg
|
27
|
+
|
28
|
+
ProcessRevisionDirectiveFn = Callable[
|
29
|
+
["MigrationContext", "_GetRevArg", List["MigrationScript"]], None
|
30
|
+
]
|
25
31
|
|
26
32
|
|
27
33
|
class Rewriter:
|
@@ -52,15 +58,21 @@ class Rewriter:
|
|
52
58
|
|
53
59
|
_traverse = util.Dispatcher()
|
54
60
|
|
55
|
-
_chained:
|
61
|
+
_chained: Tuple[Union[ProcessRevisionDirectiveFn, Rewriter], ...] = ()
|
56
62
|
|
57
63
|
def __init__(self) -> None:
|
58
64
|
self.dispatch = util.Dispatcher()
|
59
65
|
|
60
|
-
def chain(
|
66
|
+
def chain(
|
67
|
+
self,
|
68
|
+
other: Union[
|
69
|
+
ProcessRevisionDirectiveFn,
|
70
|
+
Rewriter,
|
71
|
+
],
|
72
|
+
) -> Rewriter:
|
61
73
|
"""Produce a "chain" of this :class:`.Rewriter` to another.
|
62
74
|
|
63
|
-
This allows two rewriters to operate serially on a stream,
|
75
|
+
This allows two or more rewriters to operate serially on a stream,
|
64
76
|
e.g.::
|
65
77
|
|
66
78
|
writer1 = autogenerate.Rewriter()
|
@@ -89,7 +101,7 @@ class Rewriter:
|
|
89
101
|
"""
|
90
102
|
wr = self.__class__.__new__(self.__class__)
|
91
103
|
wr.__dict__.update(self.__dict__)
|
92
|
-
wr._chained
|
104
|
+
wr._chained += (other,)
|
93
105
|
return wr
|
94
106
|
|
95
107
|
def rewrites(
|
@@ -101,7 +113,7 @@ class Rewriter:
|
|
101
113
|
Type[CreateTableOp],
|
102
114
|
Type[ModifyTableOps],
|
103
115
|
],
|
104
|
-
) -> Callable:
|
116
|
+
) -> Callable[..., Any]:
|
105
117
|
"""Register a function as rewriter for a given type.
|
106
118
|
|
107
119
|
The function should receive three arguments, which are
|
@@ -146,8 +158,8 @@ class Rewriter:
|
|
146
158
|
directives: List[MigrationScript],
|
147
159
|
) -> None:
|
148
160
|
self.process_revision_directives(context, revision, directives)
|
149
|
-
|
150
|
-
|
161
|
+
for process_revision_directives in self._chained:
|
162
|
+
process_revision_directives(context, revision, directives)
|
151
163
|
|
152
164
|
@_traverse.dispatch_for(ops.MigrationScript)
|
153
165
|
def _traverse_script(
|
@@ -156,7 +168,7 @@ class Rewriter:
|
|
156
168
|
revision: _GetRevArg,
|
157
169
|
directive: MigrationScript,
|
158
170
|
) -> None:
|
159
|
-
upgrade_ops_list = []
|
171
|
+
upgrade_ops_list: List[UpgradeOps] = []
|
160
172
|
for upgrade_ops in directive.upgrade_ops_list:
|
161
173
|
ret = self._traverse_for(context, revision, upgrade_ops)
|
162
174
|
if len(ret) != 1:
|
@@ -164,9 +176,10 @@ class Rewriter:
|
|
164
176
|
"Can only return single object for UpgradeOps traverse"
|
165
177
|
)
|
166
178
|
upgrade_ops_list.append(ret[0])
|
167
|
-
directive.upgrade_ops = upgrade_ops_list
|
168
179
|
|
169
|
-
|
180
|
+
directive.upgrade_ops = upgrade_ops_list # type: ignore
|
181
|
+
|
182
|
+
downgrade_ops_list: List[DowngradeOps] = []
|
170
183
|
for downgrade_ops in directive.downgrade_ops_list:
|
171
184
|
ret = self._traverse_for(context, revision, downgrade_ops)
|
172
185
|
if len(ret) != 1:
|
@@ -174,7 +187,7 @@ class Rewriter:
|
|
174
187
|
"Can only return single object for DowngradeOps traverse"
|
175
188
|
)
|
176
189
|
downgrade_ops_list.append(ret[0])
|
177
|
-
directive.downgrade_ops = downgrade_ops_list
|
190
|
+
directive.downgrade_ops = downgrade_ops_list # type: ignore
|
178
191
|
|
179
192
|
@_traverse.dispatch_for(ops.OpContainer)
|
180
193
|
def _traverse_op_container(
|
alembic/command.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# mypy: allow-untyped-defs, allow-untyped-calls
|
2
|
+
|
1
3
|
from __future__ import annotations
|
2
4
|
|
3
5
|
import os
|
@@ -18,7 +20,7 @@ if TYPE_CHECKING:
|
|
18
20
|
from .runtime.environment import ProcessRevisionDirectiveFn
|
19
21
|
|
20
22
|
|
21
|
-
def list_templates(config: Config):
|
23
|
+
def list_templates(config: Config) -> None:
|
22
24
|
"""List available templates.
|
23
25
|
|
24
26
|
:param config: a :class:`.Config` object.
|
@@ -47,7 +49,7 @@ def init(
|
|
47
49
|
|
48
50
|
:param config: a :class:`.Config` object.
|
49
51
|
|
50
|
-
:param directory: string path of the target directory
|
52
|
+
:param directory: string path of the target directory.
|
51
53
|
|
52
54
|
:param template: string name of the migration environment template to
|
53
55
|
use.
|
@@ -172,7 +174,7 @@ def revision(
|
|
172
174
|
will be applied to the structure generated by the revision process
|
173
175
|
where it can be altered programmatically. Note that unlike all
|
174
176
|
the other parameters, this option is only available via programmatic
|
175
|
-
use of :func:`.command.revision
|
177
|
+
use of :func:`.command.revision`.
|
176
178
|
|
177
179
|
"""
|
178
180
|
|
@@ -313,9 +315,11 @@ def merge(
|
|
313
315
|
|
314
316
|
:param config: a :class:`.Config` instance
|
315
317
|
|
316
|
-
:param
|
318
|
+
:param revisions: The revisions to merge.
|
319
|
+
|
320
|
+
:param message: string message to apply to the revision.
|
317
321
|
|
318
|
-
:param branch_label: string label name to apply to the new revision
|
322
|
+
:param branch_label: string label name to apply to the new revision.
|
319
323
|
|
320
324
|
:param rev_id: hardcoded revision identifier instead of generating a new
|
321
325
|
one.
|
@@ -368,9 +372,10 @@ def upgrade(
|
|
368
372
|
|
369
373
|
:param config: a :class:`.Config` instance.
|
370
374
|
|
371
|
-
:param revision: string revision target or range for --sql mode
|
375
|
+
:param revision: string revision target or range for --sql mode. May be
|
376
|
+
``"heads"`` to target the most recent revision(s).
|
372
377
|
|
373
|
-
:param sql: if True, use ``--sql`` mode
|
378
|
+
:param sql: if True, use ``--sql`` mode.
|
374
379
|
|
375
380
|
:param tag: an arbitrary "tag" that can be intercepted by custom
|
376
381
|
``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument`
|
@@ -411,9 +416,10 @@ def downgrade(
|
|
411
416
|
|
412
417
|
:param config: a :class:`.Config` instance.
|
413
418
|
|
414
|
-
:param revision: string revision target or range for --sql mode
|
419
|
+
:param revision: string revision target or range for --sql mode. May
|
420
|
+
be ``"base"`` to target the first revision.
|
415
421
|
|
416
|
-
:param sql: if True, use ``--sql`` mode
|
422
|
+
:param sql: if True, use ``--sql`` mode.
|
417
423
|
|
418
424
|
:param tag: an arbitrary "tag" that can be intercepted by custom
|
419
425
|
``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument`
|
@@ -447,12 +453,13 @@ def downgrade(
|
|
447
453
|
script.run_env()
|
448
454
|
|
449
455
|
|
450
|
-
def show(config, rev):
|
456
|
+
def show(config: Config, rev: str) -> None:
|
451
457
|
"""Show the revision(s) denoted by the given symbol.
|
452
458
|
|
453
459
|
:param config: a :class:`.Config` instance.
|
454
460
|
|
455
|
-
:param
|
461
|
+
:param rev: string revision target. May be ``"current"`` to show the
|
462
|
+
revision(s) currently applied in the database.
|
456
463
|
|
457
464
|
"""
|
458
465
|
|
@@ -482,7 +489,7 @@ def history(
|
|
482
489
|
|
483
490
|
:param config: a :class:`.Config` instance.
|
484
491
|
|
485
|
-
:param rev_range: string revision range
|
492
|
+
:param rev_range: string revision range.
|
486
493
|
|
487
494
|
:param verbose: output in verbose mode.
|
488
495
|
|
@@ -541,7 +548,9 @@ def history(
|
|
541
548
|
_display_history(config, script, base, head)
|
542
549
|
|
543
550
|
|
544
|
-
def heads(
|
551
|
+
def heads(
|
552
|
+
config: Config, verbose: bool = False, resolve_dependencies: bool = False
|
553
|
+
) -> None:
|
545
554
|
"""Show current available heads in the script directory.
|
546
555
|
|
547
556
|
:param config: a :class:`.Config` instance.
|
@@ -566,7 +575,7 @@ def heads(config, verbose=False, resolve_dependencies=False):
|
|
566
575
|
)
|
567
576
|
|
568
577
|
|
569
|
-
def branches(config, verbose=False):
|
578
|
+
def branches(config: Config, verbose: bool = False) -> None:
|
570
579
|
"""Show current branch points.
|
571
580
|
|
572
581
|
:param config: a :class:`.Config` instance.
|
@@ -636,7 +645,9 @@ def stamp(
|
|
636
645
|
:param config: a :class:`.Config` instance.
|
637
646
|
|
638
647
|
:param revision: target revision or list of revisions. May be a list
|
639
|
-
to indicate stamping of multiple branch heads
|
648
|
+
to indicate stamping of multiple branch heads; may be ``"base"``
|
649
|
+
to remove all revisions from the table or ``"heads"`` to stamp the
|
650
|
+
most recent revision(s).
|
640
651
|
|
641
652
|
.. note:: this parameter is called "revisions" in the command line
|
642
653
|
interface.
|
@@ -726,7 +737,7 @@ def ensure_version(config: Config, sql: bool = False) -> None:
|
|
726
737
|
|
727
738
|
:param config: a :class:`.Config` instance.
|
728
739
|
|
729
|
-
:param sql: use ``--sql`` mode
|
740
|
+
:param sql: use ``--sql`` mode.
|
730
741
|
|
731
742
|
.. versionadded:: 1.7.6
|
732
743
|
|
alembic/config.py
CHANGED
@@ -12,6 +12,7 @@ from typing import Dict
|
|
12
12
|
from typing import Mapping
|
13
13
|
from typing import Optional
|
14
14
|
from typing import overload
|
15
|
+
from typing import Sequence
|
15
16
|
from typing import TextIO
|
16
17
|
from typing import Union
|
17
18
|
|
@@ -104,7 +105,7 @@ class Config:
|
|
104
105
|
stdout: TextIO = sys.stdout,
|
105
106
|
cmd_opts: Optional[Namespace] = None,
|
106
107
|
config_args: Mapping[str, Any] = util.immutabledict(),
|
107
|
-
attributes: Optional[
|
108
|
+
attributes: Optional[Dict[str, Any]] = None,
|
108
109
|
) -> None:
|
109
110
|
"""Construct a new :class:`.Config`"""
|
110
111
|
self.config_file_name = file_
|
@@ -140,7 +141,7 @@ class Config:
|
|
140
141
|
"""
|
141
142
|
|
142
143
|
@util.memoized_property
|
143
|
-
def attributes(self):
|
144
|
+
def attributes(self) -> Dict[str, Any]:
|
144
145
|
"""A Python dictionary for storage of additional state.
|
145
146
|
|
146
147
|
|
@@ -159,7 +160,7 @@ class Config:
|
|
159
160
|
"""
|
160
161
|
return {}
|
161
162
|
|
162
|
-
def print_stdout(self, text: str, *arg) -> None:
|
163
|
+
def print_stdout(self, text: str, *arg: Any) -> None:
|
163
164
|
"""Render a message to standard out.
|
164
165
|
|
165
166
|
When :meth:`.Config.print_stdout` is called with additional args
|
@@ -183,7 +184,7 @@ class Config:
|
|
183
184
|
util.write_outstream(self.stdout, output, "\n", **self.messaging_opts)
|
184
185
|
|
185
186
|
@util.memoized_property
|
186
|
-
def file_config(self):
|
187
|
+
def file_config(self) -> ConfigParser:
|
187
188
|
"""Return the underlying ``ConfigParser`` object.
|
188
189
|
|
189
190
|
Direct access to the .ini file is available here,
|
@@ -220,8 +221,7 @@ class Config:
|
|
220
221
|
@overload
|
221
222
|
def get_section(
|
222
223
|
self, name: str, default: None = ...
|
223
|
-
) -> Optional[Dict[str, str]]:
|
224
|
-
...
|
224
|
+
) -> Optional[Dict[str, str]]: ...
|
225
225
|
|
226
226
|
# "default" here could also be a TypeVar
|
227
227
|
# _MT = TypeVar("_MT", bound=Mapping[str, str]),
|
@@ -229,14 +229,12 @@ class Config:
|
|
229
229
|
@overload
|
230
230
|
def get_section(
|
231
231
|
self, name: str, default: Dict[str, str]
|
232
|
-
) -> Dict[str, str]:
|
233
|
-
...
|
232
|
+
) -> Dict[str, str]: ...
|
234
233
|
|
235
234
|
@overload
|
236
235
|
def get_section(
|
237
236
|
self, name: str, default: Mapping[str, str]
|
238
|
-
) -> Union[Dict[str, str], Mapping[str, str]]:
|
239
|
-
...
|
237
|
+
) -> Union[Dict[str, str], Mapping[str, str]]: ...
|
240
238
|
|
241
239
|
def get_section(
|
242
240
|
self, name: str, default: Optional[Mapping[str, str]] = None
|
@@ -312,16 +310,16 @@ class Config:
|
|
312
310
|
return default
|
313
311
|
|
314
312
|
@overload
|
315
|
-
def get_main_option(self, name: str, default: str) -> str:
|
316
|
-
...
|
313
|
+
def get_main_option(self, name: str, default: str) -> str: ...
|
317
314
|
|
318
315
|
@overload
|
319
316
|
def get_main_option(
|
320
317
|
self, name: str, default: Optional[str] = None
|
321
|
-
) -> Optional[str]:
|
322
|
-
...
|
318
|
+
) -> Optional[str]: ...
|
323
319
|
|
324
|
-
def get_main_option(
|
320
|
+
def get_main_option(
|
321
|
+
self, name: str, default: Optional[str] = None
|
322
|
+
) -> Optional[str]:
|
325
323
|
"""Return an option from the 'main' section of the .ini file.
|
326
324
|
|
327
325
|
This defaults to being a key from the ``[alembic]``
|
@@ -351,7 +349,9 @@ class CommandLine:
|
|
351
349
|
self._generate_args(prog)
|
352
350
|
|
353
351
|
def _generate_args(self, prog: Optional[str]) -> None:
|
354
|
-
def add_options(
|
352
|
+
def add_options(
|
353
|
+
fn: Any, parser: Any, positional: Any, kwargs: Any
|
354
|
+
) -> None:
|
355
355
|
kwargs_opts = {
|
356
356
|
"template": (
|
357
357
|
"-t",
|
@@ -554,7 +554,9 @@ class CommandLine:
|
|
554
554
|
)
|
555
555
|
subparsers = parser.add_subparsers()
|
556
556
|
|
557
|
-
positional_translations = {
|
557
|
+
positional_translations: Dict[Any, Any] = {
|
558
|
+
command.stamp: {"revision": "revisions"}
|
559
|
+
}
|
558
560
|
|
559
561
|
for fn in [getattr(command, n) for n in dir(command)]:
|
560
562
|
if (
|
@@ -609,7 +611,7 @@ class CommandLine:
|
|
609
611
|
else:
|
610
612
|
util.err(str(e), **config.messaging_opts)
|
611
613
|
|
612
|
-
def main(self, argv=None):
|
614
|
+
def main(self, argv: Optional[Sequence[str]] = None) -> None:
|
613
615
|
options = self.parser.parse_args(argv)
|
614
616
|
if not hasattr(options, "cmd"):
|
615
617
|
# see http://bugs.python.org/issue9253, argparse
|
@@ -624,7 +626,11 @@ class CommandLine:
|
|
624
626
|
self.run_cmd(cfg, options)
|
625
627
|
|
626
628
|
|
627
|
-
def main(
|
629
|
+
def main(
|
630
|
+
argv: Optional[Sequence[str]] = None,
|
631
|
+
prog: Optional[str] = None,
|
632
|
+
**kwargs: Any,
|
633
|
+
) -> None:
|
628
634
|
"""The console runner function for Alembic."""
|
629
635
|
|
630
636
|
CommandLine(prog=prog).main(argv=argv)
|
alembic/context.pyi
CHANGED
@@ -160,8 +160,8 @@ def configure(
|
|
160
160
|
MigrationContext,
|
161
161
|
Column[Any],
|
162
162
|
Column[Any],
|
163
|
-
TypeEngine,
|
164
|
-
TypeEngine,
|
163
|
+
TypeEngine[Any],
|
164
|
+
TypeEngine[Any],
|
165
165
|
],
|
166
166
|
Optional[bool],
|
167
167
|
],
|
@@ -636,7 +636,8 @@ def configure(
|
|
636
636
|
"""
|
637
637
|
|
638
638
|
def execute(
|
639
|
-
sql: Union[Executable, str],
|
639
|
+
sql: Union[Executable, str],
|
640
|
+
execution_options: Optional[Dict[str, Any]] = None,
|
640
641
|
) -> None:
|
641
642
|
"""Execute the given SQL using the current change context.
|
642
643
|
|
@@ -759,7 +760,11 @@ def get_x_argument(
|
|
759
760
|
The return value is a list, returned directly from the ``argparse``
|
760
761
|
structure. If ``as_dictionary=True`` is passed, the ``x`` arguments
|
761
762
|
are parsed using ``key=value`` format into a dictionary that is
|
762
|
-
then returned.
|
763
|
+
then returned. If there is no ``=`` in the argument, value is an empty
|
764
|
+
string.
|
765
|
+
|
766
|
+
.. versionchanged:: 1.13.1 Support ``as_dictionary=True`` when
|
767
|
+
arguments are passed without the ``=`` symbol.
|
763
768
|
|
764
769
|
For example, to support passing a database URL on the command line,
|
765
770
|
the standard ``env.py`` script can be modified like this::
|
@@ -801,7 +806,7 @@ def is_offline_mode() -> bool:
|
|
801
806
|
|
802
807
|
"""
|
803
808
|
|
804
|
-
def is_transactional_ddl():
|
809
|
+
def is_transactional_ddl() -> bool:
|
805
810
|
"""Return True if the context is configured to expect a
|
806
811
|
transactional DDL capable backend.
|
807
812
|
|
alembic/ddl/__init__.py
CHANGED