Update nullable attribute for created_at field in variable table
This commit is contained in:
parent
9c188db486
commit
17f04d8b78
1 changed files with 23 additions and 17 deletions
|
|
@ -26,11 +26,13 @@ def upgrade() -> None:
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
if "variable" not in table_names:
|
if "variable" not in table_names:
|
||||||
return
|
return
|
||||||
|
columns = [column for column in inspector.get_columns("variable")]
|
||||||
column_names = [column["name"] 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:
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
if "created_at" in column_names:
|
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 False:
|
||||||
batch_op.alter_column(
|
batch_op.alter_column(
|
||||||
"created_at",
|
"created_at",
|
||||||
existing_type=sa.TIMESTAMP(timezone=True),
|
existing_type=sa.TIMESTAMP(timezone=True),
|
||||||
|
|
@ -50,8 +52,12 @@ def downgrade() -> None:
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
if "variable" not in table_names:
|
if "variable" not in table_names:
|
||||||
return
|
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:
|
with op.batch_alter_table("variable", schema=None) as batch_op:
|
||||||
if "created_at" in inspector.get_columns("variable"):
|
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(
|
batch_op.alter_column(
|
||||||
"created_at",
|
"created_at",
|
||||||
existing_type=sa.TIMESTAMP(timezone=True),
|
existing_type=sa.TIMESTAMP(timezone=True),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue