fix: model issue

pull/21891/head
ytqh 1 year ago
parent da90753256
commit edb1bd7d26

@ -0,0 +1,67 @@
"""fix merge error
Revision ID: 71afb1a6d8dc
Revises: e885e2eddbad
Create Date: 2025-05-02 22:37:16.506584
"""
from alembic import op
import models as models
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '71afb1a6d8dc'
down_revision = 'e885e2eddbad'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tool_published_apps', schema=None) as batch_op:
batch_op.add_column(sa.Column('tenant_id', models.types.StringUUID(), nullable=False))
batch_op.add_column(sa.Column('conversation_id', models.types.StringUUID(), nullable=True))
batch_op.add_column(sa.Column('file_key', sa.String(length=255), nullable=False))
batch_op.add_column(sa.Column('mimetype', sa.String(length=255), nullable=False))
batch_op.add_column(sa.Column('original_url', sa.String(length=2048), nullable=True))
batch_op.add_column(sa.Column('name', sa.String(), nullable=False))
batch_op.add_column(sa.Column('size', sa.Integer(), nullable=False))
with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op:
batch_op.drop_index('workflow_app_log_app_idx')
batch_op.create_index('workflow_app_log_app_idx', ['tenant_id', 'app_id', 'created_at'], unique=False)
batch_op.create_index('workflow_app_log_workflow_run_idx', ['workflow_run_id'], unique=False)
with op.batch_alter_table('workflow_conversation_variables', schema=None) as batch_op:
batch_op.drop_index('workflow_conversation_variables_app_id_idx')
batch_op.drop_index('workflow_conversation_variables_created_at_idx')
batch_op.create_index('workflow__conversation_variables_app_id_idx', ['app_id'], unique=False)
batch_op.create_index('workflow__conversation_variables_created_at_idx', ['created_at'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('workflow_conversation_variables', schema=None) as batch_op:
batch_op.drop_index('workflow__conversation_variables_created_at_idx')
batch_op.drop_index('workflow__conversation_variables_app_id_idx')
batch_op.create_index('workflow_conversation_variables_created_at_idx', ['created_at'], unique=False)
batch_op.create_index('workflow_conversation_variables_app_id_idx', ['app_id'], unique=False)
with op.batch_alter_table('workflow_app_logs', schema=None) as batch_op:
batch_op.drop_index('workflow_app_log_workflow_run_idx')
batch_op.drop_index('workflow_app_log_app_idx')
batch_op.create_index('workflow_app_log_app_idx', ['tenant_id', 'app_id'], unique=False)
with op.batch_alter_table('tool_published_apps', schema=None) as batch_op:
batch_op.drop_column('size')
batch_op.drop_column('name')
batch_op.drop_column('original_url')
batch_op.drop_column('mimetype')
batch_op.drop_column('file_key')
batch_op.drop_column('conversation_id')
batch_op.drop_column('tenant_id')
# ### end Alembic commands ###

@ -15,19 +15,18 @@ if TYPE_CHECKING:
from models.workflow import Workflow from models.workflow import Workflow
import sqlalchemy as sa import sqlalchemy as sa
from flask import request
from flask_login import UserMixin # type: ignore
from sqlalchemy import Float, Index, PrimaryKeyConstraint, func, text
from sqlalchemy.orm import Mapped, Session, mapped_column
from configs import dify_config from configs import dify_config
from constants import DEFAULT_FILE_NUMBER_LIMITS from constants import DEFAULT_FILE_NUMBER_LIMITS
from core.file import FILE_MODEL_IDENTITY, File, FileTransferMethod, FileType from core.file import FILE_MODEL_IDENTITY, File, FileTransferMethod, FileType
from core.file import helpers as file_helpers from core.file import helpers as file_helpers
from flask import request
from flask_login import UserMixin # type: ignore
from libs.helper import generate_string from libs.helper import generate_string
from models.base import Base from models.base import Base
from models.enums import CreatedByRole from models.enums import CreatedByRole
from models.workflow import WorkflowRunStatus from models.workflow import WorkflowRunStatus
from sqlalchemy import Float, Index, PrimaryKeyConstraint, func, text
from sqlalchemy.orm import Mapped, Session, mapped_column
from .account import Account, Tenant from .account import Account, Tenant
from .engine import db from .engine import db
@ -900,13 +899,6 @@ class Message(db.Model): # type: ignore[name-defined]
db.Index("message_created_at_idx", "created_at"), db.Index("message_created_at_idx", "created_at"),
db.Index("message_organization_id_idx", "organization_id"), db.Index("message_organization_id_idx", "organization_id"),
db.Index("message_end_user_org_created_idx", "from_end_user_id", "organization_id", "created_at"), db.Index("message_end_user_org_created_idx", "from_end_user_id", "organization_id", "created_at"),
PrimaryKeyConstraint("id", name="message_pkey"),
Index("message_app_id_idx", "app_id", "created_at"),
Index("message_conversation_id_idx", "conversation_id"),
Index("message_end_user_idx", "app_id", "from_source", "from_end_user_id"),
Index("message_account_idx", "app_id", "from_source", "from_account_id"),
Index("message_workflow_run_id_idx", "conversation_id", "workflow_run_id"),
Index("message_created_at_idx", "created_at"),
) )
id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()"))

@ -1,14 +1,13 @@
import time import time
from datetime import datetime from datetime import datetime
import click
from sqlalchemy import asc, func, or_
import app import app
import click
from configs import dify_config from configs import dify_config
from core.app.entities.app_invoke_entities import InvokeFrom from core.app.entities.app_invoke_entities import InvokeFrom
from models.model import App, EndUser, Message, db from models.model import App, EndUser, Message, db
from services.app_generate_service import AppGenerateService from services.app_generate_service import AppGenerateService
from sqlalchemy import asc, func, or_
@app.celery.task(queue="dataset") @app.celery.task(queue="dataset")
@ -145,7 +144,7 @@ def process_user_memory(user: EndUser, new_messages: str):
click.echo(click.style("No memory generation app_id provided, skipping memory generation.", fg="yellow")) click.echo(click.style("No memory generation app_id provided, skipping memory generation.", fg="yellow"))
return return
memory_app_model = App.query.filter(App.id == memory_app_id).first() memory_app_model = db.session.query(App).filter(App.id == memory_app_id).first()
if memory_app_model is None: if memory_app_model is None:
click.echo(click.style(f"App not found for memory generation app_id {memory_app_id}", fg="yellow")) click.echo(click.style(f"App not found for memory generation app_id {memory_app_id}", fg="yellow"))
return return
@ -190,7 +189,7 @@ def process_user_health_summary(user: EndUser, new_messages: str):
click.echo(click.style("No health_summary_app_id provided, skipping health summary generation.", fg="yellow")) click.echo(click.style("No health_summary_app_id provided, skipping health summary generation.", fg="yellow"))
return return
health_summary_app_model = App.query.filter(App.id == health_summary_app_id).first() health_summary_app_model = db.session.query(App).filter(App.id == health_summary_app_id).first()
if health_summary_app_model is None: if health_summary_app_model is None:
click.echo( click.echo(
click.style(f"App not found for health summary generation app_id {health_summary_app_id}", fg="yellow") click.style(f"App not found for health summary generation app_id {health_summary_app_id}", fg="yellow")

Loading…
Cancel
Save