summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2023-05-12 21:59:15 +0200
committerFederico Caselli <cfederico87@gmail.com>2023-05-12 21:59:15 +0200
commit86d1178e7e96dfd790b5db3cab28b06904c4e22e (patch)
tree4b0cf59607d6a7ae1afd8a24c78d40a82f49b2d7
parent513aa2a673449cbcdc314b2b692bef08ce4e49d4 (diff)
downloadalembic-86d1178e7e96dfd790b5db3cab28b06904c4e22e.tar.gz
Improve commit 497c6c86b9547eed2ac297b1618300430578b86f
Follow up of I91b453c8848dc5d24d63840bfd7ce4d22dd0e693 to improve some leftover changes. Change-Id: I368b93df4d8bd6782b04042ab7872276ff00e56b
-rw-r--r--alembic/op.pyi4
-rw-r--r--alembic/operations/base.py22
-rw-r--r--alembic/operations/ops.py33
3 files changed, 51 insertions, 8 deletions
diff --git a/alembic/op.pyi b/alembic/op.pyi
index a0f1d7e..8c672fa 100644
--- a/alembic/op.pyi
+++ b/alembic/op.pyi
@@ -387,6 +387,7 @@ def batch_alter_table(
def bulk_insert(
table: Union[Table, TableClause],
rows: List[dict],
+ *,
multiinsert: bool = True,
) -> None:
"""Issue a "bulk insert" operation using the current
@@ -815,8 +816,8 @@ def create_table(table_name: str, *columns: SchemaItem, **kw: Any) -> Table:
def create_table_comment(
table_name: str,
comment: Optional[str],
- existing_comment: Optional[str] = None,
*,
+ existing_comment: Optional[str] = None,
schema: Optional[str] = None,
) -> None:
"""Emit a COMMENT ON operation to set the comment for a table.
@@ -1024,6 +1025,7 @@ def drop_table_comment(
def execute(
sqltext: Union[str, TextClause, Update],
+ *,
execution_options: Optional[dict[str, Any]] = None,
) -> None:
r"""Execute the given SQL using the current migration context.
diff --git a/alembic/operations/base.py b/alembic/operations/base.py
index 1dd7aca..39dadda 100644
--- a/alembic/operations/base.py
+++ b/alembic/operations/base.py
@@ -765,6 +765,7 @@ class Operations(AbstractOperations):
self,
table: Union[Table, TableClause],
rows: List[dict],
+ *,
multiinsert: bool = True,
) -> None:
"""Issue a "bulk insert" operation using the current
@@ -1211,8 +1212,8 @@ class Operations(AbstractOperations):
self,
table_name: str,
comment: Optional[str],
- existing_comment: Optional[str] = None,
*,
+ existing_comment: Optional[str] = None,
schema: Optional[str] = None,
) -> None:
"""Emit a COMMENT ON operation to set the comment for a table.
@@ -1433,6 +1434,7 @@ class Operations(AbstractOperations):
def execute(
self,
sqltext: Union[str, TextClause, Update],
+ *,
execution_options: Optional[dict[str, Any]] = None,
) -> None:
r"""Execute the given SQL using the current migration context.
@@ -1739,6 +1741,7 @@ class BatchOperations(AbstractOperations):
def create_table_comment(
self,
comment: Optional[str],
+ *,
existing_comment: Optional[str] = None,
) -> None:
"""Emit a COMMENT ON operation to set the comment for a table
@@ -1811,7 +1814,7 @@ class BatchOperations(AbstractOperations):
...
def drop_table_comment(
- self, existing_comment: Optional[str] = None
+ self, *, existing_comment: Optional[str] = None
) -> None:
"""Issue a "drop table comment" operation to
remove an existing comment set on a table using the current
@@ -1825,4 +1828,19 @@ class BatchOperations(AbstractOperations):
""" # noqa: E501
...
+ def execute(
+ self,
+ sqltext: Union[str, TextClause, Update],
+ *,
+ execution_options: Optional[dict[str, Any]] = None,
+ ) -> None:
+ """Execute the given SQL using the current migration context.
+
+ .. seealso::
+
+ :meth:`.Operations.execute`
+
+ """ # noqa: E501
+ ...
+
# END STUB FUNCTIONS: batch_op
diff --git a/alembic/operations/ops.py b/alembic/operations/ops.py
index 1fede52..05c01aa 100644
--- a/alembic/operations/ops.py
+++ b/alembic/operations/ops.py
@@ -174,9 +174,7 @@ class DropConstraintOp(MigrateOperation):
_reverse=AddConstraintOp.from_constraint(constraint),
)
- def to_constraint(
- self,
- ) -> Constraint:
+ def to_constraint(self) -> Constraint:
if self._reverse is not None:
constraint = self._reverse.to_constraint()
@@ -1453,8 +1451,8 @@ class CreateTableCommentOp(AlterTableOp):
operations: Operations,
table_name: str,
comment: Optional[str],
- existing_comment: Optional[str] = None,
*,
+ existing_comment: Optional[str] = None,
schema: Optional[str] = None,
) -> None:
"""Emit a COMMENT ON operation to set the comment for a table.
@@ -1490,6 +1488,7 @@ class CreateTableCommentOp(AlterTableOp):
cls,
operations: BatchOperations,
comment: Optional[str],
+ *,
existing_comment: Optional[str] = None,
) -> None:
"""Emit a COMMENT ON operation to set the comment for a table
@@ -1592,6 +1591,7 @@ class DropTableCommentOp(AlterTableOp):
def batch_drop_table_comment(
cls,
operations: BatchOperations,
+ *,
existing_comment: Optional[str] = None,
) -> None:
"""Issue a "drop table comment" operation to
@@ -2293,6 +2293,7 @@ class BulkInsertOp(MigrateOperation):
self,
table: Union[Table, TableClause],
rows: List[dict],
+ *,
multiinsert: bool = True,
) -> None:
self.table = table
@@ -2305,6 +2306,7 @@ class BulkInsertOp(MigrateOperation):
operations: Operations,
table: Union[Table, TableClause],
rows: List[dict],
+ *,
multiinsert: bool = True,
) -> None:
"""Issue a "bulk insert" operation using the current
@@ -2408,13 +2410,14 @@ class BulkInsertOp(MigrateOperation):
@Operations.register_operation("execute")
-@BatchOperations.register_operation("execute")
+@BatchOperations.register_operation("execute", "batch_execute")
class ExecuteSQLOp(MigrateOperation):
"""Represent an execute SQL operation."""
def __init__(
self,
sqltext: Union[Update, str, Insert, TextClause],
+ *,
execution_options: Optional[dict[str, Any]] = None,
) -> None:
self.sqltext = sqltext
@@ -2425,6 +2428,7 @@ class ExecuteSQLOp(MigrateOperation):
cls,
operations: Operations,
sqltext: Union[str, TextClause, Update],
+ *,
execution_options: Optional[dict[str, Any]] = None,
) -> None:
r"""Execute the given SQL using the current migration context.
@@ -2511,6 +2515,25 @@ class ExecuteSQLOp(MigrateOperation):
op = cls(sqltext, execution_options=execution_options)
return operations.invoke(op)
+ @classmethod
+ def batch_execute(
+ cls,
+ operations: Operations,
+ sqltext: Union[str, TextClause, Update],
+ *,
+ execution_options: Optional[dict[str, Any]] = None,
+ ) -> None:
+ """Execute the given SQL using the current migration context.
+
+ .. seealso::
+
+ :meth:`.Operations.execute`
+
+ """
+ return cls.execute(
+ operations, sqltext, execution_options=execution_options
+ )
+
class OpContainer(MigrateOperation):
"""Represent a sequence of operations operation."""