Habilidades db-migration
🗄️

db-migration

Seguro ⚡ Contém scripts

使用 Alembic 管理数据库迁移

数据库迁移复杂且易出错。此技能为 SQLModel 与 FastAPI 项目中的 Alembic 迁移提供专业指导,支持安全的架构演进与回滚能力。

Suporta: Claude Codex Code(CC)
🥉 72 Bronze
1

Baixar o ZIP da skill

2

Upload no Claude

Vá em Configurações → Capacidades → Skills → Upload skill

3

Ative e comece a usar

Testar

A utilizar "db-migration". Generate a migration for adding a fees table with student_id, amount, status, and due_date columns

Resultado esperado:

  • 生成包含表创建与外键约束的迁移文件
  • 在 student_id 与 status 列上添加索引
  • 创建 downgrade 函数以安全地删除表
  • 迁移已准备好在应用前进行审查

A utilizar "db-migration". How do I handle enum type changes safely

Resultado esperado:

  • 在修改列之前创建新的枚举类型
  • 使用 USING 子句进行类型转换
  • 包含回滚路径以恢复枚举值
  • 测试完整的升级与降级流程

Auditoria de Segurança

Seguro
v5 • 1/16/2026

Pure documentation skill with no executable code. The SKILL.md contains only documentation and code examples. The verify.py script only reads and validates YAML frontmatter locally. All 86 static findings are false positives from misidentified patterns: regex was flagged as crypto, markdown backticks as shell execution, and database terms like 'upgrade' as C2 keywords.

3
Arquivos analisados
616
Linhas analisadas
1
achados
5
Total de auditorias

Fatores de risco

⚡ Contém scripts (1)
Auditado por: claude Ver Histórico de Auditoria →

Pontuação de qualidade

45
Arquitetura
100
Manutenibilidade
85
Conteúdo
30
Comunidade
100
Segurança
91
Conformidade com especificações

O Que Você Pode Construir

设置迁移

为生产环境 FastAPI 应用初始化并管理 Alembic 迁移

处理数据迁移

通过批量更新与枚举类型变更创建复杂数据迁移

维护回滚安全

在数据库架构演进中保持安全的回滚能力

Tente Estes Prompts

初始化 Alembic
Initialize Alembic migrations in my SQLModel project
生成迁移
Generate a migration for my new User table with email and created_at fields
应用迁移
Apply all pending migrations and show the current revision
安全回滚
Rollback the last migration and show the downgrade steps

Melhores Práticas

  • 在手动编辑前始终使用 --autogenerate 生成迁移
  • 在非生产环境测试完整的升级与降级流程
  • 确保降级操作先删除索引再删除表,并使用 IF EXISTS 子句

Evitar

  • 不要跳过 autogenerate 步骤而完全手写迁移
  • 不要忘记在 downgrade 函数中包含回滚逻辑
  • 不要在生产环境中直接运行迁移而不先测试降级路径

Perguntas Frequentes

这个技能适用于纯 SQLAlchemy 吗?
是的。示例使用 SQLModel,但 Alembic 的命令与模式适用于任何基于 SQLAlchemy 的项目。
支持哪些数据库?
Alembic 支持 PostgreSQL、MySQL、SQLite 及其他兼容 SQLAlchemy 的数据库。该技能覆盖适用于所有数据库的模式。
如何处理大型表迁移?
在 upgrade 函数中使用带 LIMIT 子句的批量更新,以避免在数据迁移期间锁定大型表。
迁移期间我的数据安全吗?
该技能提供数据安全最佳实践,包括测试迁移、使用事务以及始终提供降级路径。
为什么我的自动生成迁移是空的?
确保在 env.py 中导入你的 SQLModel 类,这样 Alembic 才能在 target_metadata 中检测到变更。
这与原始 SQL 有何不同?
Alembic 为架构变更提供可逆迁移的版本控制。原始 SQL 缺乏这种安全性与跟踪能力。

Detalhes do Desenvolvedor

Estrutura de arquivos

📁 scripts/

📄 verify.py

📄 SKILL.md