PostgreSQL 테이블 실제 구조와 코드 불일치 문서화
- 테이블명 불일치: user vs users, 단수형 vs 복수형 - 존재하지 않는 테이블: slack_user_mapping, gmail_audit_logs 등 - 구조 차이: workspace 중심 vs company-team 계층 - 비어있는 테이블 명시
This commit is contained in:
parent
6fc88d2a6d
commit
30b6d7e444
@ -24,10 +24,11 @@
|
||||
|
||||
## 2. 테이블별 사용 위치 상세
|
||||
|
||||
### 2.1 users 테이블
|
||||
**컬럼**:
|
||||
- auth-server 모델: id(UUID), username, email, name, **picture**, **oauth_provider**, **oauth_id**, is_active, created_at, updated_at, last_login_at
|
||||
- robeing-gateway 모델: id(UUID), email, name, **avatar_url**, **provider**, **provider_id**, created_at, updated_at (username 없음)
|
||||
### 2.1 user 테이블 (실제 DB: user, 코드: users 참조)
|
||||
**실제 DB 컬럼**: id(UUID), team_id(FK), email, username, oauth_provider, oauth_id, created_at, updated_at
|
||||
**코드 모델 차이**:
|
||||
- auth-server: picture 컬럼 (DB에 없음)
|
||||
- robeing-gateway: avatar_url, provider, provider_id (DB에 없음)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -39,8 +40,9 @@
|
||||
| robeing-gateway/app/database.py | 321-328 | SELECT * FROM users (전체 조회) |
|
||||
| robeing-gateway/app/models.py | 11-24 | 테이블 모델 정의 (avatar_url 컬럼) |
|
||||
|
||||
### 2.2 workspaces 테이블
|
||||
**컬럼**: id(UUID), name, subdomain, robeing_id, robeing_port, robeing_url, max_members, workspace_type, status, created_at, updated_at
|
||||
### 2.2 company/team 테이블 (실제 DB: company+team, 코드: workspaces 참조)
|
||||
**실제 DB**: company(id, name, url) + team(id, company_id, name) 구조
|
||||
**코드 모델**: workspaces 테이블 참조 (DB에 없음)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -51,9 +53,9 @@
|
||||
| robeing-gateway/app/database.py | 216-230 | JOIN 쿼리 (workspace_members와 함께) |
|
||||
| robeing-gateway/app/models.py | 26-44 | 테이블 모델 정의 |
|
||||
|
||||
### 2.3 workspace_members 테이블
|
||||
**컬럼**: id(UUID), workspace_id(FK), user_id(FK), role, robeing_id, robeing_url, is_active, joined_at, updated_at
|
||||
**주의**: role 타입이 auth-server는 Enum(UserRole), robeing-gateway는 String(50)
|
||||
### 2.3 workspace_member 테이블 (실제 DB: workspace_member, 레코드 0건)
|
||||
**실제 DB 컬럼**: user_id(FK), role(user_role enum), created_at, updated_at
|
||||
**코드 모델**: workspace_members 테이블 참조 (복수형 차이)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -65,9 +67,8 @@
|
||||
| robeing-gateway/app/database.py | 285-299 | INSERT 쿼리 (gen_random_uuid() 사용) |
|
||||
| robeing-gateway/app/models.py | 46-60 | 테이블 모델 정의 |
|
||||
|
||||
### 2.4 slack_user_mapping 테이블
|
||||
**컬럼**: slack_user_id, slack_workspace_id, user_id, created_at, updated_at
|
||||
**제약조건**: UNIQUE(slack_user_id, slack_workspace_id), FK(user_id → users.id), FK(slack_workspace_id → slack_workspaces.id)
|
||||
### 2.4 slack_user_mapping 테이블 (실제 DB: 없음)
|
||||
**코드에서 참조하나 실제 DB에 테이블 없음**
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -76,9 +77,9 @@
|
||||
| rb8001/app/router/router.py | 92 | SELECT user_id FROM slack_user_mapping WHERE slack_user_id = :slack_id |
|
||||
| robeing-gateway/app/main.py | 479-486 | SELECT user_id FROM slack_user_mapping WHERE slack_user_id = $1 |
|
||||
|
||||
### 2.5 slack_workspaces 테이블
|
||||
**컬럼**: id(UUID), workspace_id(UUID), team_id, team_name, bot_token, bot_user_id, app_id, scopes(JSON), is_enterprise_install, is_active, installed_at, updated_at
|
||||
**주의**: 마이그레이션에서 company_id → workspace_id로 컬럼명 변경 정의됨
|
||||
### 2.5 slack_workspace 테이블 (실제 DB: slack_workspace, 2건)
|
||||
**실제 DB 컬럼**: id(UUID), team_id(FK), team_name, bot_token, bot_user_id, app_id, scope(json), created_at, updated_at
|
||||
**코드 모델**: slack_workspaces 참조 (복수형 차이)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -87,9 +88,9 @@
|
||||
| robeing-gateway/app/main.py | 522-525 | SELECT bot_token FROM slack_workspaces WHERE team_id = $1 |
|
||||
| robeing-gateway/app/main.py | 567-570 | SELECT bot_token FROM slack_workspaces WHERE team_id = $1 |
|
||||
|
||||
### 2.6 gmail_tokens 테이블
|
||||
**컬럼**: id, user_id, username, slack_user_id, robeing_id, token_data(JSON), access_token, refresh_token, oauth_config, scopes, expiry, is_equipped, equipped_to, created_at, updated_at
|
||||
**주의**: token_data(JSON) 컬럼과 개별 토큰 컬럼(access_token, refresh_token)이 병행 사용 중
|
||||
### 2.6 gmail_token 테이블 (실제 DB: gmail_token, 0건)
|
||||
**실제 DB 컬럼**: user_id(FK), token_data(jsonb), oauth_config(jsonb), created_at, updated_at
|
||||
**코드 모델**: gmail_tokens 참조 (복수형 차이), 추가 컬럼 사용
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -106,8 +107,8 @@
|
||||
| robeing-monitor/app/api/items.py | 307-319 | SELECT 쿼리 (장착된 토큰) |
|
||||
| robeing-monitor/app/api/items.py | 384-388 | DELETE 쿼리 |
|
||||
|
||||
### 2.7 gmail_audit_logs 테이블
|
||||
**컬럼**: user_id, robeing_id, action, success, details
|
||||
### 2.7 gmail_audit_logs 테이블 (실제 DB: 없음)
|
||||
**코드에서 참조하나 실제 DB에 테이블 없음**
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -115,8 +116,9 @@
|
||||
| robeing-monitor/app/api/items.py | 263-270 | INSERT 쿼리 |
|
||||
| robeing-monitor/app/api/items.py | 395-401 | INSERT 쿼리 |
|
||||
|
||||
### 2.8 robeing_stats 테이블
|
||||
**컬럼**: id, robeing_id, memory, compute, react, empathy, leadership, ethics, level, experience, stat_points, created_at, updated_at
|
||||
### 2.8 robeing 테이블 (실제 DB: robeing, 2건)
|
||||
**실제 DB 컬럼**: id(UUID), product_id(FK), team_id(FK), memory, compute, react, empathy, leadership, created_at, updated_at
|
||||
**코드 모델**: robeing_stats 테이블 참조 (테이블명 불일치)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -129,8 +131,8 @@
|
||||
| robeing-monitor/app/state/state_service.py | 215 | SELECT 전체 조회 |
|
||||
| robeing-monitor/app/api/items.py | 169-173 | SELECT level 쿼리 |
|
||||
|
||||
### 2.9 robeing_settings 테이블
|
||||
**컬럼**: id, robeing_id, company_name, workspace_id, preferences(JSON), created_at, updated_at
|
||||
### 2.9 robeing_settings 테이블 (실제 DB: 없음)
|
||||
**코드에서 참조하나 실제 DB에 테이블 없음**
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -140,10 +142,9 @@
|
||||
| robeing-monitor/app/state/state_service.py | 114-117 | INSERT 쿼리 |
|
||||
| robeing-monitor/app/state/state_service.py | 133 | SELECT 쿼리 |
|
||||
|
||||
### 2.10 conversation_logs 테이블
|
||||
**컬럼**:
|
||||
- rb8001 모델: id, robeing_id, user_id, **slack_user_id**, channel_id, message, response, intent, confidence, timestamp
|
||||
- robeing-monitor 모델: id, robeing_id, user_id, channel_id, message, response, intent, confidence, timestamp (slack_user_id 없음)
|
||||
### 2.10 conversation_log 테이블 (실제 DB: conversation_log, 0건)
|
||||
**실제 DB 컬럼**: user_id(FK), message, response, intent, created_at, updated_at
|
||||
**코드 모델**: conversation_logs 참조 (복수형 차이), 추가 컬럼 사용
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -155,8 +156,9 @@
|
||||
| robeing-monitor/app/state/state_service.py | 173-177 | SELECT 쿼리 (최근 로그, slack_user_id 없음) |
|
||||
| robeing-monitor/app/state/state_service.py | 194-203 | SELECT 쿼리 (7일간, slack_user_id 없음) |
|
||||
|
||||
### 2.11 user_preferences 테이블
|
||||
**컬럼**: user_id, slack_user_id, news_keywords, email_filter, briefing_enabled, briefing_time
|
||||
### 2.11 user_preference 테이블 (실제 DB: user_preference, 0건)
|
||||
**실제 DB 컬럼**: user_id(FK), slack_user_id, news_keywords[], briefing_enabled, briefing_time, created_at, updated_at
|
||||
**코드 모델**: user_preferences 참조 (복수형 차이)
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -166,8 +168,13 @@
|
||||
| robeing-monitor/app/api/monitor.py | 276-292 | UPDATE 쿼리 (동적 쿼리 생성) |
|
||||
| robeing-monitor/app/api/monitor.py | 309-316 | INSERT 쿼리 |
|
||||
|
||||
### 2.12 system_metrics 테이블
|
||||
**컬럼**: time, metric_type, value
|
||||
### 2.12 news 테이블 (실제 DB: news, 0건)
|
||||
**실제 DB 컬럼**: user_id(FK), data(jsonb), created_at, updated_at
|
||||
**코드 참조**: 확인 필요
|
||||
|
||||
### 2.13 product 테이블 (실제 DB: product, 1건)
|
||||
**실제 DB 컬럼**: id(UUID), name, app_id, scope(json), created_at, updated_at
|
||||
**코드 참조**: 확인 필요
|
||||
|
||||
| 파일 경로 | 라인 번호 | 작업 내용 |
|
||||
|-----------|-----------|-----------|
|
||||
@ -204,26 +211,30 @@
|
||||
- [ ] 데이터 마이그레이션 테스트
|
||||
- [ ] 롤백 계획 수립
|
||||
|
||||
## 4. 위험 요소
|
||||
## 4. 위험 요소 - 치명적 불일치
|
||||
|
||||
1. **다중 라이브러리 사용**: SQLAlchemy, asyncpg, psycopg2를 혼용하고 있어 일관성 있는 수정 필요
|
||||
2. **UUID 처리**: 일부는 문자열로, 일부는 UUID 타입으로 처리
|
||||
3. **JSON 컬럼**: preferences, scopes, oauth_config, token_data 등 JSON 타입 컬럼 처리 주의
|
||||
4. **외래키 관계**: workspace_members의 workspace_id, user_id FK 관계 유지
|
||||
5. **gen_random_uuid()**: PostgreSQL 함수 사용 부분 확인 필요
|
||||
6. **모델 불일치 - 심각**:
|
||||
- users: picture vs avatar_url, oauth_provider/oauth_id vs provider/provider_id
|
||||
- workspace_members: role이 Enum vs String(50)
|
||||
- conversation_logs: slack_user_id 유무
|
||||
- gmail_tokens: token_data(JSON) vs 개별 컬럼 병행
|
||||
7. **마이그레이션 충돌**: slack_workspaces의 company_id → workspace_id 변경이 모델과 불일치
|
||||
8. **복합 고유키**: slack_user_mapping의 (slack_user_id, slack_workspace_id) 조합 처리
|
||||
1. **테이블명 전체 불일치**:
|
||||
- 코드: users, workspaces, workspace_members (복수형)
|
||||
- DB: user, company/team, workspace_member (단수형)
|
||||
|
||||
2. **존재하지 않는 테이블 참조**:
|
||||
- slack_user_mapping (코드 참조, DB 없음)
|
||||
- gmail_audit_logs (코드 참조, DB 없음)
|
||||
- robeing_settings (코드 참조, DB 없음)
|
||||
- workspaces (코드 참조, DB는 company+team)
|
||||
|
||||
3. **구조 불일치**:
|
||||
- 코드: workspace 중심 구조
|
||||
- DB: company → team → user 계층 구조
|
||||
|
||||
4. **비어있는 주요 테이블** (레코드 0건):
|
||||
- conversation_log, gmail_token, news, user_preference, workspace_member
|
||||
|
||||
## 5. 작업 우선순위
|
||||
|
||||
1. **높음**: users, workspaces, workspace_members (핵심 인증/권한)
|
||||
2. **중간**: gmail_tokens, slack_user_mapping (통합 기능)
|
||||
3. **낮음**: robeing_stats, conversation_logs (부가 기능)
|
||||
1. **긴급**: 테이블명 불일치 해결 (user vs users 등)
|
||||
2. **높음**: 존재하지 않는 테이블 생성 또는 코드 수정
|
||||
3. **중간**: 컬럼 불일치 해결
|
||||
|
||||
## 6. 롤백 계획
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user