Skip to content

Commit

Permalink
fix: Problem in the description field when using the MariaDB or MySQL (
Browse files Browse the repository at this point in the history
…#3431)

* fix: Problem in the description field when using the MariaDB or MySQL database.

* fix: Problem in the description field when using the MariaDB or MySQL database.

* fix: Add the migration script to update description columns type.

* [autofix.ci] apply automated fixes

* Update src/backend/base/langflow/alembic/versions/1d90f8a0efe1_update_description_columns_type.py

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

---------

Co-authored-by: Marcelo Nunes <marcelo.nunes@nava.com.br>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
  • Loading branch information
4 people authored Aug 29, 2024
1 parent 06ea6c4 commit 10d0336
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Update description columns type
Revision ID: 4522eb831f5c
Revises: 0d60fcbd4e8e
Create Date: 2024-08-20 11:46:56.266061
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op
from langflow.utils import migration
from sqlalchemy.engine.reflection import Inspector

# revision identifiers, used by Alembic.
revision: str = "4522eb831f5c"
down_revision: Union[str, None] = "0d60fcbd4e8e"
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("flow", schema=None) as batch_op:
if migration.column_exists(table_name="flow", column_name="description", conn=conn):
columns = inspector.get_columns("flow")
description_column = next((column for column in columns if column["name"] == "description"), None)
if description_column is not None and isinstance(description_column["type"], sa.VARCHAR):
batch_op.alter_column(
"description", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
)

with op.batch_alter_table("folder", schema=None) as batch_op:
if migration.column_exists(table_name="folder", column_name="description", conn=conn):
columns = inspector.get_columns("folder")
description_column = next((column for column in columns if column["name"] == "description"), None)
if description_column is not None and isinstance(description_column["type"], sa.VARCHAR):
batch_op.alter_column(
"description", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
)

# ### 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("folder", schema=None) as batch_op:
if migration.column_exists(table_name="folder", column_name="description", conn=conn):
columns = inspector.get_columns("folder")
description_column = next((column for column in columns if column["name"] == "description"), None)
if description_column is not None and isinstance(description_column["type"], sa.VARCHAR):
batch_op.alter_column(
"description", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
)

with op.batch_alter_table("flow", schema=None) as batch_op:
if migration.column_exists(table_name="flow", column_name="description", conn=conn):
columns = inspector.get_columns("flow")
description_column = next((column for column in columns if column["name"] == "description"), None)
if description_column is not None and isinstance(description_column["type"], sa.VARCHAR):
batch_op.alter_column(
"description", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from emoji import purely_emoji # type: ignore
from fastapi import HTTPException, status
from pydantic import field_serializer, field_validator
from sqlalchemy import UniqueConstraint
from sqlalchemy import UniqueConstraint, Text
from sqlmodel import JSON, Column, Field, Relationship, SQLModel

from langflow.schema import Data
Expand All @@ -25,7 +25,7 @@

class FlowBase(SQLModel):
name: str = Field(index=True)
description: Optional[str] = Field(index=True, nullable=True, default=None)
description: Optional[str] = Field(default=None, sa_column=Column(Text, index=True, nullable=True))
icon: Optional[str] = Field(default=None, nullable=True)
icon_bg_color: Optional[str] = Field(default=None, nullable=True)
data: Optional[Dict] = Field(default=None, nullable=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import TYPE_CHECKING, List, Optional
from uuid import UUID, uuid4

from sqlalchemy import UniqueConstraint
from sqlmodel import Field, Relationship, SQLModel
from sqlalchemy import UniqueConstraint, Text
from sqlmodel import Field, Relationship, SQLModel, Column

from langflow.services.database.models.flow.model import FlowRead

Expand All @@ -13,7 +13,7 @@

class FolderBase(SQLModel):
name: str = Field(index=True)
description: Optional[str] = Field(default=None)
description: Optional[str] = Field(default=None, sa_column=Column(Text))


class Folder(FolderBase, table=True): # type: ignore
Expand Down

0 comments on commit 10d0336

Please sign in to comment.