nonopolarity
nonopolarity

Reputation: 150986

In Rails 3.2.3, can a migration to add index be created on the command line?

It might be convenient to put all the lines we type inside of bash to create the whole initial project inside a script, for all the scaffold creations, rake db:migrate, and even the git commands, so that if we ever need to create the same project under Rails 4 or 5, that will be very simple.

But for a migration file that adds index to a table column, is there a way to specify that on the command line or somehow automate that on the command line? Otherwise we will need to put in the command for the migration file creation and then manually edit that file by hand -- if everything can be put in a script, that can be kind of neat.

(or if the index can be specified in the scaffold line, that might be even better)

Upvotes: 0

Views: 431

Answers (1)

dogenpunk
dogenpunk

Reputation: 4382

When generating your model's migration, use index after the field name for a regular index and uniq for a unique index.

Example:

$rails g resource Widget name:index part_number:uniq

You can probably do something similar when generating just a migration

Upvotes: 1

Related Questions