Mi
mi
is a generator of migration file instead of rails generate migration
.
- Simple Syntax
- Automatically generate class name.
Installation
Add this line to your application's Gemfile:
group :development do
gem 'mi'
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install mi
Usage
add_column
$ bin/rails g mi users +email:string
create db/migrate/20160429062420_add_email_to_users.rb
db/migrate/20160429062420_add_email_to_users.rb
class AddEmailToUsers < ActiveRecord::Migration
def change
add_column :users, :email, :string
end
end
remove_column
$ bin/rails g mi users -email
create db/migrate/20160429124502_remove_email_to_users.rb
db/migrate/20160429124502_remove_email_to_users.rb
class RemoveEmailToUsers < ActiveRecord::Migration
def change
remove_column :users, :email
end
end
change_column
$ bin/rails g mi users %email:string:{null:true}
create db/migrate/20160429124852_change_email_to_users.rb
db/migrate/20160429124852_change_email_to_users.rb
class ChangeEmailToUsers < ActiveRecord::Migration
def change
change_column :users, :email, :string, null: true
end
end
create_table
$ bin/rails g mi:create users +email:string:{null:false} +name:string
create db/migrate/20160704144601_create_users_table.rb
db/migrate/20160704144601_create_users_table.rb
class CreateUsersTable < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :email, null: false
t.string :name
t.timestamps null: false
end
end
end
Open with editor
Put a --edit
option, mi opens the migration file after generated.
$ bin/rails g mi users +email:string --edit
Dependencies
- Ruby 2.2 or higher
- Rails 4 or higher
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/mi.