fix: Update the columns that need to change their type to text (MySQL e MariaDB) (#4026)
* fix: Update the columns that need to change their type to text * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
9adf1ef2e5
commit
bffb0f129b
3 changed files with 74 additions and 2 deletions
|
|
@ -0,0 +1,70 @@
|
||||||
|
"""Update the columns that need to change their type to text
|
||||||
|
|
||||||
|
Revision ID: 0ae3a2674f32
|
||||||
|
Revises: d2d475a1f7c0
|
||||||
|
Create Date: 2024-10-04 17:30:12.924809
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import sqlmodel
|
||||||
|
from sqlalchemy.engine.reflection import Inspector
|
||||||
|
from langflow.utils import migration
|
||||||
|
from sqlalchemy.dialects import sqlite
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '0ae3a2674f32'
|
||||||
|
down_revision: Union[str, None] = 'd2d475a1f7c0'
|
||||||
|
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("vertex_build", schema=None) as batch_op:
|
||||||
|
if migration.column_exists(table_name="vertex_build", column_name="params", conn=conn):
|
||||||
|
columns = inspector.get_columns("vertex_build")
|
||||||
|
params_column = next((column for column in columns if column["name"] == "params"), None)
|
||||||
|
if params_column is not None and isinstance(params_column["type"], sa.VARCHAR):
|
||||||
|
batch_op.alter_column(
|
||||||
|
"params", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
|
||||||
|
)
|
||||||
|
|
||||||
|
with op.batch_alter_table("message", schema=None) as batch_op:
|
||||||
|
if migration.column_exists(table_name="message", column_name="text", conn=conn):
|
||||||
|
columns = inspector.get_columns("message")
|
||||||
|
text_column = next((column for column in columns if column["name"] == "text"), None)
|
||||||
|
if text_column is not None and isinstance(text_column["type"], sa.VARCHAR):
|
||||||
|
batch_op.alter_column(
|
||||||
|
"text", 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("message", schema=None) as batch_op:
|
||||||
|
if migration.column_exists(table_name="message", column_name="text", conn=conn):
|
||||||
|
columns = inspector.get_columns("message")
|
||||||
|
text_column = next((column for column in columns if column["name"] == "text"), None)
|
||||||
|
if text_column is not None and isinstance(text_column["type"], sa.VARCHAR):
|
||||||
|
batch_op.alter_column(
|
||||||
|
"text", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
|
||||||
|
)
|
||||||
|
|
||||||
|
with op.batch_alter_table("vertex_build", schema=None) as batch_op:
|
||||||
|
if migration.column_exists(table_name="vertex_build", column_name="params", conn=conn):
|
||||||
|
columns = inspector.get_columns("vertex_build")
|
||||||
|
params_column = next((column for column in columns if column["name"] == "params"), None)
|
||||||
|
if params_column is not None and isinstance(params_column["type"], sa.VARCHAR):
|
||||||
|
batch_op.alter_column(
|
||||||
|
"params", existing_type=sa.VARCHAR(), type_=sa.Text(), existing_nullable=True
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
@ -3,6 +3,7 @@ from typing import TYPE_CHECKING
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from pydantic import field_validator
|
from pydantic import field_validator
|
||||||
|
from sqlalchemy import Text
|
||||||
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -15,7 +16,7 @@ class MessageBase(SQLModel):
|
||||||
sender: str
|
sender: str
|
||||||
sender_name: str
|
sender_name: str
|
||||||
session_id: str
|
session_id: str
|
||||||
text: str
|
text: str = Field(sa_column=Column(Text))
|
||||||
files: list[str] = Field(default_factory=list)
|
files: list[str] = Field(default_factory=list)
|
||||||
|
|
||||||
@field_validator("files", mode="before")
|
@field_validator("files", mode="before")
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from typing import TYPE_CHECKING
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
from pydantic import BaseModel, field_serializer, field_validator
|
from pydantic import BaseModel, field_serializer, field_validator
|
||||||
|
from sqlalchemy import Text
|
||||||
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
from sqlmodel import JSON, Column, Field, Relationship, SQLModel
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -14,7 +15,7 @@ class VertexBuildBase(SQLModel):
|
||||||
id: str = Field(nullable=False)
|
id: str = Field(nullable=False)
|
||||||
data: dict | None = Field(default=None, sa_column=Column(JSON))
|
data: dict | None = Field(default=None, sa_column=Column(JSON))
|
||||||
artifacts: dict | None = Field(default=None, sa_column=Column(JSON))
|
artifacts: dict | None = Field(default=None, sa_column=Column(JSON))
|
||||||
params: str | None = Field(nullable=True)
|
params: str | None = Field(default=None, sa_column=Column(Text, nullable=True))
|
||||||
valid: bool = Field(nullable=False)
|
valid: bool = Field(nullable=False)
|
||||||
flow_id: UUID = Field(foreign_key="flow.id")
|
flow_id: UUID = Field(foreign_key="flow.id")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue