SchemaDryRunPlanner ConsoleHost 顯示實作前確認

SchemaDryRunPlanner ConsoleHost 顯示實作前確認

返回 docs

SchemaDryRunPlanner ConsoleHost 顯示實作前確認

1. 文件目的

本文件確認 SchemaDryRunPlanner 要接到 ConsoleHost 顯示層之前,實作範圍、輸出格式、測試方式與不可碰觸範圍。

本節點是實作前確認,不直接修改程式碼。

2. 本次確認結論

項目結論
是否接真實 MySQL
是否導入 MySQL 套件
是否查詢 information_schema
是否執行 DDL
是否改 ConsoleHost 啟動方式
是否修改既有 public method 簽章
是否可進入下一步實作可以,限 ConsoleHost 顯示與 formatter

3. 建議實作範圍

第一版只做 ConsoleHost 的 dry run 顯示,不做真實資料庫初始化。

類別建議內容
Demo schema使用現有或新增的測試 schema class 產生 target schema
Current schema使用 MockSchemaInspector.Empty() 或 mock snapshot
Planner呼叫 SchemaDryRunPlanner.GenerateDryRunPlan(...)
Console output顯示 plan summary、warnings、manual review、SQL preview
Formatter建議抽出 internal formatter,方便單元測試
測試放在 ConsoleHost 相關測試或現有 ConsoleHost 驗證測試區
文件實作後補 schema-dry-run-planner-consolehost-display-record.md

4. 建議 ConsoleHost 顯示格式

ConsoleHost 顯示應清楚告訴使用者這只是 Dry Run。

Schema dry run:
Mode=DryRun Success=True
TablesToCreate=1 ColumnsToAdd=0 IndexesToAdd=0 ManualReview=0

SQL preview:
- CREATE TABLE IF NOT EXISTS `task_executions` (...)

Warnings:
- Dry Run 不會執行任何 MySQL DDL

若沒有任何變更:

Schema dry run:
Mode=DryRun Success=True
TablesToCreate=0 ColumnsToAdd=0 IndexesToAdd=0 ManualReview=0
SQL preview: empty.
Warnings: empty.

若 inspector 或 planner 失敗:

Schema dry run failed:
ErrorCode=SCH-0002
Message=metadata read failed

5. Formatter 建議

建議新增或擴充 ConsoleHost formatter:

internal static IEnumerable<string> FormatSchemaDryRunResult(SchemaDryRunResult result)

格式化規則:

情境輸出
result == nullSchema dry run: empty.
Success == false顯示 Schema dry run failed:ErrorCodeMessage
無 SQL顯示 SQL preview: empty.
無 warnings顯示 Warnings: empty.
有 manual review顯示 Manual review: 與每筆 table / object / message
有 SQL每筆 SQL 前加 -

6. 測試清單

測試名稱建議驗證內容
ConsoleHost_ShouldFormatSchemaDryRunCreateTablePreviewempty snapshot 時顯示 create table preview
ConsoleHost_ShouldFormatSchemaDryRunAddColumnAndIndexPreview缺欄位與索引時顯示 add column / add index
ConsoleHost_ShouldFormatSchemaDryRunManualReviewschema 差異時顯示 manual review
ConsoleHost_ShouldFormatSchemaDryRunWarnings顯示 warning 清單
ConsoleHost_ShouldFormatSchemaDryRunFailureinspector 失敗時顯示錯誤碼與訊息
ConsoleHost_ShouldFormatEmptySchemaDryRunResultnull result 時顯示 empty

7. 實作時禁止範圍

本次後續實作不得做以下事項:

8. 驗證方式

下一步實作完成後,至少需執行:

dotnet test tests\HS.DeviceControl.Core.Tests\HS.DeviceControl.Core.Tests.csproj
dotnet test

若實作有修改 ConsoleHost,建議再執行:

dotnet run --project src\HS.DeviceControl.ConsoleHost

人工驗證重點:

9. 建議下一步

建議下一步進入:

SchemaDryRunPlanner ConsoleHost 顯示第一版實作

實作範圍限: