Scenario: we already have a Document model, and we want to add
- public
- private
or more columns using a single migration.
From what I’ve searched and read so far, you just have to edit the migration file. If the migration was already applied, roll back and migrate again.
- Is this the common best practice, or is there a better way?
- If this is the way to do it, what would a proper naming for that migration be?
Rolling back a migration and re-editing it is only safe if that migration is local and has not been pushed out to any repository. Editing a migration that others have applied may cause issues.
The safest way to add columns to an existing table is to just create a new migration:
If you use the
add_[column_names]_to_[model]naming convention, rails will work out the appropriate table and create the migration you want.Have a read here for more info: http://guides.rubyonrails.org/migrations.html