Skip to content

Commit

Permalink
chore: add migration to enforce non-nullable 'id' in 'vertex_build' t…
Browse files Browse the repository at this point in the history
…able (#3655)

Add Alembic migration to enforce non-nullable 'id' in 'vertex_build' table
  • Loading branch information
ogabrielluiz authored Sep 2, 2024
1 parent f2abb94 commit b2f5a43
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""nullable in vertex build
Revision ID: e5a65ecff2cd
Revises: 4522eb831f5c
Create Date: 2024-09-02 14:55:19.707355
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op
from sqlalchemy.engine.reflection import Inspector

from langflow.utils import migration

# revision identifiers, used by Alembic.
revision: str = "e5a65ecff2cd"
down_revision: Union[str, None] = "4522eb831f5c"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
conn = op.get_bind()
# ### commands auto generated by Alembic - please adjust! ###
inspector = Inspector.from_engine(conn) # type: ignore
with op.batch_alter_table("vertex_build", schema=None) as batch_op:
if migration.column_exists(table_name="vertex_build", column_name="id", conn=conn):
columns = inspector.get_columns("vertex_build")
id_column = next((column for column in columns if column["name"] == "id"), None)
if id_column is not None and id_column["nullable"]:
batch_op.alter_column("id", existing_type=sa.VARCHAR(), nullable=False)

# ### end Alembic commands ###


def downgrade() -> None:
conn = op.get_bind()
# ### commands auto generated by Alembic - please adjust! ###
inspector = Inspector.from_engine(conn) # type: ignore
with op.batch_alter_table("vertex_build", schema=None) as batch_op:
if migration.column_exists(table_name="vertex_build", column_name="id", conn=conn):
columns = inspector.get_columns("vertex_build")
id_column = next((column for column in columns if column["name"] == "id"), None)
if id_column is not None and not id_column["nullable"]:
batch_op.alter_column("id", existing_type=sa.VARCHAR(), nullable=True)

# ### end Alembic commands ###

0 comments on commit b2f5a43

Please sign in to comment.