Mtool正本文書 · 日本語 / English

このページの目次

Storage And State Model / 保存先と状態モデル

English companion: This document explains where state is stored across the existing-DB-to-output journey. It separates durable metadata, disposable runtime output, shared artifacts, and resume checkpoints so operators know what persists and what can be thrown away.

この文書は、existing DB -> canonical metadata -> output の journey で、何がどこに保存されるかを 1 枚で説明するための恒久文書です。
「既存 DB をつないだら何が永続化されるのか」「どこが disposable なのか」「どこが share lane なのか」を current rule で固定します。

導線の正本は existing-db-to-output.md (Mtool原本: existing-db-to-output.md) を参照してください。

1 枚で見る flow

existing DB / lab_db
  -> import preview / apply
  -> config_db canonical metadata
  -> sync_project_data_classes.php
  -> sync_project_db_access.php
  -> create_project_output.php --publish
  -> work/artifacts/... + work/source-outputs/...
  -> lab viewer / admin artifact download

state map

place主な役割何が入るか誰が書くかdurable reading
config_dbcanonical storeproject, dbtable*, dataclass*, project_db_access_*, project_source_outputs, database_sourcesadmin UI、import apply、sync CLI、bundle importcurrent source of truth
existing DBimport source / runtime source既存 schema と dataDB owner、自分の migration、運用 jobcanonical store ではない
db-lablocal rehearsal sourceeditable schema / sample datalab-db-ui、lab 側の手操作canonical store ではない
work/artifacts/source-outputs/{project_key}/{artifact_key}/bundle/...artifact history生成済み source output bundlecreate_project_output.phpregenerate できる artifact
work/source-outputs/{project_key}/{source_output_key}current raw output最新 publish の materialized outputcreate_project_output.php --publish次回 publish で上書きされる
bundle dir (/tmp/...)transport packageexport 済み metadata bundleexport_project_metadata.php配布用。live store ではない
database-source-secrets*.jsonsecret sidecardatabase source password または password_envoperatorcommit しない
mtool/reference/legacy-*curated legacy reference旧生成 DB class、旧 build ロジック、旧テンプレートの参照人の調査作業だけruntime input ではない

よくある質問

既存 DB に接続したら、その DB 自体に書き込みますか

current mainline では、import_project_tables.php、sync_project_data_classes.php、sync_project_db_access.php、create_project_output.php --publish は canonical metadata と output artifact を更新します。
既存 DB を直接 canonical store に置き換えたり、schema/data をそのまま書き換えたりする前提ではありません。

例外は、自分で lab-db-ui や DB client から既存 DB / db-lab を編集した時だけです。
その変更を canonical metadata へ反映するには、改めて import preview / apply を流します。

設計はどこに永続化されますか

config_db です。

  • table 設計: dbtable / dbtablecolumns
  • data class 設計: dataclass / dataclassfields
  • DB access 設計: project_db_access_*
  • output 設計: project_source_outputs
  • source catalog: database_sources

つまり、既存 DB から取り込んだあとに設計として残る正本は config_db 側です。

output はどこに出ますか

create_project_output.php はまず artifact bundle を work/artifacts/source-outputs/{project_key}/{artifact_key}/bundle/... に作ります。
--publish を付けた時だけ、current raw output として work/source-outputs/{project_key}/{source_output_key} も更新します。

この current raw output は便利な materialization ですが、永続正本ではありません。
次の publish で置き換わるので、再現可能な正本は config_db と artifact history だと考えます。

Swagger viewer / published proxy はどの DB を読みますか

runtime DB source は db_source_key で選びます。

  • viewer path: /runs/swagger/{project_key}?source_output_key=OPENAPI-JSON&db_source_key={source_key}
  • current rule: explicit db_source_key は supports_proxy_runtime_read=1 の source だけ

つまり、existing DB を runtime read にも使いたいなら、named source 登録時に supports_proxy_runtime_read=1 が必要です。

OpenAPI は public file として配られますか

いいえ。current supported share lane は次だけです。

  • authenticated viewer
  • admin artifact download

spec_visibility=internal-only が default で、disabled なら viewer からも隠れます。
raw openapi.json を public static file として配る前提にはしません。

durable / disposable の読み方

durable と読むもの:

  • config_db の canonical metadata
  • 必要に応じて保持した artifact bundle
  • 明示的に配布した metadata bundle

disposable と読むもの:

  • work/ 配下の current raw output
  • compare 用の scratch
  • local compose stack の一時 state

補足:

  • work/ は repo rule 上 disposable です
  • ただし artifact history は再現確認や配布に使えるので、必要なものは明示的に残します

resume / handoff でどこを見るか

  • source 登録が残っているか
    • config_db.database_sources
  • import apply が終わっているか
    • config_db.dbtable / config_db.dbtablecolumns
  • Data Class sync が終わっているか
    • config_db.dataclass / config_db.dataclassfields
  • DB Access sync が終わっているか
    • config_db.project_db_access_*
  • 最後に publish した artifact はどれか
    • work/artifacts/source-outputs/{project_key}/{artifact_key}/bundle/...
  • 今 viewer / proxy が見ている current raw output は何か
    • work/source-outputs/{project_key}/{source_output_key}
  • 別環境へ持ち出せる rerun 材料は何か
    • bundle dir と database-source-secrets*.json

resume 時は、existing DB や db-lab の中身そのものより、まず config_db と artifact / bundle 側に残った state を確認します。
existing DB、db-lab、work/source-outputs/... は便利でも canonical store ではありません。

secrets の current rule

  • bundle 本体には actual password を入れない
  • database-source-secrets.template.json を placeholder として配布してよい
  • populated secret file は commit しない
  • 共有する時は literal password より { "password_env": "ENV_NAME" } を優先する

current boundary

  • config_db は canonical store
  • existing DB / db-lab は import source または runtime source
  • work/ は output materialization と artifact workspace
  • mtool/reference/legacy-* は curated legacy reference only

関連文書

  • existing-db-to-output.md (Mtool原本: existing-db-to-output.md)
    • journey 全体
  • config-db-externalization.md (Mtool原本: config-db-externalization.md)
    • config_db topology の詳細
  • project-metadata-bundle.md
    • bundle / secret sidecar の current rule
この文書の出典・同期情報
正本ファイル
docs/storage-and-state-model.md
参照commit
c995b6b5673e2220501daa3f0997d0876277be82
原文 SHA-256
5d995f3912eb66e310a5dc22ed6c1d115747ac2b85f43be2eb45743f87f16616

本文の修正はMtool側で行い、レビュー後に同期します。未掲載の関連文書はMtool原本のファイル名で案内しています。

文書manifest