Community程式設計與開發github.com

alfathafp/portofolio-web-design

管理系統棄用與遷移流程。用於移除舊系統、API 或功能,以及無停機時間的資料庫 schema 遷移(擴展/收縮模式)。

portofolio-web-design 是什麼?

此技能提供了一套完整的棄用與遷移框架,幫助工程團隊安全、有條理地移除不再需要的程式碼或系統。其核心原則是「程式碼即負債」——每一行程式碼都需持續維護成本,因此當功能可用更少、更簡單的程式碼實現時,就應該淘汰舊程式碼。技能詳細說明了從「棄用決策」到「逐步遷移」再到「最終移除」的四個步驟,並涵蓋了多種安全遷移模式,如 Strangler 模式、Adapter 模式、功能旗標遷移,以及最關鍵的資料庫 schema 遷移(擴展/收縮模式)。特別強調了「Hyrum's Law」——任何可觀察的行為都會被依賴,因此棄用必須伴隨主動遷移,而非僅發布公告。同時也指出「殭屍程式碼」的風險並提供對應策略。本技能適用於 Claude Code、Cursor 等 AI 輔助開發工具,協助開發者在重構、升級或削減技術債務時做出明智決策,避免常見的遷移陷阱。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/deprecation-and-migration

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

系統棄用與遷移

概述

程式碼是負債,而非資產。每一行程式碼都需要持續的維護成本——修復錯誤、更新相依套件、套用安全性修補程式,以及培訓新進工程師。棄用(Deprecation)是移除那些不再具有維護價值之程式碼的紀律,而遷移(Migration)則是將使用者從舊系統安全轉移至新系統的過程。

多數工程組織擅長創造新事物,但鮮少擅長移除它們。本技能正是為了解決這個落差。

使用時機

  • 用新系統、API 或函式庫取代舊系統
  • 終止不再需要的功能
  • 合併重複的實作
  • 移除無人維護但人人都依賴的無主程式碼
  • 在新系統的設計階段即規劃其生命週期(棄用規劃從設計時開始)
  • 決定是否要維護舊系統,或投入資源進行遷移

核心原則

程式碼即負債

每一行程式碼都有持續成本:它需要測試、文件、安全性修補程式、相依套件更新,以及任何接觸它的工程師的心智負擔。程式碼的價值在於它提供的功能,而非程式碼本身。當相同的功能可以用更少的程式碼、更低的複雜度或更好的抽象來提供時——舊程式碼就該被移除。

Hyrum's Law 讓移除變得困難

當有足夠多的使用者時,所有可觀察的行為都會被依賴——包括錯誤、時序異常以及未記載的副作用。這就是為什麼棄用需要主動的遷移,而不僅僅是發布公告。當使用者依賴於新系統無法複製的行為時,他們無法「直接切換」。

棄用規劃始於設計階段

在建立新事物時,請問:「我們如何在三年後移除這個?」設計時採用乾淨的介面、功能旗標(feature flags)和最小 API 表面積的系統,比起那些將實作細節到處洩漏的系統更容易棄用。

棄用決策

在棄用任何東西之前,先回答這些問題:

1. 這個系統是否仍提供獨特的價值?
   → 如果是,保留它。如果否,繼續下一步。

2. 有多少使用者/消費者依賴它?
   → 量化遷移的範圍。

3. 是否存在替代方案?
   → 如果沒有,先建立替代方案。不要在沒有替代品的情況下棄用。

4. 每個消費者的遷移成本為何?
   → 如果可簡單自動化,就做。如果需要手動且高成本,則需與維護成本權衡。

5. 不棄用的持續維護成本為何?
   → 安全風險、工程師時間、因複雜度而損失的機會成本。

強制性與建議性棄用

類型使用時機機制
建議性 (Advisory)遷移為選擇性,舊系統穩定警告、文件、引導。使用者依自己的時程遷移。
強制性 (Compulsory)舊系統有安全性問題、阻礙進度,或維護成本過高硬性期限。舊系統將在日期 X 前被移除。提供遷移工具。

預設使用建議性。 僅在維護成本或風險大到需要強制遷移時才使用強制性。強制性棄用需要提供遷移工具、文件及支援——你不能只是宣布一個截止日期。

遷移流程

步驟 1:建立替代方案

