From a6b30e1b8b18085b87494cc2487ba8702620b054 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 4 Oct 2023 10:20:32 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(alembic):=20change=20colum?= =?UTF-8?q?ns=20to=20be=20nullable=20in=20migration=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔧 chore(api_key.py): make last_used_at field nullable in ApiKeyBase model 🔧 chore(flow.py): make data field nullable in FlowBase model 🔧 chore(user.py): make profile_image field nullable in User model --- ...866d51fd2_change_columns_to_be_nullable.py | 80 +++++++++++++++++++ .../database/models/api_key/api_key.py | 2 +- .../services/database/models/flow/flow.py | 3 +- .../services/database/models/user/user.py | 2 +- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 src/backend/langflow/alembic/versions/eb5866d51fd2_change_columns_to_be_nullable.py diff --git a/src/backend/langflow/alembic/versions/eb5866d51fd2_change_columns_to_be_nullable.py b/src/backend/langflow/alembic/versions/eb5866d51fd2_change_columns_to_be_nullable.py new file mode 100644 index 000000000..4bfc38461 --- /dev/null +++ b/src/backend/langflow/alembic/versions/eb5866d51fd2_change_columns_to_be_nullable.py @@ -0,0 +1,80 @@ +"""Change columns to be nullable + +Revision ID: eb5866d51fd2 +Revises: 67cc006d50bf +Create Date: 2023-10-04 10:18:25.640458 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import sqlmodel + + +# revision identifiers, used by Alembic. +revision: str = "eb5866d51fd2" +down_revision: Union[str, None] = "67cc006d50bf" +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! ### + try: + op.drop_table("flowstyle") + with op.batch_alter_table("component", schema=None) as batch_op: + batch_op.drop_index("ix_component_frontend_node_id") + batch_op.drop_index("ix_component_name") + except Exception: + pass + + try: + op.drop_table("component") + except Exception: + pass + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + try: + op.create_table( + "component", + sa.Column("id", sa.CHAR(length=32), nullable=False), + sa.Column("frontend_node_id", sa.CHAR(length=32), nullable=False), + sa.Column("name", sa.VARCHAR(), nullable=False), + sa.Column("description", sa.VARCHAR(), nullable=True), + sa.Column("python_code", sa.VARCHAR(), nullable=True), + sa.Column("return_type", sa.VARCHAR(), nullable=True), + sa.Column("is_disabled", sa.BOOLEAN(), nullable=False), + sa.Column("is_read_only", sa.BOOLEAN(), nullable=False), + sa.Column("create_at", sa.DATETIME(), nullable=False), + sa.Column("update_at", sa.DATETIME(), nullable=False), + sa.PrimaryKeyConstraint("id"), + ) + with op.batch_alter_table("component", schema=None) as batch_op: + batch_op.create_index("ix_component_name", ["name"], unique=False) + batch_op.create_index( + "ix_component_frontend_node_id", ["frontend_node_id"], unique=False + ) + except Exception: + pass + + try: + op.create_table( + "flowstyle", + sa.Column("color", sa.VARCHAR(), nullable=False), + sa.Column("emoji", sa.VARCHAR(), nullable=False), + sa.Column("flow_id", sa.CHAR(length=32), nullable=True), + sa.Column("id", sa.CHAR(length=32), nullable=False), + sa.ForeignKeyConstraint( + ["flow_id"], + ["flow.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("id"), + ) + except Exception: + pass + # ### end Alembic commands ### diff --git a/src/backend/langflow/services/database/models/api_key/api_key.py b/src/backend/langflow/services/database/models/api_key/api_key.py index 35aa6c7a9..684027ee2 100644 --- a/src/backend/langflow/services/database/models/api_key/api_key.py +++ b/src/backend/langflow/services/database/models/api_key/api_key.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: class ApiKeyBase(SQLModelSerializable): name: Optional[str] = Field(index=True) created_at: datetime = Field(default_factory=datetime.utcnow) - last_used_at: Optional[datetime] = Field(default=None) + last_used_at: Optional[datetime] = Field(default=None, nullable=True) total_uses: int = Field(default=0) is_active: bool = Field(default=True) diff --git a/src/backend/langflow/services/database/models/flow/flow.py b/src/backend/langflow/services/database/models/flow/flow.py index e6ad4af4a..e578f37c4 100644 --- a/src/backend/langflow/services/database/models/flow/flow.py +++ b/src/backend/langflow/services/database/models/flow/flow.py @@ -2,6 +2,7 @@ from langflow.services.database.models.base import SQLModelSerializable from pydantic import validator + from sqlmodel import Field, JSON, Column, Relationship from uuid import UUID, uuid4 from typing import Dict, Optional, TYPE_CHECKING @@ -13,7 +14,7 @@ if TYPE_CHECKING: class FlowBase(SQLModelSerializable): name: str = Field(index=True) description: Optional[str] = Field(index=True) - data: Optional[Dict] = Field(default=None) + data: Optional[Dict] = Field(default=None, nullable=True) @validator("data") def validate_json(v): diff --git a/src/backend/langflow/services/database/models/user/user.py b/src/backend/langflow/services/database/models/user/user.py index 5f2f3e1c4..b1f514531 100644 --- a/src/backend/langflow/services/database/models/user/user.py +++ b/src/backend/langflow/services/database/models/user/user.py @@ -15,7 +15,7 @@ class User(SQLModelSerializable, table=True): id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True) username: str = Field(index=True, unique=True) password: str = Field() - profile_image: Optional[str] = Field(default=None) + profile_image: Optional[str] = Field(default=None, nullable=True) is_active: bool = Field(default=False) is_superuser: bool = Field(default=False) create_at: datetime = Field(default_factory=datetime.utcnow)