搜索

PythonReactSEOPDF
GitHub Skill

db-migration-generator

Generator สำหรับสร้าง database migration files พร้อม up/down scripts, validation และ rollback safety

AmnadTaowsoam☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

DB Migration Generator

Overview

สร้าง database migration files อัตโนมัติจาก schema changes พร้อม validation, rollback scripts และ safety checks

Why This Matters

  • Safety: Auto-generate rollback scripts
  • Consistency: Standard migration format
  • Validation: Check before apply
  • Documentation: Auto-document changes

Quick Start

# Generate migration
npx generate-migration add_users_table

# Output:
migrations/
└── 20240116120000_add_users_table.ts
    ├── up()    # Apply migration
    └── down()  # Rollback migration

Generated Migration

// 20240116120000_add_users_table.ts
export async function up(db: Database) {
  await db.schema.createTable('users', (table) => {
    table.uuid('id').primary();
    table.string('email').unique().notNullable();
    table.string('name').notNullable();
    table.timestamps(true, true);
  });
  
  await db.schema.createIndex('users', 'email');
}

export async function down(db: Database) {
  await db.schema.dropTable('users');
}

From Schema Diff

# Generate from Prisma schema changes
npx generate-migration --from-prisma

# Detects:
- New tables
- New columns
- Index changes
- Constraint changes

Safety Checks

// Auto-generated safety checks
export async function validate(db: Database) {
  // Check table doesn't exist
  const exists = await db.schema.hasTable('users');
  if (exists) {
    throw new Error('Table users already exists');
  }
  
  // Check dependencies
  // Check data integrity
}

Summary

DB Migration Generator: สร้าง migrations อัตโนมัติ

Features:

  • Up/down scripts
  • Rollback safety
  • Validation
  • From schema diff

Usage:

npx generate-migration add_users_table
npm run migrate

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!