Token导航 LogoToken导航TokenDH.com
开发需要联网clawhub未标认证来源可访问clear审计通过

database-migrations数据库迁移

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

30,482

周安装

1,296

GitHub Stars

公开资料未说明

下载量

10,679
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:database-migrations(数据库迁移)
来源仓库:https://github.com/wpank/database-migrations
安装命令:
openclaw skills install database-migrations
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install database-migrations

简介

安全、零停机的数据库迁移策略——生产系统的模式演变、回滚规划、数据迁移、工具和反模式避免。在规划架构更改、编写迁移或检查迁移安全时使用。

SKILL.md

name
database-migrations
model
standard
description
Safe, zero-downtime database migration strategies — schema evolution, rollback planning, data migration, tooling, and anti-pattern avoidance for production systems. Use when planning schema changes, writing migrations, or reviewing migration safety.

Database Migration Patterns

Schema Evolution Strategies

StrategyRiskDowntimeBest For
Additive-OnlyVery LowNoneAPIs with backward-compatibility guarantees
Expand-ContractLowNoneRenaming, restructuring, type changes
Parallel ChangeLowNoneHigh-risk changes on critical tables
Lazy MigrationMediumNoneLarge tables where bulk migration is too slow
Big BangHighYesDev/staging or small datasets only

Default to Additive-Only. Escalate to Expand-Contract only when you must modify or remove existing structures.


Zero-Downtime Patterns

Every production migration must avoid locking tables or breaking running application code.

OperationPatternKey Constraint
Add columnNullable firstNever add NOT NULL without default on large tables
Rename columnExpand-contractAdd new → dual-write → backfill → switch reads → drop old
Drop columnDeprecate firstStop reading → stop writing → deploy → drop
Change typeParallel columnAdd new type → dual-write + cast → switch → drop old
Add indexConcurrentCREATE INDEX CONCURRENTLY — don't wrap in transaction
Split tableExtract + FKCreate new → backfill → add FK → update queries → drop old columns
Change constraintTwo-phaseAdd NOT VALIDVALIDATE CONSTRAINT separately
Add enum valueAppend onlyNever remove or rename existing values

Migration Tools

ToolEcosystemStyleKey Strength
Prisma MigrateTypeScript/NodeDeclarative (schema diff)ORM integration, shadow DB
KnexJavaScript/NodeImperative (up/down)Lightweight, flexible
Drizzle KitTypeScript/NodeDeclarative (schema diff)Type-safe, SQL-like
AlembicPythonImperative (upgrade/downgrade)Granular control, autogenerate
Django MigrationsPython/DjangoDeclarative (model diff)Auto-detection
FlywayJVM / CLISQL file versioningSimple, wide DB support
golang-migrateGo / CLISQL (up/down files)Minimal, embeddable
AtlasGo / CLIDeclarative (HCL/SQL diff)Schema-as-code, linting, CI

Match the tool to your ORM and deployment pipeline. Prefer declarative for simple schemas, imperative for fine-grained data manipulation.


Rollback Strategies

ApproachWhen to Use
Reversible (up + down)Schema-only changes, early-stage products
Forward-only (corrective migration)Data-destructive changes, production at scale
HybridReversible for schema, forward-only for data

Data Preservation

  1. Soft-delete columns — rename with _deprecated suffix instead of dropping
  2. Snapshot tablesCREATE TABLE _backup_<table>_<date> AS SELECT * FROM <table>
  3. Point-in-time recovery — ensure WAL archiving covers migration windows
  4. Logical backupspg_dump of affected tables before migration

Blue-Green Database

1. Replicate primary → secondary (green)
2. Apply migration to green
3. Run validation suite against green
4. Switch traffic to green
5. Keep blue as rollback target (N hours)
6. Decommission blue after confidence window

Data Migration Patterns

Backfill Strategies

StrategyBest For
Inline backfillSmall tables (< 100K rows)
Batched backfillMedium tables (100K–10M rows)
Background jobLarge tables (10M+ rows)
Lazy backfillWhen immediate consistency not required

Batch Processing

DO $$
DECLARE
  batch_size INT := 1000;
  rows_updated INT;
BEGIN
  LOOP
    UPDATE my_table
    SET new_col = compute_value(old_col)
    WHERE id IN (
      SELECT id FROM my_table
      WHERE new_col IS NULL
      LIMIT batch_size
      FOR UPDATE SKIP LOCKED
    );
    GET DIAGNOSTICS rows_updated = ROW_COUNT;
    EXIT WHEN rows_updated = 0;
    PERFORM pg_sleep(0.1);  -- throttle to reduce lock pressure
    COMMIT;
  END LOOP;
END $$;

Dual-Write Period

For expand-contract and parallel change:

  1. Dual-write — application writes to both old and new columns/tables
  2. Backfill — fill new structure with historical data
  3. Verify — assert consistency (row counts, checksums)
  4. Cut over — switch reads to new, stop writing to old
  5. Cleanup — drop old structure after cool-down period

Testing Migrations

Test Against Production-Like Data

  • Never test against empty or synthetic data only
  • Use anonymized production snapshots
  • Match data volume — a migration working on 1K rows may lock on 10M
  • Reproduce edge cases: NULLs, empty strings, max-length, unicode

Migration CI Pipeline

- name: Test migrations
  steps:
    - run: docker compose up -d db
    - run: npm run migrate:up        # apply all
    - run: npm run migrate:down      # rollback all
    - run: npm run migrate:up        # re-apply (idempotency)
    - run: npm run test:integration  # validate app
    - run: npm run migrate:status    # no pending

Every migration PR must pass: up → down → up → tests.


Migration Checklist

Pre-Migration

  • [ ] Tested against production-like data volume
  • [ ] Rollback written and tested
  • [ ] Backup of affected tables created
  • [ ] App code compatible with both old and new schema
  • [ ] Execution time benchmarked on staging
  • [ ] Lock impact analyzed
  • [ ] Replication lag monitoring in place

During Migration

  • [ ] Monitor lock waits and active queries
  • [ ] Monitor replication lag
  • [ ] Watch for error rate spikes
  • [ ] Keep rollback command ready

Post-Migration

  • [ ] Schema matches expected state
  • [ ] Integration tests pass against migrated DB
  • [ ] Data integrity validated (row counts, checksums)
  • [ ] ORM schema / type definitions updated
  • [ ] Deprecated structures cleaned up after cool-down
  • [ ] Migration documented in team runbook

NEVER Do

  1. NEVER run untested migrations directly in production
  2. NEVER drop a column without first removing all application references and deploying
  3. NEVER add NOT NULL to a large table without a default value in a single statement
  4. NEVER mix schema DDL and data mutations in the same migration file
  5. NEVER skip the dual-write phase when renaming columns in a live system
  6. NEVER assume migrations are instantaneous — always benchmark on production-scale data
  7. NEVER disable foreign key checks to "speed up" migrations in production
  8. NEVER deploy application code that depends on a schema change before the migration has completed

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

92.64%
按下载量换算9,893

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

未展示

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills