mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: add table relation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""044_table_relation
|
||||
|
||||
Revision ID: 455b8ce69e80
|
||||
Revises: dac062c1f7b1
|
||||
Create Date: 2025-09-24 13:34:08.205659
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel.sql.sqltypes
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '455b8ce69e80'
|
||||
down_revision = 'dac062c1f7b1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('core_datasource', sa.Column('table_relation', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('core_datasource', 'table_relation')
|
||||
# ### end Alembic commands ###
|
||||
+5
-6
@@ -1,12 +1,12 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from apps.terminology.api import terminology
|
||||
from apps.data_training.api import data_training
|
||||
from apps.chat.api import chat
|
||||
from apps.dashboard.api import dashboard_api
|
||||
from apps.datasource.api import datasource
|
||||
from apps.system.api import login, user, aimodel, workspace, assistant
|
||||
from apps.data_training.api import data_training
|
||||
from apps.datasource.api import datasource, table_relation
|
||||
from apps.mcp import mcp
|
||||
from apps.system.api import login, user, aimodel, workspace, assistant
|
||||
from apps.terminology.api import terminology
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(login.router)
|
||||
@@ -20,5 +20,4 @@ api_router.include_router(datasource.router)
|
||||
api_router.include_router(chat.router)
|
||||
api_router.include_router(dashboard_api.router)
|
||||
api_router.include_router(mcp.router)
|
||||
|
||||
|
||||
api_router.include_router(table_relation.router)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Author: Junjun
|
||||
# Date: 2025/9/24
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from apps.datasource.models.datasource import CoreDatasource
|
||||
from common.core.deps import SessionDep
|
||||
|
||||
router = APIRouter(tags=["table_relation"], prefix="/table_relation")
|
||||
|
||||
|
||||
@router.post("/save/{ds_id}")
|
||||
async def save_relation(session: SessionDep, ds_id: int, relation: List[dict]):
|
||||
ds = session.get(CoreDatasource, ds_id)
|
||||
if ds:
|
||||
ds.table_relation = relation
|
||||
session.commit()
|
||||
else:
|
||||
raise Exception("no datasource")
|
||||
return True
|
||||
|
||||
|
||||
@router.post("/get/{ds_id}")
|
||||
async def save_relation(session: SessionDep, ds_id: int):
|
||||
ds = session.get(CoreDatasource, ds_id)
|
||||
if ds:
|
||||
return ds.table_relation if ds.table_relation else []
|
||||
return []
|
||||
@@ -2,7 +2,8 @@ from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import Column, Text, BigInteger, DateTime, Integer, Identity
|
||||
from sqlalchemy import Column, Text, BigInteger, DateTime, Identity
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlmodel import SQLModel, Field
|
||||
|
||||
|
||||
@@ -19,6 +20,7 @@ class CoreDatasource(SQLModel, table=True):
|
||||
status: str = Field(max_length=64, nullable=True)
|
||||
num: str = Field(max_length=256, nullable=True)
|
||||
oid: int = Field(sa_column=Column(BigInteger()))
|
||||
table_relation: List = Field(sa_column=Column(JSONB, nullable=True))
|
||||
|
||||
|
||||
class CoreTable(SQLModel, table=True):
|
||||
|
||||
Reference in New Issue
Block a user