关于 legacy
面向升级框架、语言或依赖并减少技术债的遗留系统现代化技能。它强调渐进式改动、兼容性、测试、监控和回滚规划。
主要功能
- 01绞杀者模式与抽象迁移模式
- 02迁移前、中、后检查清单
- 03渐进式迁移指导
- 04兼容性适配器示例
- 05测试与回滚规划
适用场景
- 01将 Express 应用迁移到 Fastify
- 02升级语言版本
- 03在保持兼容的同时减少技术债
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ htlin222/ dotfiles --skill legacy安装后在 Claude Code 中输入/legacy确认已加载。
详细介绍
遗留系统现代化
安全地升级并改造遗留系统。
适用场景
- 框架迁移
- 语言版本升级
- 单体应用拆分
- 技术债务削减
- 依赖更新
迁移策略
绞杀者无花果模式
┌─────────────────────────────────────┐
│ Load Balancer │
└──────────────┬──────────────────────┘
│
┌───────┴───────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ Legacy │ │ New │
│ System │ │ Service │
└─────────────┘ └─────────────┘
1. Route new features to new service
2. Gradually migrate existing features
3. Eventually retire legacy system
通过抽象进行分支
# 1. Create abstraction layer
class PaymentProcessor(ABC):
@abstractmethod
def process(self, amount: float) -> bool:
pass
# 2. Wrap legacy implementation
class LegacyPaymentProcessor(PaymentProcessor):
def __init__(self, legacy_system):
self.legacy = legacy_system
def process(self, amount: float) -> bool:
return self.legacy.old_process_method(amount)
# 3. Create new implementation
class ModernPaymentProcessor(PaymentProcessor):
def process(self, amount: float) -> bool:
# New implementation
pass
# 4. Use feature flag to switch
processor = (ModernPaymentProcessor() if feature_flag("new_payment")
else LegacyPaymentProcessor(legacy))
迁移检查清单
开始之前
- 记录当前行为
- 为现有功能添加测试
- 设置监控和告警
- 制定回滚计划
- 与利益相关者沟通
迁移期间
- 进行增量更改
- 每次更改后都进行测试
- 监控错误率
- 保持遗留系统并行运行
- 记录破坏性更改
迁移之后
- 移除功能标志
- 清理遗留代码
- 更新文档
- 归档旧代码库
- 总结经验教训
常见迁移
从 jQuery 迁移到 React
// Phase 1: Embed React in jQuery app
const root = document.getElementById("new-component");
ReactDOM.render(<NewComponent />, root);
// Phase 2: Shared state
window.appState = { user: null };
// Both jQuery and React read from appState
// Phase 3: Gradual replacement
// Replace one component at a time
从 Python 2 迁移到 3
# Use __future__ imports for compatibility
from __future__ import print_function, division, absolute_import
# Use six for cross-version compatibility
import six
if six.PY2:
text_type = unicode
else:
text_type = str
# Run 2to3 tool
# python -m lib2to3 --write --nobackups src/
兼容层
# Adapter for API changes
class CompatibilityAdapter:
def __init__(self, new_service):
self.new = new_service
# Old API signature
def get_user(self, user_id):
# Translate to new API
return self.new.fetch_user(id=user_id)
# Deprecation warning
def old_method(self):
warnings.warn(
"old_method is deprecated, use new_method instead",
DeprecationWarning
)
return self.new.new_method()
示例
输入:“从 Express 迁移到 Fastify” **操作:**创建适配器层,逐步迁移路由,并在每个步骤进行测试
输入:“减少此模块中的技术债务” **操作:**先添加测试,再逐步重构,同时保持兼容性
评论
支持 Markdown