mirror of https://github.com/langgenius/dify.git
Delete soft-deleted conversations before dropping is_deleted column
Use sa.table() with sa.delete() and sa.true() to generate cross-database compatible SQL that works in both online and offline modes without requiring schema reflection.
This commit is contained in:
parent
4ad79538e2
commit
eadf137b75
|
|
@ -1,33 +0,0 @@
|
|||
"""remove unused is_deleted field from conversations
|
||||
|
||||
Revision ID: 4f02b6704509
|
||||
Revises: 7bb281b7a422
|
||||
Create Date: 2025-09-02 20:12:37.311318
|
||||
|
||||
This migration runs on both PostgreSQL and MySQL.
|
||||
"""
|
||||
from alembic import op
|
||||
import models as models
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4f02b6704509'
|
||||
down_revision = '7bb281b7a422'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('conversations', schema=None) as batch_op:
|
||||
batch_op.drop_column('is_deleted')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('conversations', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('is_deleted', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
"""remove unused is_deleted from conversations
|
||||
|
||||
Revision ID: e5d7a95e676f
|
||||
Revises: 7bb281b7a422
|
||||
Create Date: 2025-11-27 18:27:09.006691
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "e5d7a95e676f"
|
||||
down_revision = "7bb281b7a422"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
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_column("is_deleted")
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table("conversations", schema=None) as batch_op:
|
||||
batch_op.add_column(
|
||||
sa.Column("is_deleted", sa.BOOLEAN(), server_default=sa.text("false"), autoincrement=False, nullable=False)
|
||||
)
|
||||
Loading…
Reference in New Issue