From 481606ef00ab12f5f8bb3452d39ffb28a3c7011f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 20 Dec 2023 08:17:55 -0300 Subject: [PATCH] Add unique constraints to tables --- .../006b3990db50_add_unique_constraints.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/backend/langflow/alembic/versions/006b3990db50_add_unique_constraints.py b/src/backend/langflow/alembic/versions/006b3990db50_add_unique_constraints.py index cfdd10578..692dc0413 100644 --- a/src/backend/langflow/alembic/versions/006b3990db50_add_unique_constraints.py +++ b/src/backend/langflow/alembic/versions/006b3990db50_add_unique_constraints.py @@ -8,8 +8,7 @@ Create Date: 2023-12-13 18:55:52.587360 from typing import Sequence, Union from alembic import op -import sqlalchemy as sa # noqa: F401 -import sqlmodel # noqa: F401 + # revision identifiers, used by Alembic. revision: str = '006b3990db50' down_revision: Union[str, None] = '1ef9c4f3765d' @@ -19,27 +18,32 @@ depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('apikey', schema=None) as batch_op: - batch_op.create_unique_constraint('uq_apikey_id', ['id']) + try: + with op.batch_alter_table('apikey', schema=None) as batch_op: + batch_op.create_unique_constraint('uq_apikey_id', ['id']) - with op.batch_alter_table('flow', schema=None) as batch_op: - batch_op.create_unique_constraint('uq_flow_id', ['id']) + with op.batch_alter_table('flow', schema=None) as batch_op: + batch_op.create_unique_constraint('uq_flow_id', ['id']) - with op.batch_alter_table('user', schema=None) as batch_op: - batch_op.create_unique_constraint('uq_user_id', ['id']) + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.create_unique_constraint('uq_user_id', ['id']) + except Exception: + pass # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('user', schema=None) as batch_op: - batch_op.drop_constraint('uq_user_id', type_='unique') + try: + with op.batch_alter_table('user', schema=None) as batch_op: + batch_op.drop_constraint('uq_user_id', type_='unique') - with op.batch_alter_table('flow', schema=None) as batch_op: - batch_op.drop_constraint('uq_flow_id', type_='unique') - - with op.batch_alter_table('apikey', schema=None) as batch_op: - batch_op.drop_constraint('uq_apikey_id', type_='unique') + with op.batch_alter_table('flow', schema=None) as batch_op: + batch_op.drop_constraint('uq_flow_id', type_='unique') + with op.batch_alter_table('apikey', schema=None) as batch_op: + batch_op.drop_constraint('uq_apikey_id', type_='unique') + except Exception: + pass # ### end Alembic commands ###