data-migration-scripts by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill data-migration-scripts创建健壮、安全且可逆的数据迁移脚本,用于数据库模式变更和数据转换,同时实现最短的停机时间。
最小工作示例:
import { Knex } from "knex";
// migrations/20240101000000_add_user_preferences.ts
export async function up(knex: Knex): Promise<void> {
// Create new table
await knex.schema.createTable("user_preferences", (table) => {
table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()"));
table
.uuid("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE");
table.jsonb("preferences").defaultTo("{}");
table.timestamp("created_at").defaultTo(knex.fn.now());
table.timestamp("updated_at").defaultTo(knex.fn.now());
table.index("user_id");
});
// Migrate existing data
await knex.raw(`
INSERT INTO user_preferences (user_id, preferences)
SELECT id, jsonb_build_object(
'theme', COALESCE(theme, 'light'),
// ... (完整实现请参阅参考指南)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
| 指南 | 内容 |
|---|---|
| Knex.js 迁移 (Node.js) | Knex.js 迁移 (Node.js) |
| Alembic 迁移 (Python/SQLAlchemy) | Alembic 迁移 (Python/SQLAlchemy) |
| 使用批处理进行大规模数据迁移 | 使用批处理进行大规模数据迁移 |
| 零停机迁移模式 | 零停机迁移模式 |
| 迁移验证 | 迁移验证 |
| 跨数据库迁移 | 跨数据库迁移 |
up 和 down 迁移每周安装量
104
代码仓库
GitHub 星标数
116
首次出现
Jan 21, 2026
安全审计
安装于
opencode89
gemini-cli86
claude-code84
codex83
cursor80
github-copilot71
Create robust, safe, and reversible data migration scripts for database schema changes and data transformations with minimal downtime.
Minimal working example:
import { Knex } from "knex";
// migrations/20240101000000_add_user_preferences.ts
export async function up(knex: Knex): Promise<void> {
// Create new table
await knex.schema.createTable("user_preferences", (table) => {
table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()"));
table
.uuid("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE");
table.jsonb("preferences").defaultTo("{}");
table.timestamp("created_at").defaultTo(knex.fn.now());
table.timestamp("updated_at").defaultTo(knex.fn.now());
table.index("user_id");
});
// Migrate existing data
await knex.raw(`
INSERT INTO user_preferences (user_id, preferences)
SELECT id, jsonb_build_object(
'theme', COALESCE(theme, 'light'),
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Knex.js Migrations (Node.js) | Knex.js Migrations (Node.js) |
| Alembic Migrations (Python/SQLAlchemy) | Alembic Migrations (Python/SQLAlchemy) |
| Large Data Migration with Batching | Large Data Migration with Batching |
| Zero-Downtime Migration Pattern | Zero-Downtime Migration Pattern |
| Migration Validation | Migration Validation |
| Cross-Database Migration | Cross-Database Migration |
up and down migrationsWeekly Installs
104
Repository
GitHub Stars
116
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode89
gemini-cli86
claude-code84
codex83
cursor80
github-copilot71
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
133,300 周安装