From 706cdc08747181c0bdc426a6fbdd715eb934cf6b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 25 Aug 2023 15:25:09 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat(alembic):=20add=20migration?= =?UTF-8?q?=20script=20to=20update=20all=20tables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new migration script to update all tables in the database. The script includes the following changes: - Added columns 'created_at' and 'user_id' to the 'apikey' table - Altered the 'name' column in the 'apikey' table to allow null values - Created indexes on the 'name' and 'user_id' columns in the 'apikey' table - Created a foreign key constraint between the 'apikey' table and the 'user' table - Added the 'user_id' column to the 'flow' table - Created an index on the 'user_id' column in the 'flow' table - Created a foreign key constraint between the 'flow' table and the 'user' table - Removed the 'create_at' column from the 'apikey' table This migration script is designed to be used with Alembic for database schema updates. --- .../d3749cf7ac7e_update_all_tables.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/backend/langflow/alembic/versions/d3749cf7ac7e_update_all_tables.py diff --git a/src/backend/langflow/alembic/versions/d3749cf7ac7e_update_all_tables.py b/src/backend/langflow/alembic/versions/d3749cf7ac7e_update_all_tables.py new file mode 100644 index 000000000..fee7b9b93 --- /dev/null +++ b/src/backend/langflow/alembic/versions/d3749cf7ac7e_update_all_tables.py @@ -0,0 +1,53 @@ +"""Update all tables + +Revision ID: d3749cf7ac7e +Revises: 5512e39b4012 +Create Date: 2023-08-25 15:16:00.970071 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import sqlmodel + + +# revision identifiers, used by Alembic. +revision: str = 'd3749cf7ac7e' +down_revision: Union[str, None] = '5512e39b4012' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('apikey', sa.Column('created_at', sa.DateTime(), nullable=False)) + op.add_column('apikey', sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=False)) + op.alter_column('apikey', 'name', + existing_type=sa.VARCHAR(), + nullable=True) + op.create_index(op.f('ix_apikey_name'), 'apikey', ['name'], unique=False) + op.create_index(op.f('ix_apikey_user_id'), 'apikey', ['user_id'], unique=False) + op.create_foreign_key(None, 'apikey', 'user', ['user_id'], ['id']) + op.drop_column('apikey', 'create_at') + op.add_column('flow', sa.Column('user_id', sqlmodel.sql.sqltypes.GUID(), nullable=False)) + op.create_index(op.f('ix_flow_user_id'), 'flow', ['user_id'], unique=False) + op.create_foreign_key(None, 'flow', 'user', ['user_id'], ['id']) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'flow', type_='foreignkey') + op.drop_index(op.f('ix_flow_user_id'), table_name='flow') + op.drop_column('flow', 'user_id') + op.add_column('apikey', sa.Column('create_at', sa.DATETIME(), nullable=False)) + op.drop_constraint(None, 'apikey', type_='foreignkey') + op.drop_index(op.f('ix_apikey_user_id'), table_name='apikey') + op.drop_index(op.f('ix_apikey_name'), table_name='apikey') + op.alter_column('apikey', 'name', + existing_type=sa.VARCHAR(), + nullable=False) + op.drop_column('apikey', 'user_id') + op.drop_column('apikey', 'created_at') + # ### end Alembic commands ###