Use the create method of MigrationCreator to generate a new migration file. The method automatically prefixes the filename with a timestamp in the format YYYY_MM_DD_HHmmss.
Depending on the arguments provided, it selects different stubs:
- If
table is null: Uses migration-js.stub. - If
table is provided and create is true: Uses migration.create-js.stub. - If
table is provided and create is false: Uses migration.update-js.stub.
If a table name is provided, the stub's DummyTable or {{\s*table\s*}} placeholders are replaced with the actual table name.
const MigrationCreator = require('./path/to/migration-creator');
// Initialize with a path to custom stubs if available
const creator = new MigrationCreator('./custom-stubs');
// Create a 'create' migration for a table named 'users'
const filePath = await creator.create('add_users_table', './migrations', 'users', true);
// Create an 'update' migration for a table named 'users'
const updatePath = await creator.create('add_email_to_users', './migrations', 'users', false);