Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lennhy/3071aa18c9e908ab3fd362ef2e8fa847 to your computer and use it in GitHub Desktop.
Save lennhy/3071aa18c9e908ab3fd362ef2e8fa847 to your computer and use it in GitHub Desktop.
Rails Migration - Cheatsheet

Rails Migration

http://guides.rubyonrails.org/migrations.html

Migrations methods:

  • add_column
  • add_index
  • change_column
  • change_table
  • create_table
  • drop_table
  • remove_column
  • remove_index
  • rename_column

Basic format YYYYMMDDHHMMSS_create_products.rb

Supported types

  • :binary
  • :boolean
  • :date
  • :datetime
  • :decimal
  • :float
  • :integer
  • :primary_key
  • :string
  • :text
  • :time
  • :timestamp especial type:
  • :references

Commands to create migrations

$ rails generate model Product name:string description:text
$ rails generate migration AddPartNumberToProducts part_number:string
$ rails generate migration RemovePartNumberFromProducts part_number:string
$ rails generate migration AddDetailsToProducts part_number:string price:decimal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment