-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add migration to enforce non-nullable 'id' in 'vertex_build' t…
…able (#3655) Add Alembic migration to enforce non-nullable 'id' in 'vertex_build' table
- Loading branch information
1 parent
f2abb94
commit b2f5a43
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/backend/base/langflow/alembic/versions/e5a65ecff2cd_nullable_in_vertex_build.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ### |