不要在沒有可行替代方案的情況下棄用。替代方案必須:

  • 涵蓋舊系統的所有關鍵使用案例
  • 具備文件與遷移指南
  • 已在生產環境中驗證(而非僅「理論上更好」)

步驟 2:公告與文件

## 棄用通知:OldService

**狀態:** 自 2025-03-01 起已棄用
**替代方案:** NewService(請參閱下方遷移指南)
**移除日期:** 建議性——尚無硬性期限
**原因:** OldService 需要手動擴展且缺乏可觀測性。
            NewService 自動處理兩者。

### 遷移指南
1. 將 `import { client } from 'old-service'` 替換為 `import { client } from 'new-service'`
2. 更新設定(請參閱下方範例)
3. 執行遷移驗證腳本:`npx migrate-check`

步驟 3:逐步遷移

一次遷移一個消費者,而非一次全部遷移。對於每個消費者:

1. 識別與已棄用系統的所有接觸點
2. 更新使用替代方案
3. 驗證行為一致(測試、整合檢查)
4. 移除對舊系統的參考
5. 確認無回歸問題

轉移規則 (Churn Rule): 如果你擁有正被棄用的基礎設施,你有責任遷移你的使用者——或者提供不需要遷移的向後相容更新。不要只是宣布棄用,然後讓使用者自己想辦法。

步驟 4:移除舊系統

只有在所有消費者都遷移完成後:

1. 驗證零活躍使用量(指標、日誌、相依性分析)
2. 移除程式碼
3. 移除相關的測試、文件和設定
4. 移除棄用通知
5. 慶祝——移除程式碼是一項成就

遷移模式

Strangler 模式(絞殺藤模式)

新舊系統並行運作。逐步將流量從舊系統導向新系統。當舊系統處理 0% 的流量時,將其移除。

階段 1:新系統處理 0%,舊系統處理 100%
階段 2:新系統處理 10%(金絲雀部署)
階段 3:新系統處理 50%
階段 4:新系統處理 100%,舊系統空轉
階段 5:移除舊系統

Adapter 模式(轉接器模式)

建立一個轉接器,將舊介面的呼叫轉換為新實作。消費者在後端遷移的同時,繼續使用舊介面。

// 轉接器:舊介面,新實作
class LegacyTaskService implements OldTaskAPI {
  constructor(private newService: NewTaskService) {}

  // 舊方法簽章,委派給新實作
  getTask(id: number): OldTask {
    const task = this.newService.findById(String(id));
    return this.toOldFormat(task);
  }
}

功能旗標遷移

使用功能旗標一次將一個消費者從舊系統切換到新系統:

function getTaskService(userId: string): TaskService {
  if (featureFlags.isEnabled('new-task-service', { userId })) {
    return new NewTaskService();
  }
  return new LegacyTaskService();
}

資料庫 Schema 遷移(擴展/收縮)

Schema 變更是最有風險的遷移,因為資料是你無法透過回退部署來復原的東西。常見的失敗模式是將 schema 變更與程式碼變更耦合在一起:在同一個版本中重新命名欄位並開始使用新名稱,而在部署窗口期間——當新舊程式碼同時運行時——其中一個會查詢一個不存在的欄位。解決方案是永遠不要原地變更欄位。以增量階段進行遷移,使新舊程式碼在每個步驟都有效。

擴展 (EXPAND) ──────────────→ 遷移 (MIGRATE) ──────────────→ 收縮 (CONTRACT)
新增新欄位(可 null),      回填現有資料列,             一旦沒有程式碼讀取舊欄位,
與舊欄位並存               應用程式同時寫入新舊欄位       在後續的獨立部署中移除

實例——將 name 重新命名為 full_name:

  1. 擴展。 新增 full_name 為可 null。部署。(舊程式碼忽略它;不會出錯。)
  2. 雙寫。 應用程式在每次插入/更新時同時寫入 name 和 full_name。部署。
  3. 回填。 將 name → full_name 複製到現有資料列,分批進行,以免鎖定資料表。
  4. 切換讀取。 將應用程式指向 full_name,保持同時寫入兩者。部署並觀察。
  5. 收縮。 停止寫入 name,然後——在一個分開的、後續的部署中——移除該欄位。

每個步驟都可獨立部署且可逆轉:如果步驟 4 出問題,回退程式碼,而 full_name 仍在被填充。將每個階段視為一個薄垂直切面——請參閱 incremental-implementation 技能。

