Community编程与开发github.com

alfathafp/portofolio-web-design

管理弃用和迁移。用于移除旧系统、API 或功能。用于将用户从一个实现迁移到另一个。用于在生产环境中迁移数据库 schema(如重命名或删除列且无需停机,采用扩展/收缩模式)。用于决定是否维护现有代码或使其退役。

portofolio-web-design 是什么?

该技能专注于软件工程中的弃用和迁移实践。它帮助开发者系统地移除不再有价值的代码,并以最小风险迁移用户。核心原则包括:代码是负债而非资产、Hyrum 定律使移除困难、弃用规划应从设计阶段开始。该技能提供了清晰的决策框架(如唯一性价值、用户量、维护成本分析),区分了建议性弃用和强制性弃用,并详细介绍了迁移流程(构建替代方案、公告、增量迁移、最终移除)。关键模式包括扼杀者模式、适配器模式和特性标志迁移。它还特别关注数据库 schema 迁移,提供了扩展/收缩模式的详细分步指南(添加、双写、回填、切换读、收缩),强调了每一步都应独立部署和可逆、批量回填、非阻塞创建索引以及每个迁移有经过测试的回滚路径。该技能适合使用 Claude Code、Cursor、Codex 等 AI Agent 工具,帮助工程师在管理技术债务和复杂系统演进时做出明智决策。

兼容平台~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 的新对话。

文档

弃用与迁移

概述

代码是负债,而非资产。每一行代码都有持续的维护成本——修复缺陷、更新依赖、应用安全补丁以及让新工程师上手。弃用是一门移除不再值得保留的代码的学科,而迁移则是安全地将用户从旧系统迁移到新系统的过程。

大多数工程组织擅长构建东西,但很少有人擅长移除它们。本技能旨在弥补这一差距。

何时使用

  • 用新系统、API 或库替换旧系统
  • 移除不再需要的功能使其退役
  • 合并重复的实现
  • 移除没有人拥有但每个人都在依赖的死代码
  • 规划新系统的生命周期(弃用规划从设计阶段开始)
  • 决定是维护遗留系统还是投资进行迁移

核心原则

代码即是负债

每一行代码都有持续的成本:它需要测试、文档、安全补丁、依赖更新以及任何接触它的人的心理负担。代码的价值在于它提供的功能,而不是代码本身。当相同的功能可以用更少的代码、更少的复杂性或更好的抽象来提供时——旧代码应该被移除。

Hyrum 定律让移除变得困难

有足够多的用户时,每一个可观察到的行为都会变成依赖——包括 bug、时序异常和未记录的副作用。这就是为什么弃用需要主动迁移,而不仅仅是发布公告。当用户依赖那些替代品无法复现的行为时,他们无法“直接切换”。

弃用规划从设计阶段开始

在构建新东西时,问自己:“3年后我们将如何移除它?”设计具有清晰接口、特性标志和最小表面积*(minimal surface area)*的系统比那些到处泄露实现细节的系统更容易弃用。

弃用决策

在弃用任何东西之前,先回答这些问题:

1. 这个系统是否仍然提供独特的价值?
   → 如果是,维护它。如果否,继续。

2. 有多少用户/消费者依赖它?
   → 量化迁移范围。

3. 是否存在替代方案?
   → 如果没有,先构建替代方案。不要在没有替代品的情况下弃用。

4. 每个消费者的迁移成本是多少?
   → 如果可以低成本自动化,就做。如果是手动且高成本的,与维护成本权衡。

5. 不弃用的持续维护成本是多少?
   → 安全风险、工程师时间、复杂性带来的机会成本。

强制性弃用 vs 建议性弃用

类型何时使用机制
建议性迁移是可选的,旧系统稳定警告、文档、提醒。用户按自己的时间表迁移。
强制性旧系统存在安全问题、阻碍进展或维护成本不可持续硬性截止日期。旧系统将在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. 确认无回归

搅动规则: 如果你拥有正在弃用的基础设施,你有责任迁移你的用户——或者提供无需迁移的向后兼容更新。不要发布弃用公告后把用户丢在一边让他们自己摸索。

第 4 步:移除旧系统

只有在所有消费者都迁移完成后:

1. 验证零活跃使用(指标、日志、依赖分析)
2. 移除代码
3. 移除相关的测试、文档和配置
4. 移除弃用通知
5. 庆祝——移除代码是一种成就

迁移模式

