mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-08 02:16:51 +08:00
Feat/assistant app (#2086)
Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: Pascal M <11357019+perzeuss@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""rename api provider description
|
||||
|
||||
Revision ID: 00bacef91f18
|
||||
Revises: 8ec536f3c800
|
||||
Create Date: 2024-01-07 04:07:34.482983
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '00bacef91f18'
|
||||
down_revision = '8ec536f3c800'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('description', sa.Text(), nullable=False))
|
||||
batch_op.drop_column('description_str')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('description_str', sa.TEXT(), autoincrement=False, nullable=False))
|
||||
batch_op.drop_column('description')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
51
api/migrations/versions/053da0c1d756_add_api_tool_privacy.py
Normal file
51
api/migrations/versions/053da0c1d756_add_api_tool_privacy.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""add api tool privacy
|
||||
|
||||
Revision ID: 053da0c1d756
|
||||
Revises: 4829e54d2fee
|
||||
Create Date: 2024-01-12 06:47:21.656262
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '053da0c1d756'
|
||||
down_revision = '4829e54d2fee'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('tool_conversation_variables',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('conversation_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('variables_str', sa.Text(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name='tool_conversation_variables_pkey')
|
||||
)
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('privacy_policy', sa.String(length=255), nullable=True))
|
||||
batch_op.alter_column('icon',
|
||||
existing_type=sa.VARCHAR(length=256),
|
||||
type_=sa.String(length=255),
|
||||
existing_nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.alter_column('icon',
|
||||
existing_type=sa.String(length=255),
|
||||
type_=sa.VARCHAR(length=256),
|
||||
existing_nullable=False)
|
||||
batch_op.drop_column('privacy_policy')
|
||||
|
||||
op.drop_table('tool_conversation_variables')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,32 @@
|
||||
"""remove tool id from model invoke
|
||||
|
||||
Revision ID: 114eed84c228
|
||||
Revises: c71211c8f604
|
||||
Create Date: 2024-01-10 04:40:57.257824
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '114eed84c228'
|
||||
down_revision = 'c71211c8f604'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
|
||||
batch_op.drop_column('tool_id')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_model_invokes', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('tool_id', postgresql.UUID(), autoincrement=False, nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,32 @@
|
||||
"""add message files into agent thought
|
||||
|
||||
Revision ID: 23db93619b9d
|
||||
Revises: 8ae9bc661daa
|
||||
Create Date: 2024-01-18 08:46:37.302657
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '23db93619b9d'
|
||||
down_revision = '8ae9bc661daa'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('message_files', sa.Text(), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
|
||||
batch_op.drop_column('message_files')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
67
api/migrations/versions/3ef9b2b6bee6_add_assistant_app.py
Normal file
67
api/migrations/versions/3ef9b2b6bee6_add_assistant_app.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""add_assistant_app
|
||||
|
||||
Revision ID: 3ef9b2b6bee6
|
||||
Revises: 89c7899ca936
|
||||
Create Date: 2024-01-05 15:26:25.117551
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3ef9b2b6bee6'
|
||||
down_revision = '89c7899ca936'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('tool_api_providers',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('name', sa.String(length=40), nullable=False),
|
||||
sa.Column('schema', sa.Text(), nullable=False),
|
||||
sa.Column('schema_type_str', sa.String(length=40), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('description_str', sa.Text(), nullable=False),
|
||||
sa.Column('tools_str', sa.Text(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name='tool_api_provider_pkey')
|
||||
)
|
||||
op.create_table('tool_builtin_providers',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(), nullable=True),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('provider', sa.String(length=40), nullable=False),
|
||||
sa.Column('encrypted_credentials', sa.Text(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name='tool_builtin_provider_pkey'),
|
||||
sa.UniqueConstraint('tenant_id', 'provider', name='unique_builtin_tool_provider')
|
||||
)
|
||||
op.create_table('tool_published_apps',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('app_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=False),
|
||||
sa.Column('llm_description', sa.Text(), nullable=False),
|
||||
sa.Column('query_description', sa.Text(), nullable=False),
|
||||
sa.Column('query_name', sa.String(length=40), nullable=False),
|
||||
sa.Column('tool_name', sa.String(length=40), nullable=False),
|
||||
sa.Column('author', sa.String(length=40), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], ),
|
||||
sa.PrimaryKeyConstraint('id', name='published_app_tool_pkey'),
|
||||
sa.UniqueConstraint('app_id', 'user_id', name='unique_published_app_tool')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('tool_published_apps')
|
||||
op.drop_table('tool_builtin_providers')
|
||||
op.drop_table('tool_api_providers')
|
||||
# ### end Alembic commands ###
|
||||
37
api/migrations/versions/4823da1d26cf_add_tool_file.py
Normal file
37
api/migrations/versions/4823da1d26cf_add_tool_file.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""add tool file
|
||||
|
||||
Revision ID: 4823da1d26cf
|
||||
Revises: 053da0c1d756
|
||||
Create Date: 2024-01-15 11:37:16.782718
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4823da1d26cf'
|
||||
down_revision = '053da0c1d756'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('tool_files',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('conversation_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('file_key', sa.String(length=255), nullable=False),
|
||||
sa.Column('mimetype', sa.String(length=255), nullable=False),
|
||||
sa.Column('original_url', sa.String(length=255), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id', name='tool_file_pkey')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('tool_files')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,36 @@
|
||||
"""change message chain id to nullable
|
||||
|
||||
Revision ID: 4829e54d2fee
|
||||
Revises: 114eed84c228
|
||||
Create Date: 2024-01-12 03:42:27.362415
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4829e54d2fee'
|
||||
down_revision = '114eed84c228'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
|
||||
batch_op.alter_column('message_chain_id',
|
||||
existing_type=postgresql.UUID(),
|
||||
nullable=True)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
|
||||
batch_op.alter_column('message_chain_id',
|
||||
existing_type=postgresql.UUID(),
|
||||
nullable=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,34 @@
|
||||
"""add tool conversation variables idx
|
||||
|
||||
Revision ID: 8ae9bc661daa
|
||||
Revises: 9fafbd60eca1
|
||||
Create Date: 2024-01-15 14:22:03.597692
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8ae9bc661daa'
|
||||
down_revision = '9fafbd60eca1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_conversation_variables', schema=None) as batch_op:
|
||||
batch_op.create_index('conversation_id_idx', ['conversation_id'], unique=False)
|
||||
batch_op.create_index('user_id_idx', ['user_id'], unique=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_conversation_variables', schema=None) as batch_op:
|
||||
batch_op.drop_index('user_id_idx')
|
||||
batch_op.drop_index('conversation_id_idx')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,32 @@
|
||||
"""rename api provider credentails
|
||||
|
||||
Revision ID: 8ec536f3c800
|
||||
Revises: ad472b61a054
|
||||
Create Date: 2024-01-07 03:57:35.257545
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8ec536f3c800'
|
||||
down_revision = 'ad472b61a054'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('credentials_str', sa.Text(), nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.drop_column('credentials_str')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,32 @@
|
||||
"""add message file belongs to
|
||||
|
||||
Revision ID: 9fafbd60eca1
|
||||
Revises: 4823da1d26cf
|
||||
Create Date: 2024-01-15 13:07:20.340896
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '9fafbd60eca1'
|
||||
down_revision = '4823da1d26cf'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_files', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('belongs_to', sa.String(length=255), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('message_files', schema=None) as batch_op:
|
||||
batch_op.drop_column('belongs_to')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,32 @@
|
||||
"""add api provider icon
|
||||
|
||||
Revision ID: ad472b61a054
|
||||
Revises: 3ef9b2b6bee6
|
||||
Create Date: 2024-01-07 02:21:23.114790
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ad472b61a054'
|
||||
down_revision = '3ef9b2b6bee6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('icon', sa.String(length=256), nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.drop_column('icon')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,49 @@
|
||||
"""add tool_invoke_model_log
|
||||
|
||||
Revision ID: c71211c8f604
|
||||
Revises: f25003750af4
|
||||
Create Date: 2024-01-09 11:42:50.664797
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'c71211c8f604'
|
||||
down_revision = 'f25003750af4'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('tool_model_invokes',
|
||||
sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
|
||||
sa.Column('user_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('provider', sa.String(length=40), nullable=False),
|
||||
sa.Column('tool_type', sa.String(length=40), nullable=False),
|
||||
sa.Column('tool_name', sa.String(length=40), nullable=False),
|
||||
sa.Column('tool_id', postgresql.UUID(), nullable=False),
|
||||
sa.Column('model_parameters', sa.Text(), nullable=False),
|
||||
sa.Column('prompt_messages', sa.Text(), nullable=False),
|
||||
sa.Column('model_response', sa.Text(), nullable=False),
|
||||
sa.Column('prompt_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
|
||||
sa.Column('answer_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
|
||||
sa.Column('answer_unit_price', sa.Numeric(precision=10, scale=4), nullable=False),
|
||||
sa.Column('answer_price_unit', sa.Numeric(precision=10, scale=7), server_default=sa.text('0.001'), nullable=False),
|
||||
sa.Column('provider_response_latency', sa.Float(), server_default=sa.text('0'), nullable=False),
|
||||
sa.Column('total_price', sa.Numeric(precision=10, scale=7), nullable=True),
|
||||
sa.Column('currency', sa.String(length=255), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name='tool_model_invoke_pkey')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('tool_model_invokes')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,109 @@
|
||||
"""migration serpapi_api_key
|
||||
|
||||
Revision ID: de95f5c77138
|
||||
Revises: 23db93619b9d
|
||||
Create Date: 2024-01-21 12:09:04.651394
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from json import dumps, loads
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'de95f5c77138'
|
||||
down_revision = '23db93619b9d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
"""
|
||||
1. select all tool_providers
|
||||
2. insert api_key to tool_provider_configs
|
||||
|
||||
tool_providers
|
||||
- id
|
||||
- tenant_id
|
||||
- tool_name
|
||||
- encrypted_credentials
|
||||
{"api_key": "$KEY"}
|
||||
- created_at
|
||||
- updated_at
|
||||
|
||||
tool_builtin_providers
|
||||
- id <- tool_providers.id
|
||||
- tenant_id <- tool_providers.tenant_id
|
||||
- user_id <- tenant_account_joins.account_id (tenant_account_joins.tenant_id = tool_providers.tenant_id and tenant_account_joins.role = 'owner')
|
||||
- encrypted_credentials <- tool_providers.encrypted_credentials
|
||||
{"serpapi_api_key": "$KEY"}
|
||||
- created_at <- tool_providers.created_at
|
||||
- updated_at <- tool_providers.updated_at
|
||||
|
||||
"""
|
||||
# select all tool_providers
|
||||
tool_providers = op.get_bind().execute(
|
||||
sa.text(
|
||||
"SELECT * FROM tool_providers WHERE tool_name = 'serpapi'"
|
||||
)
|
||||
).fetchall()
|
||||
|
||||
# insert api_key to tool_provider_configs
|
||||
for tool_provider in tool_providers:
|
||||
id = tool_provider['id']
|
||||
tenant_id = tool_provider['tenant_id']
|
||||
encrypted_credentials = tool_provider['encrypted_credentials']
|
||||
|
||||
try:
|
||||
credentials = loads(encrypted_credentials)
|
||||
api_key = credentials['api_key']
|
||||
credentials['serpapi_api_key'] = api_key
|
||||
credentials.pop('api_key')
|
||||
encrypted_credentials = dumps(credentials)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
|
||||
# get user_id
|
||||
user_id = op.get_bind().execute(
|
||||
sa.text(
|
||||
"SELECT account_id FROM tenant_account_joins WHERE tenant_id = :tenant_id AND role = 'owner'"
|
||||
),
|
||||
tenant_id=tenant_id
|
||||
).fetchone()['account_id']
|
||||
|
||||
created_at = tool_provider['created_at']
|
||||
updated_at = tool_provider['updated_at']
|
||||
|
||||
# insert to tool_builtin_providers
|
||||
# check if exists
|
||||
exists = op.get_bind().execute(
|
||||
sa.text(
|
||||
"SELECT * FROM tool_builtin_providers WHERE tenant_id = :tenant_id AND provider = 'google'"
|
||||
),
|
||||
tenant_id=tenant_id
|
||||
).fetchone()
|
||||
if exists:
|
||||
continue
|
||||
|
||||
op.get_bind().execute(
|
||||
sa.text(
|
||||
"INSERT INTO tool_builtin_providers (id, tenant_id, user_id, provider, encrypted_credentials, created_at, updated_at) VALUES (:id, :tenant_id, :user_id, :provider, :encrypted_credentials, :created_at, :updated_at)"
|
||||
),
|
||||
id=id,
|
||||
tenant_id=tenant_id,
|
||||
user_id=user_id,
|
||||
provider='google',
|
||||
encrypted_credentials=encrypted_credentials,
|
||||
created_at=created_at,
|
||||
updated_at=updated_at
|
||||
)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,34 @@
|
||||
"""add created/updated at
|
||||
|
||||
Revision ID: f25003750af4
|
||||
Revises: 00bacef91f18
|
||||
Create Date: 2024-01-07 04:53:24.441861
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f25003750af4'
|
||||
down_revision = '00bacef91f18'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False))
|
||||
batch_op.add_column(sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('tool_api_providers', schema=None) as batch_op:
|
||||
batch_op.drop_column('updated_at')
|
||||
batch_op.drop_column('created_at')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user