aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/migrations.md
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source/migrations.md')
-rw-r--r--guides/source/migrations.md25
1 files changed, 22 insertions, 3 deletions
diff --git a/guides/source/migrations.md b/guides/source/migrations.md
index 086cf434d9..fcfc54a3d7 100644
--- a/guides/source/migrations.md
+++ b/guides/source/migrations.md
@@ -150,7 +150,25 @@ class AddPartNumberToProducts < ActiveRecord::Migration
end
```
-Similarly,
+If you'd like to add an index on the new column, you can do that as well:
+
+```bash
+$ rails generate migration AddPartNumberToProducts part_number:string:index
+```
+
+will generate
+
+```ruby
+class AddPartNumberToProducts < ActiveRecord::Migration
+ def change
+ add_column :products, :part_number, :string
+ add_index :products, :part_number
+ end
+end
+```
+
+
+Similarly, you can generate a migration to remove a column from the command line:
```bash
$ rails generate migration RemovePartNumberFromProducts part_number:string
@@ -834,7 +852,7 @@ end
# app/models/product.rb
class Product < ActiveRecord::Base
- validates :flag, presence: true
+ validates :flag, :inclusion => { :in => [true, false] }
end
```
@@ -859,7 +877,8 @@ end
# app/models/product.rb
class Product < ActiveRecord::Base
- validates :flag, :fuzz, presence: true
+ validates :flag, :inclusion => { :in => [true, false] }
+ validates :fuzz, presence: true
end
```