fix: P001, P002 약국 보호 로직 추가

문제:
- cleanup 스크립트가 P0003 이후 삭제 시 P001, P002도 함께 삭제됨
- 문자열 비교 'P001' >= 'P0003'이 true로 평가됨

원인:
- SQLite 문자열 비교에서 'P001' < 'P0003'이지만
- 'P002' >= 'P0003'은 false인데, 기존 조건이 잘못됨

해결:
- LENGTH(pharmacy_code) = 5 조건 추가
- P0003 <= pharmacy_code <= P9999 범위 명시
- P001, P002 (4자), P0001, P0002 (5자) 모두 보호

변경 파일:
- cleanup-test-data.sh: 삭제 쿼리 수정
- CLEANUP_TEST_DATA.md: 문서 업데이트

보호되는 약국:
- P001: default 약국 (4자)
- P002: 새서울약국 (4자)
- P0002: 청춘약국 (5자, 범위 밖)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude 2025-11-14 10:53:59 +00:00
parent e7485983cc
commit ae1782a6de
2 changed files with 6 additions and 5 deletions

View File

@ -30,9 +30,9 @@ cursor.execute('SELECT pharmacy_code, pharmacy_name, tailscale_ip FROM pharmacie
for row in cursor.fetchall():
print(f' {row[0]}: {row[1]} - {row[2]}')
# P0003 이후 약국 삭제 (테스트 데이터)
# P0003~P9999 약국 삭제 (P001, P002, P0001, P0002는 보호)
print('\nP0003 이후 약국 삭제 중...')
cursor.execute("DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code < 'P1000'")
cursor.execute("DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code <= 'P9999' AND LENGTH(pharmacy_code) = 5")
deleted_count = cursor.rowcount
conn.commit()
@ -199,9 +199,9 @@ curl -fsSL https://raw.githubusercontent.com/thug0bin/pve9-repo-fix/main/cleanup
### 시나리오 1: 전체 테스트 데이터 정리
```bash
# 1. farmq.db 정리 (P0003 이후)
# 1. farmq.db 정리 (P0003~P9999, P001/P002 보호)
cd /srv/headscale-tailscale-replacement/farmq-admin
python3 -c "import sqlite3; conn = sqlite3.connect('farmq.db'); cursor = conn.cursor(); cursor.execute(\"DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code < 'P1000'\"); conn.commit(); print(f'✓ {cursor.rowcount}개 약국 삭제'); conn.close()"
python3 -c "import sqlite3; conn = sqlite3.connect('farmq.db'); cursor = conn.cursor(); cursor.execute(\"DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code <= 'P9999' AND LENGTH(pharmacy_code) = 5\"); conn.commit(); print(f'✓ {cursor.rowcount}개 약국 삭제'); conn.close()"
# 2. gateway.db 정리 (ID 5 이후)
cd /srv/pharmq-gateway

View File

@ -64,7 +64,8 @@ EOF
import sqlite3
conn = sqlite3.connect('$FARMQ_DB')
cursor = conn.cursor()
cursor.execute("DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code < 'P1000'")
# P0003~P9999만 삭제 (P001, P002, P0001, P0002는 보호)
cursor.execute("DELETE FROM pharmacies WHERE pharmacy_code >= 'P0003' AND pharmacy_code <= 'P9999' AND LENGTH(pharmacy_code) = 5")
deleted_count = cursor.rowcount
conn.commit()
conn.close()