fix: Problem in the description field when using the MariaDB or MySQL (#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>
This commit is contained in:
parent
06ea6c408b
commit
10d03360c5
3 changed files with 75 additions and 5 deletions
|
|
@ -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 ###
|
||||||
|
|
@ -10,7 +10,7 @@ import emoji
|
||||||
from emoji import purely_emoji # type: ignore
|
from emoji import purely_emoji # type: ignore
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
from pydantic import field_serializer, field_validator
|
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 sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||||
|
|
||||||
from langflow.schema import Data
|
from langflow.schema import Data
|
||||||
|
|
@ -25,7 +25,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
class FlowBase(SQLModel):
|
class FlowBase(SQLModel):
|
||||||
name: str = Field(index=True)
|
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: Optional[str] = Field(default=None, nullable=True)
|
||||||
icon_bg_color: 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)
|
data: Optional[Dict] = Field(default=None, nullable=True)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from typing import TYPE_CHECKING, List, Optional
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from sqlalchemy import UniqueConstraint
|
from sqlalchemy import UniqueConstraint, Text
|
||||||
from sqlmodel import Field, Relationship, SQLModel
|
from sqlmodel import Field, Relationship, SQLModel, Column
|
||||||
|
|
||||||
from langflow.services.database.models.flow.model import FlowRead
|
from langflow.services.database.models.flow.model import FlowRead
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
class FolderBase(SQLModel):
|
class FolderBase(SQLModel):
|
||||||
name: str = Field(index=True)
|
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
|
class Folder(FolderBase, table=True): # type: ignore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue