Skip to content

Common Workflows

Add a column

php vendor/bin/migraw make add_phone_to_users

Raw example:

return $this->raw(<<<'SQL'
ALTER TABLE users
    ADD COLUMN phone VARCHAR(50) NULL;
SQL);

Fluent example:

return $this->alter('users')
    ->add('phone VARCHAR(50) NULL');

Add an index

return $this->alter('users')
    ->index('idx_users_email', 'email');

Add a foreign key

return $this->alter('posts')
    ->foreign(
        columns: 'user_id',
        referencesTable: 'users',
        referencesColumns: 'id',
        name: 'fk_posts_user',
        onDelete: 'CASCADE'
    );

Preview a migration

php vendor/bin/migraw migrate --dry-run

Undo the latest batch

php vendor/bin/migraw rollback

Rebuild a development database

php vendor/bin/migraw fresh

Check for modified migrations

php vendor/bin/migraw status

If an executed migration was intentionally changed:

php vendor/bin/migraw repair --modified

Compact a long migration history

php vendor/bin/migraw migrate
php vendor/bin/migraw squash app_schema

Restore the pre-squash migration history

php vendor/bin/migraw unsquash