feat(snippets): 한글 설명 초안 143개·새 이름 11개 검토 파일 + import_snippets 는 빈 DB 에서만(규칙 변경 후 중복·옛 이름 부활 방지)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
lee-hyeon-cheol
2026-09-23 13:46:17 +09:00
co-authored by Claude Opus 5.5
parent 7a1498a791
commit f0520cdcc1
4 changed files with 188 additions and 5 deletions
@@ -1,6 +1,10 @@
"""옛 로컬 snippets.db(SQLite) → 서버. 같은 이름은 건너뜀(--overwrite 로 덮어씀).
"""옛 로컬 snippets.db(SQLite) → 서버. **스니펫이 하나도 없을 때만**(처음 채우기). --force 면 비어 있지 않아도.
python manage.py import_snippets ../CODE_ASSISTANT_DB/snippets.db
deploy.sh 가 배포 때마다 부르므로, 이미 채워진 DB 에서 다시 돌면 안 됨 —
2026-09-23: 이름 규칙이 바뀐 뒤 다시 돌면 옛 이름(IF_SUBRC-ABAP)이 새 규칙 이름(IF_SUBRC_ABAP)으로 중복 추가되고,
apply_snippet_meta 로 이름을 바꾼 뒤엔 옛 이름이 되살아났음. 이름은 옛 규칙 그대로 둠(lookup_name).
"""
import sqlite3
@@ -8,7 +12,7 @@ import sqlite3
from django.core.management.base import BaseCommand
from apps.snippets.models import Snippet
from apps.snippets.views import normalize_name
from apps.snippets.views import lookup_name
class Command(BaseCommand):
@@ -17,13 +21,17 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("path")
parser.add_argument("--overwrite", action="store_true")
parser.add_argument("--force", action="store_true", help="스니펫이 이미 있어도 가져옴")
def handle(self, path, overwrite, **_):
def handle(self, path, overwrite, force, **_):
if Snippet.objects.exists() and not force:
self.stdout.write(f"이미 스니펫 {Snippet.objects.count()}개 있음 — 건너뜀(처음 채울 때만 씀, 필요하면 --force)")
return
con = sqlite3.connect(path)
rows = con.execute("SELECT name, desc, body, category FROM snippets").fetchall()
added = updated = skipped = 0
for name, desc, body, category in rows:
name = normalize_name(name)
name = lookup_name(name)
if not name or not (body or "").strip():
skipped += 1
continue
+4 -1
View File
@@ -49,8 +49,11 @@ def test_import_from_sqlite(db, tmp_path):
call_command("import_snippets", str(p))
names = {s.name: s for s in Snippet.objects.all()}
assert set(names) == {"A_B", "C"} and names["C"].category == "코드"
call_command("import_snippets", str(p)) # 재실행해도 중복 없음
call_command("import_snippets", str(p)) # 이미 있으면 건너뜀 — 배포마다 돌아도 안전
assert Snippet.objects.count() == 2
Snippet.objects.create(name="LEGACY-ABAP", body="x")
call_command("import_snippets", str(p))
assert not Snippet.objects.filter(name="LEGACY_ABAP").exists() # 새 규칙 이름으로 중복 생기지 않음
def test_legacy_name_still_editable(auth_api, user):