langflow-ai / langflow

⛓️ Langflow is a visual framework for building multi-agent and RAG applications. It's open-source, Python-powered, fully customizable, model and vector store agnostic.
http://www.langflow.org
MIT License
22.64k stars 3.21k forks source link

The error - duplicate 'folder_id' in alembic #1988

Closed songjinu closed 1 week ago

songjinu commented 2 months ago

Describe the bug The error - duplicate 'folder_id' in alembic

at src/backend/base/langflow/alembic/versions/012fb73ac359_add_folder_table.py

    if "folder_id" not in inspector.get_columns("flow"):
        with op.batch_alter_table("flow", schema=None) as batch_op:
            batch_op.add_column(sa.Column("folder_id", sqlmodel.sql.sqltypes.GUID(), nullable=True))
            batch_op.create_foreign_key("flow_folder_id_fkey", "folder", ["folder_id"], ["id"])
            batch_op.drop_column("folder")

inspector.get_columns("flow") return List[Dict] I modifed like this

    flow = inspector.get_columns("flow")
    if any('folder_id' in columns["name"] for columns in flow):
        with op.batch_alter_table("flow", schema=None) as batch_op:
            batch_op.create_foreign_key("flow_folder_id_fkey", "folder", ["folder_id"], ["id"])
            batch_op.drop_column("folder")
    else:
        with op.batch_alter_table("flow", schema=None) as batch_op:
            batch_op.add_column(sa.Column("folder_id", sqlmodel.sql.sqltypes.GUID(), nullable=True))
            batch_op.create_foreign_key("flow_folder_id_fkey", "folder", ["folder_id"], ["id"])
            batch_op.drop_column("folder")

Browser and Version

dosubot[bot] commented 2 months ago

To resolve the error related to a duplicate 'folder_id' in Alembic in the file src/backend/base/langflow/alembic/versions/012fb73ac359_add_folder_table.py, you need to ensure that the column folder_id is not being added multiple times. The issue might be due to the drop_column("folder") line, which should be drop_column("folder_id") instead.

Here is the corrected upgrade function:

def upgrade() -> None:
    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)  # type: ignore
    table_names = inspector.get_table_names()
    # ### commands auto generated by Alembic - please adjust! ###
    if "folder" not in table_names:
        op.create_table(
            "folder",
            sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
            sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
            sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
            sa.Column("parent_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
            sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
            sa.ForeignKeyConstraint(
                ["parent_id"],
                ["folder.id"],
            ),
            sa.ForeignKeyConstraint(
                ["user_id"],
                ["user.id"],
            ),
            sa.PrimaryKeyConstraint("id"),
        )
    indexes = inspector.get_indexes("folder")
    if "ix_folder_name" not in [index["name"] for index in indexes]:
        with op.batch_alter_table("folder", schema=None) as batch_op:
            batch_op.create_index(batch_op.f("ix_folder_name"), ["name"], unique=False)

    if "folder_id" not in inspector.get_columns("flow"):
        with op.batch_alter_table("flow", schema=None) as batch_op:
            batch_op.add_column(sa.Column("folder_id", sqlmodel.sql.sqltypes.GUID(), nullable=True))
            batch_op.create_foreign_key("flow_folder_id_fkey", "folder", ["folder_id"], ["id"])
            batch_op.drop_column("folder_id")

    # ### end Alembic commands ###

This change ensures that the folder_id column is correctly managed without causing duplication errors [1].

#### Details **About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

anovazzi1 commented 3 weeks ago

Hello, Sorry for the delay. Did you try using the new version? Does the error still persist?

carlosrcoelho commented 1 week ago

Hi @songjinu , 
 I hope you're doing well. Just a friendly reminder that if we do not hear back from you within the next 3 days, we will close this issue. If you need more time or further assistance, please let us know.


Thank you for your understanding!

carlosrcoelho commented 1 week ago

Thank you for your contribution! This issue will be closed. If you have any questions or encounter another problem, please open a new issue and we will be ready to assist you.