規則:

  • 先加法,最後且單獨進行破壞性操作。 新增(新的可 null 欄位、新表、新索引)在任何部署中都是安全的;刪除和重新命名需要在自己專屬的部署中進行,且是在沒有程式碼參考舊結構之後。
  • 每個遷移都要有經過測試的回退路徑。 無法復原的遷移就是無法回退的部署。在合併前撰寫並執行 down。
  • 分批回填,避開熱點路徑。 對數百萬列執行單一 UPDATE 會鎖定資料表;應將其分塊並限流。
  • 在不阻塞寫入的情況下建立大型索引(例如 Postgres 的 CREATE INDEX CONCURRENTLY)。
  • 透過功能旗標與程式碼解耦,當切換有風險時,完全遵循上述的功能旗標遷移模式。

殭屍程式碼

殭屍程式碼是無人維護但人人都依賴的程式碼。它沒有被積極維護,沒有明確的擁有者,並且會積累安全漏洞和相容性問題。徵兆:

  • 超過 6 個月沒有提交,但有活躍的消費者存在
  • 沒有指定的維護者或團隊
  • 失敗的測試無人修復
  • 有已知漏洞的相依套件無人更新
  • 文件參考了已不存在的系統

對策: 指派一個擁有者並妥善維護它,或者透過具體的遷移計畫將其棄用。殭屍程式碼不能處於灰色地帶——它要麼獲得投資,要麼被移除。

常見的合理化藉口

合理化藉口現實
「它還能用,為什麼要移除?」無人維護但仍在運作的程式碼會累積安全債務和複雜度。維護成本悄然增長。
「以後可能還會有人需要它」如果以後需要,可以重新建構。保留未使用的程式碼「以防萬一」的成本遠高於重建。
「遷移成本太高了」比較遷移成本與 2-3 年的持續維護成本。長遠來看,遷移通常更便宜。
「我們等完成新系統後再棄用舊的」棄用規劃始於設計階段。等到新系統完成時,你已經有新的優先事項。現在就開始計劃。
「使用者會自己遷移」他們不會。提供工具、文件和誘因——或者自己做遷移(轉移規則)。
「我們可以無限期地同時維護兩個系統」兩個做同樣事情的系統,維護、測試、文件和 onboarding 成本都會倍增。
「只要重新命名欄位,一行而已」在部署期間,新舊程式碼同時運行——其中一個會查詢一個已不存在的欄位。使用擴展/收縮模式,永遠不要原地重新命名。
「我會在同一個遷移中新增欄位並移除舊欄位」這將安全的加法操作與破壞性的刪除操作耦合在一起。刪除操作必須在自己專屬的部署中進行,且是在沒有程式碼參考舊結構之後。
「如果需要,我們再寫回退腳本」沒有向下路徑的遷移就是無法復原的部署。在合併前撰寫並執行 down。

紅旗警訊

  • 已棄用的系統沒有可用的替代方案
  • 棄用公告沒有提供遷移工具或文件
  • 「軟性」棄用多年來一直停留在建議階段,沒有進展
  • 沒有擁有者但有活躍使用者的殭屍程式碼
  • 對已棄用的系統新增功能(應投資在替代方案上)
  • 棄用時未衡量當前使用量
  • 未驗證活躍消費者為零就移除程式碼
  • 在同一個部署中發布 schema 變更及其依賴的程式碼
  • 原地重新命名或刪除欄位,而非使用擴展/收縮模式
  • 合併的遷移沒有經過測試的回退路徑,或回填導致資料表鎖定

驗證檢查清單

完成棄用後:

  • 替代方案已在生產環境中驗證,並涵蓋所有關鍵使用案例
  • 存在具備具體步驟和範例的遷移指南
  • 所有活躍消費者皆已遷移(透過指標/日誌驗證)
  • 舊程式碼、測試、文件和設定已完全移除
  • 程式碼庫中沒有對已棄用系統的殘留參考
  • 棄用通知已移除(它們已完成任務)

完成資料庫 Schema 遷移後:

  • 變更以加法階段發布(擴展 → 回填 → 收縮),而非單一原地編輯
  • 在每個部署步驟中,新舊程式碼對該 schema 都有效
  • 每個遷移都有經過測試的回退路徑;回填以限流批次執行
  • 破壞性步驟(刪除/重新命名)在自己專屬的部署中進行,且是在沒有程式碼參考舊結構之後

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相關技能