Update nullable attribute for created_at field in variable table

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-04-12 12:25:43 -03:00
commit 17f04d8b78

View file

@ -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 ###