feat: 스니펫 공용화 — 서버 PostgreSQL 테이블 + API, 프론트는 브릿지 대신 HTTP
결정(9/21): 공용 하나, 개인 로컬 없음.
- backend apps/snippets: Snippet(name PK·desc·body·category) + SnippetUsage(사람별 count/last_used).
GET/POST /api/v1/snippets, PUT/DELETE /snippets/{name}, POST /snippets/{name}/use — 옛 브릿지 5개와 1:1,
이름 정규화·중복 409·빈 내용 400 규칙 동일. import_snippets 커맨드로 옛 snippets.db 적재. 테스트 3개
- frontend snippets.api.ts 만 HTTP 로 교체(훅·페이지·타입 무변경). 테스트 axios-mock-adapter 로
- ponytail: Tauri 로컬 SQLite 커맨드는 미사용 상태로 남김. 지울 때 Rust+브릿지 테스트 함께
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
df5feaad3a
commit
2e7bae4c06
@@ -0,0 +1,39 @@
|
||||
"""옛 로컬 snippets.db(SQLite) → 서버. 같은 이름은 건너뜀(--overwrite 로 덮어씀).
|
||||
|
||||
python manage.py import_snippets ../CODE_ASSISTANT_DB/snippets.db
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from apps.snippets.models import Snippet
|
||||
from apps.snippets.views import normalize_name
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "로컬 snippets.db 를 서버 스니펫으로 가져옴"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("path")
|
||||
parser.add_argument("--overwrite", action="store_true")
|
||||
|
||||
def handle(self, path, overwrite, **_):
|
||||
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)
|
||||
if not name or not (body or "").strip():
|
||||
skipped += 1
|
||||
continue
|
||||
d = {"desc": desc or "", "body": body, "category": (category or "").strip() or "코드"}
|
||||
if overwrite:
|
||||
_, created = Snippet.objects.update_or_create(name=name, defaults=d)
|
||||
added += created
|
||||
updated += not created
|
||||
else:
|
||||
_, created = Snippet.objects.get_or_create(name=name, defaults=d)
|
||||
added += created
|
||||
skipped += not created
|
||||
self.stdout.write(f"추가 {added} / 갱신 {updated} / 건너뜀 {skipped} (총 {len(rows)})")
|
||||
Reference in New Issue
Block a user