]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add TextClause to alter_column's server_default fields.
authorDanCardin <ddcardin@gmail.com>
Tue, 4 Mar 2025 21:07:59 +0000 (16:07 -0500)
committerFederico Caselli <cfederico87@gmail.com>
Wed, 5 Mar 2025 19:32:37 +0000 (20:32 +0100)
Given sqlalchemy models with server_defaults, alembic may autogenerate
`existing_server_default=sa.text("...")`, which fails typechecking on
the resultant migration because `TextClause` is not currently a valid
annotated type.

Closes: #1577
Pull-request: https://github.com/sqlalchemy/alembic/pull/1577
Pull-request-sha: e21d07e55847f1e78e53f4f04bc2e458945f83fe

Change-Id: I583748e16f3fccb4d58d8c4aa0e33c00b029523c

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

index d86bef4680ddc9bfe01ff586b5d9d7b8a8d0b184..13a5852f6b1310c1e4a6ab6f9eb421456bb545f6 100644 (file)
@@ -146,12 +146,12 @@ def alter_column(
     *,
     nullable: Optional[bool] = None,
     comment: Union[str, Literal[False], None] = False,
-    server_default: Any = False,
+    server_default: Union[str, bool, Identity, Computed, TextClause] = False,
     new_column_name: Optional[str] = None,
     type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
     existing_type: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
     existing_server_default: Union[
-        str, bool, Identity, Computed, None
+        str, bool, Identity, Computed, TextClause, None
     ] = False,
     existing_nullable: Optional[bool] = None,
     existing_comment: Optional[str] = None,
index 456d1c75bb39eca98417bd491c5cdd50384ef440..139931147eba583ab5626195a2011763b601f466 100644 (file)
@@ -705,14 +705,16 @@ class Operations(AbstractOperations):
             *,
             nullable: Optional[bool] = None,
             comment: Union[str, Literal[False], None] = False,
-            server_default: Any = False,
+            server_default: Union[
+                str, bool, Identity, Computed, TextClause
+            ] = False,
             new_column_name: Optional[str] = None,
             type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
             existing_type: Union[
                 TypeEngine[Any], Type[TypeEngine[Any]], None
             ] = None,
             existing_server_default: Union[
-                str, bool, Identity, Computed, None
+                str, bool, Identity, Computed, TextClause, None
             ] = False,
             existing_nullable: Optional[bool] = None,
             existing_comment: Optional[str] = None,
index bb4d825b1460adaf66e3bfb711e511b1f3f3877e..eebc23235b4c09ffa4dc8fda3dd8697c5a45a573 100644 (file)
@@ -1840,14 +1840,16 @@ class AlterColumnOp(AlterTableOp):
         *,
         nullable: Optional[bool] = None,
         comment: Optional[Union[str, Literal[False]]] = False,
-        server_default: Any = False,
+        server_default: Union[
+            str, bool, Identity, Computed, TextClause
+        ] = False,
         new_column_name: Optional[str] = None,
         type_: Optional[Union[TypeEngine[Any], Type[TypeEngine[Any]]]] = None,
         existing_type: Optional[
             Union[TypeEngine[Any], Type[TypeEngine[Any]]]
         ] = None,
-        existing_server_default: Optional[
-            Union[str, bool, Identity, Computed]
+        existing_server_default: Union[
+            str, bool, Identity, Computed, TextClause, None
         ] = False,
         existing_nullable: Optional[bool] = None,
         existing_comment: Optional[str] = None,