mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
chore: add database migration
This commit is contained in:
83
api/migrations/versions/2025_08_22_2103-f3747f1446a4_.py
Normal file
83
api/migrations/versions/2025_08_22_2103-f3747f1446a4_.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: f3747f1446a4
|
||||||
|
Revises: 3803626caa7c
|
||||||
|
Create Date: 2025-08-22 21:03:32.462487
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import models as models
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'f3747f1446a4'
|
||||||
|
down_revision = '3803626caa7c'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('chatflow_conversations',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('app_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('node_id', sa.Text(), nullable=True),
|
||||||
|
sa.Column('original_conversation_id', models.types.StringUUID(), nullable=True),
|
||||||
|
sa.Column('conversation_metadata', sa.Text(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='chatflow_conversations_pkey')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('chatflow_conversations', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('chatflow_conversations_original_conversation_id_idx', ['tenant_id', 'app_id', 'node_id', 'original_conversation_id'], unique=False)
|
||||||
|
|
||||||
|
op.create_table('chatflow_memory_variables',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('tenant_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('app_id', models.types.StringUUID(), nullable=True),
|
||||||
|
sa.Column('conversation_id', models.types.StringUUID(), nullable=True),
|
||||||
|
sa.Column('node_id', sa.Text(), nullable=True),
|
||||||
|
sa.Column('memory_id', sa.Text(), nullable=False),
|
||||||
|
sa.Column('value', sa.Text(), nullable=False),
|
||||||
|
sa.Column('name', sa.Text(), nullable=False),
|
||||||
|
sa.Column('scope', sa.String(length=10), nullable=False),
|
||||||
|
sa.Column('term', sa.String(length=20), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='chatflow_memory_variables_pkey')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('chatflow_memory_variables', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('chatflow_memory_variables_memory_id_idx', ['tenant_id', 'app_id', 'node_id', 'memory_id'], unique=False)
|
||||||
|
|
||||||
|
op.create_table('chatflow_messages',
|
||||||
|
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||||
|
sa.Column('conversation_id', models.types.StringUUID(), nullable=False),
|
||||||
|
sa.Column('index', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('version', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('data', sa.Text(), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id', name='chatflow_messages_pkey')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('chatflow_messages', schema=None) as batch_op:
|
||||||
|
batch_op.create_index('chatflow_messages_version_idx', ['conversation_id', 'index', 'version'], unique=False)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('chatflow_messages', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('chatflow_messages_version_idx')
|
||||||
|
|
||||||
|
op.drop_table('chatflow_messages')
|
||||||
|
with op.batch_alter_table('chatflow_memory_variables', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('chatflow_memory_variables_memory_id_idx')
|
||||||
|
|
||||||
|
op.drop_table('chatflow_memory_variables')
|
||||||
|
with op.batch_alter_table('chatflow_conversations', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index('chatflow_conversations_original_conversation_id_idx')
|
||||||
|
|
||||||
|
op.drop_table('chatflow_conversations')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@ -9,6 +9,7 @@ from .account import (
|
|||||||
TenantStatus,
|
TenantStatus,
|
||||||
)
|
)
|
||||||
from .api_based_extension import APIBasedExtension, APIBasedExtensionPoint
|
from .api_based_extension import APIBasedExtension, APIBasedExtensionPoint
|
||||||
|
from .chatflow_memory import ChatflowMemoryVariable, ChatflowConversation, ChatflowMessage
|
||||||
from .dataset import (
|
from .dataset import (
|
||||||
AppDatasetJoin,
|
AppDatasetJoin,
|
||||||
Dataset,
|
Dataset,
|
||||||
@ -177,5 +178,8 @@ __all__ = [
|
|||||||
"WorkflowRunTriggeredFrom",
|
"WorkflowRunTriggeredFrom",
|
||||||
"WorkflowToolProvider",
|
"WorkflowToolProvider",
|
||||||
"WorkflowType",
|
"WorkflowType",
|
||||||
|
"ChatflowMemoryVariable",
|
||||||
|
"ChatflowConversation",
|
||||||
|
"ChatflowMessage",
|
||||||
"db",
|
"db",
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user