From 17f04d8b78be660a05ab24c256b2a45f962b4c19 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 12 Apr 2024 12:25:43 -0300 Subject: [PATCH] Update nullable attribute for created_at field in variable table --- .../versions/e3bc869fa272_fix_nullable.py | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/backend/base/langflow/alembic/versions/e3bc869fa272_fix_nullable.py b/src/backend/base/langflow/alembic/versions/e3bc869fa272_fix_nullable.py index dbcf7fd9f..bfcd8e60b 100644 --- a/src/backend/base/langflow/alembic/versions/e3bc869fa272_fix_nullable.py +++ b/src/backend/base/langflow/alembic/versions/e3bc869fa272_fix_nullable.py @@ -26,19 +26,21 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### if "variable" not in table_names: return - - column_names = [column["name"] for column in inspector.get_columns("variable")] + columns = [column for column in inspector.get_columns("variable")] + column_names = [column["name"] for column in columns] with op.batch_alter_table("variable", schema=None) as batch_op: if "created_at" in column_names: - batch_op.alter_column( - "created_at", - existing_type=sa.TIMESTAMP(timezone=True), - nullable=True, - # existing_server_default expects str | bool | Identity | Computed | None - # sa.text("now()") is not a valid value for existing_server_default - existing_server_default=False, - ) + created_at_colunmn = next(column for column in columns if column["name"] == "created_at") + if created_at_colunmn["nullable"] is False: + batch_op.alter_column( + "created_at", + existing_type=sa.TIMESTAMP(timezone=True), + nullable=True, + # existing_server_default expects str | bool | Identity | Computed | None + # sa.text("now()") is not a valid value for existing_server_default + existing_server_default=False, + ) # ### end Alembic commands ### @@ -50,13 +52,17 @@ def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### if "variable" not in table_names: return + columns = [column for column in inspector.get_columns("variable")] + column_names = [column["name"] for column in columns] with op.batch_alter_table("variable", schema=None) as batch_op: - if "created_at" in inspector.get_columns("variable"): - batch_op.alter_column( - "created_at", - existing_type=sa.TIMESTAMP(timezone=True), - nullable=False, - existing_server_default=False, - ) + if "created_at" in column_names: + created_at_colunmn = next(column for column in columns if column["name"] == "created_at") + if created_at_colunmn["nullable"] is True: + batch_op.alter_column( + "created_at", + existing_type=sa.TIMESTAMP(timezone=True), + nullable=False, + existing_server_default=False, + ) # ### end Alembic commands ###