member_center/docs/INSTALL.md

2.4 KiB
Raw Blame History

安裝流程Installer + 管理者帳號)

此文件定義「首次安裝」與「既有環境管理」兩種情境,並以 EF Core Code First 為主。

目標

  • 透過 EF Core migrations 建立/更新 DB schema
  • 建立或更新 superuser 帳號
  • 已設定 DB 連線時,可重複執行(不重建 schema

安裝模式

A. 首次安裝Init

  1. 輸入 DB 連線資訊
  2. 連線檢查與版本檢查
  3. 建立/更新 schemaEF Core migrations
  4. 建立 superuser預設帳號 admin可自訂
  5. 建立必要 seedroles 等)

B. 既有環境(管理)

  • 建立額外 superuser
  • 強制重設 superuser 密碼
  • 只執行 migration差異安裝不重建 schema

CLI 指令規格(實作)

通用參數

  • --connection-string <string>: DB 連線字串
  • --appsettings <path>: 設定檔路徑(讀/寫 ConnectionStrings:Default
  • --no-prompt: 不使用互動輸入CI/CD
  • --verbose: 詳細輸出

1) installer init

用途:首次安裝(含 migrations + seed + superuser

參數:

  • --admin-email <email>: 預設 admin@example.com
  • --admin-password <string>: 預設需互動輸入
  • --admin-display-name <string>: 可選
  • --force: 若偵測已初始化,仍強制執行

流程:

  1. 解析連線字串(參數或 appsettings
    • 若提供 --connection-string,會寫入 appsettings
    • 若 appsettings 中缺少連線字串,會互動式詢問並寫入
  2. 執行 migrations不 Drop
  3. 建立 rolesadmin, support
  4. 建立 admin不存在才建立並加入 admin 角色
  5. 寫入安裝鎖定DB flag: system_flags / installed=true

2) installer add-admin

用途:新增 superuser

參數:

  • --admin-email <email>
  • --admin-password <string>
  • --admin-display-name <string>

流程:

  1. 解析連線字串
  2. 建立使用者並指派 admin 角色

3) installer reset-admin-password

用途:重設指定 admin 密碼

參數:

  • --admin-email <email>
  • --admin-password <string>

流程:

  1. 解析連線字串
  2. 更新密碼(強制)

4) installer migrate

用途:只執行 migrations

參數:

  • --target <migration>: 指定遷移(可選)

流程:

  1. 解析連線字串
  2. 執行 migrations可指定 target

安全注意

  • 密碼必須符合強度規則
  • 初次安裝完成後,禁用安裝入口或限內網
  • 安裝過程需紀錄 audit log