forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(db): use a better way to export models and remove unused table (l…
…anggenius#11838) Signed-off-by: -LAN- <laipz8200@outlook.com>
- Loading branch information
Showing
19 changed files
with
212 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
api/migrations/versions/2024_12_19_1746-11b07f66c737_remove_unused_tool_providers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""remove unused tool_providers | ||
Revision ID: 11b07f66c737 | ||
Revises: cf8f4fc45278 | ||
Create Date: 2024-12-19 17:46:25.780116 | ||
""" | ||
from alembic import op | ||
import models as models | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '11b07f66c737' | ||
down_revision = 'cf8f4fc45278' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('tool_providers') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('tool_providers', | ||
sa.Column('id', sa.UUID(), server_default=sa.text('uuid_generate_v4()'), autoincrement=False, nullable=False), | ||
sa.Column('tenant_id', sa.UUID(), autoincrement=False, nullable=False), | ||
sa.Column('tool_name', sa.VARCHAR(length=40), autoincrement=False, nullable=False), | ||
sa.Column('encrypted_credentials', sa.TEXT(), autoincrement=False, nullable=True), | ||
sa.Column('is_enabled', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False), | ||
sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False), | ||
sa.Column('updated_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), autoincrement=False, nullable=False), | ||
sa.PrimaryKeyConstraint('id', name='tool_provider_pkey'), | ||
sa.UniqueConstraint('tenant_id', 'tool_name', name='unique_tool_provider_tool_name') | ||
) | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,187 @@ | ||
from .account import Account, AccountIntegrate, InvitationCode, Tenant | ||
from .dataset import Dataset, DatasetProcessRule, Document, DocumentSegment | ||
from .account import ( | ||
Account, | ||
AccountIntegrate, | ||
AccountStatus, | ||
InvitationCode, | ||
Tenant, | ||
TenantAccountJoin, | ||
TenantAccountJoinRole, | ||
TenantAccountRole, | ||
TenantStatus, | ||
) | ||
from .api_based_extension import APIBasedExtension, APIBasedExtensionPoint | ||
from .dataset import ( | ||
AppDatasetJoin, | ||
Dataset, | ||
DatasetCollectionBinding, | ||
DatasetKeywordTable, | ||
DatasetPermission, | ||
DatasetPermissionEnum, | ||
DatasetProcessRule, | ||
DatasetQuery, | ||
Document, | ||
DocumentSegment, | ||
Embedding, | ||
ExternalKnowledgeApis, | ||
ExternalKnowledgeBindings, | ||
TidbAuthBinding, | ||
Whitelist, | ||
) | ||
from .engine import db | ||
from .enums import CreatedByRole, UserFrom, WorkflowRunTriggeredFrom | ||
from .model import ( | ||
ApiRequest, | ||
ApiToken, | ||
App, | ||
AppAnnotationHitHistory, | ||
AppAnnotationSetting, | ||
AppMode, | ||
AppModelConfig, | ||
Conversation, | ||
DatasetRetrieverResource, | ||
DifySetup, | ||
EndUser, | ||
IconType, | ||
InstalledApp, | ||
Message, | ||
MessageAgentThought, | ||
MessageAnnotation, | ||
MessageChain, | ||
MessageFeedback, | ||
MessageFile, | ||
OperationLog, | ||
RecommendedApp, | ||
Site, | ||
Tag, | ||
TagBinding, | ||
TraceAppConfig, | ||
UploadFile, | ||
) | ||
from .source import DataSourceOauthBinding | ||
from .tools import ToolFile | ||
from .provider import ( | ||
LoadBalancingModelConfig, | ||
Provider, | ||
ProviderModel, | ||
ProviderModelSetting, | ||
ProviderOrder, | ||
ProviderQuotaType, | ||
ProviderType, | ||
TenantDefaultModel, | ||
TenantPreferredModelProvider, | ||
) | ||
from .source import DataSourceApiKeyAuthBinding, DataSourceOauthBinding | ||
from .task import CeleryTask, CeleryTaskSet | ||
from .tools import ( | ||
ApiToolProvider, | ||
BuiltinToolProvider, | ||
PublishedAppTool, | ||
ToolConversationVariables, | ||
ToolFile, | ||
ToolLabelBinding, | ||
ToolModelInvoke, | ||
WorkflowToolProvider, | ||
) | ||
from .web import PinnedConversation, SavedMessage | ||
from .workflow import ( | ||
ConversationVariable, | ||
Workflow, | ||
WorkflowAppLog, | ||
WorkflowAppLogCreatedFrom, | ||
WorkflowNodeExecution, | ||
WorkflowNodeExecutionStatus, | ||
WorkflowNodeExecutionTriggeredFrom, | ||
WorkflowRun, | ||
WorkflowRunStatus, | ||
WorkflowType, | ||
) | ||
|
||
__all__ = [ | ||
"APIBasedExtension", | ||
"APIBasedExtensionPoint", | ||
"Account", | ||
"AccountIntegrate", | ||
"AccountStatus", | ||
"ApiRequest", | ||
"ApiToken", | ||
"ApiToolProvider", # Added | ||
"App", | ||
"AppAnnotationHitHistory", | ||
"AppAnnotationSetting", | ||
"AppDatasetJoin", | ||
"AppMode", | ||
"AppModelConfig", | ||
"BuiltinToolProvider", # Added | ||
"CeleryTask", | ||
"CeleryTaskSet", | ||
"Conversation", | ||
"ConversationVariable", | ||
"CreatedByRole", | ||
"DataSourceApiKeyAuthBinding", | ||
"DataSourceOauthBinding", | ||
"Dataset", | ||
"DatasetCollectionBinding", | ||
"DatasetKeywordTable", | ||
"DatasetPermission", | ||
"DatasetPermissionEnum", | ||
"DatasetProcessRule", | ||
"DatasetQuery", | ||
"DatasetRetrieverResource", | ||
"DifySetup", | ||
"Document", | ||
"DocumentSegment", | ||
"Embedding", | ||
"EndUser", | ||
"ExternalKnowledgeApis", | ||
"ExternalKnowledgeBindings", | ||
"IconType", | ||
"InstalledApp", | ||
"InvitationCode", | ||
"LoadBalancingModelConfig", | ||
"Message", | ||
"MessageAgentThought", | ||
"MessageAnnotation", | ||
"MessageChain", | ||
"MessageFeedback", | ||
"MessageFile", | ||
"OperationLog", | ||
"PinnedConversation", | ||
"Provider", | ||
"ProviderModel", | ||
"ProviderModelSetting", | ||
"ProviderOrder", | ||
"ProviderQuotaType", | ||
"ProviderType", | ||
"PublishedAppTool", | ||
"RecommendedApp", | ||
"SavedMessage", | ||
"Site", | ||
"Tag", | ||
"TagBinding", | ||
"Tenant", | ||
"TenantAccountJoin", | ||
"TenantAccountJoinRole", | ||
"TenantAccountRole", | ||
"TenantDefaultModel", | ||
"TenantPreferredModelProvider", | ||
"TenantStatus", | ||
"TidbAuthBinding", | ||
"ToolConversationVariables", | ||
"ToolFile", | ||
"ToolLabelBinding", | ||
"ToolModelInvoke", | ||
"TraceAppConfig", | ||
"UploadFile", | ||
"UserFrom", | ||
"Whitelist", | ||
"Workflow", | ||
"WorkflowAppLog", | ||
"WorkflowAppLogCreatedFrom", | ||
"WorkflowNodeExecution", | ||
"WorkflowNodeExecutionStatus", | ||
"WorkflowNodeExecutionTriggeredFrom", | ||
"WorkflowRun", | ||
"WorkflowRunStatus", | ||
"WorkflowRunTriggeredFrom", | ||
"WorkflowToolProvider", | ||
"WorkflowType", | ||
"db", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from flask_sqlalchemy import SQLAlchemy | ||
from sqlalchemy import MetaData | ||
|
||
POSTGRES_INDEXES_NAMING_CONVENTION = { | ||
"ix": "%(column_0_label)s_idx", | ||
"uq": "%(table_name)s_%(column_0_name)s_key", | ||
"ck": "%(table_name)s_%(constraint_name)s_check", | ||
"fk": "%(table_name)s_%(column_0_name)s_fkey", | ||
"pk": "%(table_name)s_pkey", | ||
} | ||
|
||
metadata = MetaData(naming_convention=POSTGRES_INDEXES_NAMING_CONVENTION) | ||
db = SQLAlchemy(metadata=metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.