feat(M02): 옛 표 틀 새 판으로 갱신 — Migrate --refresh-tables · 손 값 · 변수 · 보기 지킴 · _initial 도 같은 판 (브레인 최종 확인)
- 계산 열에 바인딩이 붙은 옛 틀만 골라 시스템 새 판으로 - 손댄 것이 없으면 시스템 파일 그대로 복사(판이 시스템과 같음) · 있으면 고쳐 쓰고 manifest 에 출처 판 - 기존 프로젝트 6개 작업본 · _initial 갱신 완료 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015LuapLYqN1GGFD8Y1PStD5
This commit is contained in:
@@ -3,14 +3,17 @@
|
||||
프로젝트마다 `seed_project(only_missing=True)` — 작업본 · `_initial/` 에 **없는 것만 더함**.
|
||||
이미 있는 양식 · 다른 파일은 안 건드림 · 폴더가 없는 프로젝트는 건너뜀(만들지 않음).
|
||||
다시 돌려도 됨 — 시스템 양식이 늘었으면 그 몫만 더해짐.
|
||||
`--refresh-tables` — 옛 표 틀(계산 열에 바인딩)만 새 판으로 · 손 값은 지킴.
|
||||
|
||||
./venv/Scripts/python.exe M02_MasterTemplete/M02_Template_Migrate.py [--dry-run] [--report 파일]
|
||||
./venv/Scripts/python.exe M02_MasterTemplete/M02_Template_Migrate.py \\
|
||||
[--dry-run] [--refresh-tables] [--report 파일]
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import copy
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
@@ -21,6 +24,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from config import config_system # noqa: E402
|
||||
from config.config_db import close_db_pool, get_db_pool, init_db_pool # noqa: E402
|
||||
from M02_MasterTemplete import M02_Table_Fill as fill # noqa: E402
|
||||
from M02_MasterTemplete import M02_Template_Layers as layers # noqa: E402
|
||||
|
||||
|
||||
@@ -51,13 +55,62 @@ def project_root(storage_path: str | None) -> Path | None:
|
||||
return path
|
||||
|
||||
|
||||
def migrate(projects: list[dict[str, Any]], *, dry_run: bool = False) -> list[dict[str, Any]]:
|
||||
"""프로젝트마다 넣은 것 `[{…프로젝트, 작업본, 초기, 상태}]`."""
|
||||
def _stale_frame(document: Any) -> bool:
|
||||
"""옛 표 틀 — 계산 열에 바인딩(설계값 딱지)이 붙은 판."""
|
||||
return isinstance(document, dict) and any(
|
||||
isinstance(column, dict)
|
||||
and column.get("바인딩")
|
||||
and (column.get("식") or column["바인딩"].get("값") == "식")
|
||||
for column in document.get("열") or []
|
||||
)
|
||||
|
||||
|
||||
def refresh_tables(root: Path, *, dry_run: bool = False) -> list[str]:
|
||||
"""옛 표 틀을 시스템 새 판으로 — 작업본 · `_initial/` 둘 다 · 줄(손 값) · 변수 · 보기는 지킴.
|
||||
|
||||
손댄 것이 없으면 시스템 파일을 그대로 복사(판이 시스템과 같음).
|
||||
"""
|
||||
done: list[str] = []
|
||||
for row in layers.list_templates(layers.system_dir()):
|
||||
if row["종류"] != "table":
|
||||
continue
|
||||
system = layers.read_template(layers.system_dir(), "table", row["이름"])
|
||||
for folder in (layers.project_dir(root), layers.initial_dir(root)):
|
||||
got = layers.read_template(folder, "table", row["이름"])
|
||||
if not system or not got or not _stale_frame(got["문서"]):
|
||||
continue
|
||||
done.append(f"{folder.name}/table/{row['이름']}")
|
||||
if dry_run:
|
||||
continue
|
||||
old = fill.strip_design(got["문서"])
|
||||
doc = copy.deepcopy(system["문서"])
|
||||
doc["변수"] = {**(doc.get("변수") or {}), **(old.get("변수") or {})}
|
||||
doc.update({key: old[key] for key in ("줄", "보기") if key in old})
|
||||
if doc == system["문서"]:
|
||||
layers.copy_templates(
|
||||
layers.system_dir(),
|
||||
folder,
|
||||
source_layer="system",
|
||||
kind="table",
|
||||
name=row["이름"],
|
||||
)
|
||||
else:
|
||||
layers.write_template(folder, "table", row["이름"], doc)
|
||||
layers.note_source(folder, "table", row["이름"], "system", system["판"])
|
||||
return done
|
||||
|
||||
|
||||
def migrate(
|
||||
projects: list[dict[str, Any]], *, dry_run: bool = False, refresh: bool = False
|
||||
) -> list[dict[str, Any]]:
|
||||
"""프로젝트마다 넣은 것 `[{…프로젝트, 작업본, 초기, 표갱신, 상태}]`."""
|
||||
system = {f"{row['종류']}/{row['이름']}" for row in layers.list_templates(layers.system_dir())}
|
||||
report = []
|
||||
for project in projects:
|
||||
root = project_root(project.get("storage_path"))
|
||||
entry = {**project, "작업본": [], "초기": [], "상태": ""}
|
||||
entry = {**project, "작업본": [], "초기": [], "표갱신": [], "상태": ""}
|
||||
if root is not None and refresh:
|
||||
entry["표갱신"] = refresh_tables(root, dry_run=dry_run)
|
||||
if root is None:
|
||||
entry["상태"] = "폴더 없음 — 건너뜀"
|
||||
elif dry_run:
|
||||
@@ -85,14 +138,14 @@ def render(report: list[dict[str, Any]], system: list[dict[str, Any]]) -> str:
|
||||
"- 방법: 작업본 · `_initial/` 에 없는 것만 더함 · 있는 양식 · 다른 파일은 그대로",
|
||||
f"- 프로젝트 {len(report)}개 · 넣음 {sum(r['상태'] == '넣음' for r in report)}개",
|
||||
"",
|
||||
"| 회사 | 만든 사람 | 프로젝트 | ID | 넣은 양식 | 상태 |",
|
||||
"| --- | --- | --- | --- | --- | --- |",
|
||||
"| 회사 | 만든 사람 | 프로젝트 | ID | 넣은 양식 | 표 틀 새 판 | 상태 |",
|
||||
"| --- | --- | --- | --- | --- | --- | --- |",
|
||||
]
|
||||
for row in report:
|
||||
added = " · ".join(row["작업본"]) or "—"
|
||||
lines.append(
|
||||
f"| {row['company_id']} | {row.get('owner') or row['user_id']} | {row['name']} "
|
||||
f"| `{row['id']}` | {added} | {row['상태']} |"
|
||||
f"| `{row['id']}` | {added} | {' · '.join(row['표갱신']) or '—'} | {row['상태']} |"
|
||||
)
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
@@ -100,6 +153,7 @@ def render(report: list[dict[str, Any]], system: list[dict[str, Any]]) -> str:
|
||||
async def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
parser.add_argument("--refresh-tables", action="store_true")
|
||||
parser.add_argument("--report", type=Path)
|
||||
args = parser.parse_args()
|
||||
await init_db_pool()
|
||||
@@ -107,7 +161,7 @@ async def main() -> None:
|
||||
projects = await _projects()
|
||||
finally:
|
||||
await close_db_pool()
|
||||
report = migrate(projects, dry_run=args.dry_run)
|
||||
report = migrate(projects, dry_run=args.dry_run, refresh=args.refresh_tables)
|
||||
text = render(report, layers.list_templates(layers.system_dir()))
|
||||
if args.report:
|
||||
args.report.write_text(text, encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user