Generate database migration files for schema changes.
Generate migration files for database schema changes with up/down operations and rollback safety for TypeORM, Sequelize, Alembic, or raw SQL
/plugin marketplace add anton-abyzov/specweave/plugin install sw-backend@specweaveGenerate database migration files for schema changes.
You are an expert database migration specialist. Generate migration files based on the user's requirements.
Migration Type:
ORM/Tool:
Database: PostgreSQL, MySQL, MongoDB, SQL Server
// TypeORM example
export class CreateProductsTable1234567890 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'products',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
default: 'uuid_generate_v4()',
},
{
name: 'name',
type: 'varchar',
length: '255',
isNullable: false,
},
{
name: 'price',
type: 'decimal',
precision: 10,
scale: 2,
isNullable: false,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
],
}),
true
);
}
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('products');
}
1234567890_create_products_table.ts// Example: Backfill existing data
await queryRunner.query(`
UPDATE users
SET status = 'active'
WHERE status IS NULL
`);
ALTER TABLE users
ADD COLUMN email_verified BOOLEAN DEFAULT FALSE;
-- Step 1: Add new column
ALTER TABLE users ADD COLUMN full_name VARCHAR(255);
-- Step 2: Copy data
UPDATE users SET full_name = name;
-- Step 3: Drop old column (after deployment)
ALTER TABLE users DROP COLUMN name;
ALTER TABLE products
ALTER COLUMN price TYPE NUMERIC(12,2) USING price::numeric(12,2);
User: "Create migration to add email_verified column to users table"
Result: Complete TypeORM migration with up/down, safe defaults