扼杀者模式

并行运行新旧系统。逐步将流量从旧系统路由到新系统。当旧系统处理 0% 的流量时,移除它。

第 1 阶段:新系统处理 0%,旧系统处理 100%
第 2 阶段:新系统处理 10%(金丝雀)
第 3 阶段:新系统处理 50%
第 4 阶段:新系统处理 100%,旧系统空闲
第 5 阶段:移除旧系统

适配器模式

创建一个适配器,将旧接口的调用转换为新实现。消费者在迁移后端时继续使用旧接口。

// 适配器:旧接口,新实现
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 变更与代码变更耦合在一起:在同一个发布中重命名列并开始使用新名称,在发布窗口期间——当新旧代码同时运行时——其中一个将查询一个不存在的列。解决方案是永远不要原地更改列。通过加法阶段进行迁移,使得旧代码和新代码在每一步都是有效的。

扩展 ──────────────→ 迁移 ──────────────→ 收缩
添加新列(可为空),   回填现有行,            一旦没有代码读取旧列,
与旧列并列            应用层双写新旧两列        在后续的独立部署中删除旧列

工作示例——将 name 重命名为 full_name:

  1. 扩展。 添加 full_name,可为空。部署。(旧代码忽略它;一切正常。)
  2. 双写。 应用在每次插入/更新时同时写入 name 和 full_name。部署。
  3. 回填。 将现有行的 name 复制到 full_name,分批进行,避免锁表。
  4. 切换读。 让应用读取 full_name,继续双写两者。部署并静置。
  5. 收缩。 停止写入 name,然后在后续的、单独的部署中删除该列。

每一步都是独立可部署和可逆的:如果第 4 步出现问题,回滚代码,但 full_name 仍然在被填充。将每个阶段视为一个薄的垂直切片——参见 incremental-implementation 技能。

规则:

  • 先做加法,最后单独做破坏性操作。 添加(新的可为空列、新表、新索引)在任何部署中都是安全的;删除和重命名操作需要在自己的部署中进行,在没有代码引用旧形状之后。
  • 每个迁移都有经过测试的回滚路径。 无法回滚的迁移是你无法回滚的部署。在合并前编写并运行 down。
  • 分批回填,远离热点路径。 对百万级行执行单个 UPDATE 会锁表;要分块并限速。
  • 在不阻塞写入的情况下构建大型索引(例如 Postgres 的 CREATE INDEX CONCURRENTLY)。
  • 当切换有风险时,通过特性标志与代码解耦,就像上面的特性标志迁移模式一样。

僵尸代码

僵尸代码是指没有人拥有但每个人都依赖的代码。它没有被积极维护,没有明确的所有者,并且积累安全漏洞和兼容性问题。迹象:

  • 6 个月以上没有提交但有活跃的消费者
  • 没有指定的维护者或团队
  • 无人修复的失败测试
  • 依赖项中存在已知漏洞但无人更新
  • 引用已不存在系统的文档

应对措施: 要么指定所有者并妥善维护,要么通过具体的迁移计划弃用它。僵尸代码不能处于悬而未决的状态——它要么获得投资,要么被移除。

常见借口

借口现实
“它还能工作,为什么要移除?”无人维护的工作代码会积累安全债务和复杂性。维护成本在悄然增长。
“也许以后有人需要它”如果以后需要,可以重建。保留未使用的代码“以防万一”的成本高于重建。
“迁移成本太高了”将迁移成本与未来 2-3 年的持续维护成本进行比较。从长远来看,迁移通常更便宜。
“等我们完成新系统后再弃用它”弃用规划从设计阶段开始。等到新系统完成时,你会有新的优先级。现在就开始规划。
“用户会自行迁移”他们不会。提供工具、文档和激励措施——或者自己完成迁移(搅动规则)。
“我们可以无限期地维护两个系统”执行相同功能的两个系统意味着双倍的维护、测试、文档和入职成本。
“只需重命名这一列,就一行代码”在发布期间,新旧代码同时运行——其中一个将查询一个不再存在的列。使用扩展/收缩,永远不要原地重命名。
“我将在同一个迁移中添加列并删除旧列”这会将安全的添加操作与破坏性的删除操作耦合在一起。删除操作需要在自己的部署中进行,在没有代码引用旧形状之后。
“如果需要,我们会编写回滚”没有回滚路径的迁移是你无法回滚的部署。在合并前编写并运行 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.

相关技能