mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 02:02:40 +08:00
fix(api): repair conversation is_deleted removal migration
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""remove unused is_deleted from conversations
|
||||
|
||||
Revision ID: e5d7a95e676f
|
||||
Revises: 288345cd01d1
|
||||
Create Date: 2025-11-27 18:27:09.006691
|
||||
Revises: 6b5f9f8b1a2c
|
||||
Create Date: 2026-04-02 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
@@ -10,21 +10,48 @@ import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "e5d7a95e676f"
|
||||
down_revision = "9d77545f524e"
|
||||
down_revision = "6b5f9f8b1a2c"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
CONVERSATION_CREATED_AT_INDEX_NAME = "conversation_app_created_at_idx"
|
||||
CONVERSATION_UPDATED_AT_INDEX_NAME = "conversation_app_updated_at_idx"
|
||||
|
||||
|
||||
def _recreate_conversation_indexes(*, use_partial_indexes: bool) -> None:
|
||||
index_kwargs: dict[str, object] = {"unique": False}
|
||||
if use_partial_indexes:
|
||||
index_kwargs["postgresql_where"] = sa.text("is_deleted IS false")
|
||||
|
||||
with op.batch_alter_table("conversations", schema=None) as batch_op:
|
||||
batch_op.create_index(
|
||||
CONVERSATION_CREATED_AT_INDEX_NAME,
|
||||
["app_id", sa.literal_column("created_at DESC")],
|
||||
**index_kwargs,
|
||||
)
|
||||
batch_op.create_index(
|
||||
CONVERSATION_UPDATED_AT_INDEX_NAME,
|
||||
["app_id", sa.literal_column("updated_at DESC")],
|
||||
**index_kwargs,
|
||||
)
|
||||
|
||||
|
||||
def upgrade():
|
||||
conversations = sa.table("conversations", sa.column("is_deleted", sa.Boolean))
|
||||
op.execute(sa.delete(conversations).where(conversations.c.is_deleted == sa.true()))
|
||||
|
||||
with op.batch_alter_table("conversations", schema=None) as batch_op:
|
||||
batch_op.drop_index(CONVERSATION_UPDATED_AT_INDEX_NAME)
|
||||
batch_op.drop_index(CONVERSATION_CREATED_AT_INDEX_NAME)
|
||||
batch_op.drop_column("is_deleted")
|
||||
|
||||
_recreate_conversation_indexes(use_partial_indexes=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("conversations", schema=None) as batch_op:
|
||||
batch_op.drop_index(CONVERSATION_UPDATED_AT_INDEX_NAME)
|
||||
batch_op.drop_index(CONVERSATION_CREATED_AT_INDEX_NAME)
|
||||
batch_op.add_column(
|
||||
sa.Column(
|
||||
"is_deleted",
|
||||
@@ -34,3 +61,5 @@ def downgrade():
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
|
||||
_recreate_conversation_indexes(use_partial_indexes=True)
|
||||
|
||||
@@ -1029,18 +1029,8 @@ class Conversation(Base):
|
||||
__table_args__ = (
|
||||
sa.PrimaryKeyConstraint("id", name="conversation_pkey"),
|
||||
sa.Index("conversation_app_from_user_idx", "app_id", "from_source", "from_end_user_id"),
|
||||
sa.Index(
|
||||
"conversation_app_created_at_idx",
|
||||
"app_id",
|
||||
sa.text("created_at DESC"),
|
||||
postgresql_where=sa.text("is_deleted IS false"),
|
||||
),
|
||||
sa.Index(
|
||||
"conversation_app_updated_at_idx",
|
||||
"app_id",
|
||||
sa.text("updated_at DESC"),
|
||||
postgresql_where=sa.text("is_deleted IS false"),
|
||||
),
|
||||
sa.Index("conversation_app_created_at_idx", "app_id", sa.text("created_at DESC")),
|
||||
sa.Index("conversation_app_updated_at_idx", "app_id", sa.text("updated_at DESC")),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(StringUUID, default=lambda: str(uuid4()))
|
||||
|
||||
@@ -112,7 +112,6 @@ class ConversationServiceIntegrationTestDataFactory:
|
||||
from_end_user_id=user.id if isinstance(user, EndUser) else None,
|
||||
from_account_id=user.id if isinstance(user, Account) else None,
|
||||
dialogue_count=0,
|
||||
is_deleted=False,
|
||||
)
|
||||
conversation.inputs = {}
|
||||
if updated_at is not None:
|
||||
|
||||
Reference in New Issue
Block a user