Skip to content

Commit 14b17c5

Browse files
committed
feat: DBMS -> DB -> SCHEMA -> TABLE -> COLUMN 계층 조회 구현
1 parent e519419 commit 14b17c5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

app/api/user_db_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from app.core.response import ResponseMessage
88
from app.core.status import CommonCode
99
from app.schemas.user_db.db_profile_model import DBProfileInfo, UpdateOrCreateDBProfile
10-
from app.schemas.user_db.result_model import ColumnInfo, DBProfile, SchemaDetail, TableInfo
10+
from app.schemas.user_db.result_model import ColumnInfo, DBDetail, DBProfile, TableInfo
1111
from app.services.user_db_service import UserDbService, user_db_service
1212

1313
user_db_service_dependency = Depends(lambda: user_db_service)
@@ -160,13 +160,13 @@ def find_all_schema_info(
160160

161161
@router.get(
162162
"/find/hierarchical-schema/{profile_id}",
163-
response_model=ResponseMessage[list[SchemaDetail]],
163+
response_model=ResponseMessage[DBDetail],
164164
summary="특정 DB의 전체 스키마의 계층적 상세 정보 조회",
165165
description="스키마, 테이블, 컬럼, 제약조건, 인덱스를 포함한 모든 스키마 정보를 계층 구조로 반환합니다.",
166166
)
167167
def find_hierarchical_schema_info(
168168
profile_id: str, service: UserDbService = user_db_service_dependency
169-
) -> ResponseMessage[list[SchemaDetail]]:
169+
) -> ResponseMessage[DBDetail]:
170170
db_info = service.find_profile(profile_id)
171171
hierarchical_schema_info = service.get_hierarchical_schema_info(db_info)
172172

app/schemas/user_db/result_model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ class SchemaDetail(BaseModel):
118118

119119
schema_name: str = Field(..., description="스키마 이름")
120120
tables: list[TableInfo] = Field([], description="테이블 목록")
121+
122+
123+
class DBDetail(BaseModel):
124+
"""계층적 조회에서 DB 정보를 담는 모델 (스키마 포함)"""
125+
126+
db_name: str | None = Field(None, description="데이터베이스 이름")
127+
db_type: str = Field(..., description="데이터베이스 종류")
128+
schemas: list[SchemaDetail] = Field([], description="스키마 목록")

app/services/user_db_service.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
BasicResult,
2020
ChangeProfileResult,
2121
ColumnListResult,
22+
DBDetail,
2223
SchemaDetail,
2324
SchemaInfoResult,
2425
TableInfo,
@@ -220,7 +221,7 @@ def get_full_schema_info(
220221

221222
def get_hierarchical_schema_info(
222223
self, db_info: AllDBProfileInfo, repository: UserDbRepository = user_db_repository
223-
) -> list[SchemaDetail]:
224+
) -> DBDetail:
224225
"""
225226
DB 프로필 정보를 받아 해당 데이터베이스의 전체 스키마 정보를
226227
계층적인 구조 (스키마 -> 테이블 -> 컬럼 등)로 조회하여 반환합니다.
@@ -243,7 +244,7 @@ def get_hierarchical_schema_info(
243244
if db_info.type.lower() == "sqlite" and not schemas_to_scan:
244245
schemas_to_scan = ["main"]
245246

246-
hierarchical_schema_info = []
247+
schema_details = []
247248
for schema_name in sorted(schemas_to_scan):
248249
# For Oracle, schema names are uppercase.
249250
effective_schema_name = schema_name
@@ -269,10 +270,10 @@ def get_hierarchical_schema_info(
269270
table_details.append(table_info)
270271

271272
if table_details:
272-
hierarchical_schema_info.append(SchemaDetail(schema_name=schema_name, tables=table_details))
273+
schema_details.append(SchemaDetail(schema_name=schema_name, tables=table_details))
273274

274-
logging.info(f"Finished hierarchical schema scan. Total schemas found: {len(hierarchical_schema_info)}.")
275-
return hierarchical_schema_info
275+
logging.info(f"Finished hierarchical schema scan. Total schemas found: {len(schema_details)}.")
276+
return DBDetail(db_name=db_info.name, db_type=db_info.type, schemas=schema_details)
276277
except APIException:
277278
raise
278279
except Exception as e:

0 commit comments

Comments
 (0)