From ab775bce269859887c657c55d741d05506680ebb Mon Sep 17 00:00:00 2001 From: Harry Date: Fri, 18 Jul 2025 14:47:08 +0800 Subject: [PATCH] feat: remove BuiltinDatasourceProvider class and related credential handling --- ...18_1446-1bce102aef9a_datasource_oauth_2.py | 39 +++++++++++++++++++ api/models/tools.py | 35 ----------------- 2 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 api/migrations/versions/2025_07_18_1446-1bce102aef9a_datasource_oauth_2.py diff --git a/api/migrations/versions/2025_07_18_1446-1bce102aef9a_datasource_oauth_2.py b/api/migrations/versions/2025_07_18_1446-1bce102aef9a_datasource_oauth_2.py new file mode 100644 index 0000000000..33a45b7870 --- /dev/null +++ b/api/migrations/versions/2025_07_18_1446-1bce102aef9a_datasource_oauth_2.py @@ -0,0 +1,39 @@ +"""datasource_oauth_2 + +Revision ID: 1bce102aef9a +Revises: d4a76fde2724 +Create Date: 2025-07-18 14:46:11.392061 + +""" +from alembic import op +import models as models +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '1bce102aef9a' +down_revision = 'd4a76fde2724' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('tool_builtin_datasource_providers') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('tool_builtin_datasource_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=True), + sa.Column('user_id', sa.UUID(), autoincrement=False, nullable=False), + sa.Column('provider', sa.VARCHAR(length=256), autoincrement=False, nullable=False), + sa.Column('encrypted_credentials', sa.TEXT(), autoincrement=False, nullable=True), + 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=op.f('tool_builtin_datasource_provider_pkey')), + sa.UniqueConstraint('tenant_id', 'provider', name=op.f('unique_builtin_datasource_provider'), postgresql_include=[], postgresql_nulls_not_distinct=False) + ) + # ### end Alembic commands ### diff --git a/api/models/tools.py b/api/models/tools.py index b04ce6c5e9..1ed080ea23 100644 --- a/api/models/tools.py +++ b/api/models/tools.py @@ -98,41 +98,6 @@ class BuiltinToolProvider(Base): def credentials(self) -> dict: return cast(dict, json.loads(self.encrypted_credentials)) - -class BuiltinDatasourceProvider(Base): - """ - This table stores the datasource provider information for built-in datasources for each tenant. - """ - - __tablename__ = "tool_builtin_datasource_providers" - __table_args__ = ( - db.PrimaryKeyConstraint("id", name="tool_builtin_datasource_provider_pkey"), - # one tenant can only have one tool provider with the same name - db.UniqueConstraint("tenant_id", "provider", name="unique_builtin_datasource_provider"), - ) - - # id of the tool provider - id: Mapped[str] = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()")) - # id of the tenant - tenant_id: Mapped[str] = mapped_column(StringUUID, nullable=True) - # who created this tool provider - user_id: Mapped[str] = mapped_column(StringUUID, nullable=False) - # name of the tool provider - provider: Mapped[str] = mapped_column(db.String(256), nullable=False) - # credential of the tool provider - encrypted_credentials: Mapped[str] = mapped_column(db.Text, nullable=True) - created_at: Mapped[datetime] = mapped_column( - db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)") - ) - updated_at: Mapped[datetime] = mapped_column( - db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)") - ) - - @property - def credentials(self) -> dict: - return cast(dict, json.loads(self.encrypted_credentials)) - - class ApiToolProvider(Base): """ The table stores the api providers.