]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Improve commit 497c6c86b9547eed2ac297b1618300430578b86f
authorFederico Caselli <cfederico87@gmail.com>
Fri, 12 May 2023 19:59:15 +0000 (21:59 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 12 May 2023 19:59:15 +0000 (21:59 +0200)
Follow up of I91b453c8848dc5d24d63840bfd7ce4d22dd0e693 to improve some
leftover changes.

Change-Id: I368b93df4d8bd6782b04042ab7872276ff00e56b

alembic/op.pyi
alembic/operations/base.py
alembic/operations/ops.py

index a0f1d7ed08607cf2743cc7244e95f1f400e03c65..8c672fa3778f935de54cc16561b175b8ed5457c9 100644 (file)
@@ -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.
index 1dd7aca1badae30b66d34fa00ac24ab6d7e3618b..39dadda86d1134f1268571eb4abce2ac8279f7a0 100644 (file)
@@ -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
index 1fede525738104b0df8c816c49b30c6d426e4393..05c01aa1deed7b56d8929f68dde23c1c56e5cc9d 100644 (file)
@@ -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."""