3
votes

Let's say I create a rake task to add a column to a table. After I run that rake task, can I delete the rake file while keeping the changes to the database?

I understand that a migration could accomplish this same type of task, but if I want to cut down on running migrations for such simple database changes, is a rake task acceptable?

Apologies if this is a rookie question, I did some searching and could not find a suitable answer.

2

2 Answers

3
votes

You should definitively use migrations. If you create a rake task and then delete it, the changes will only be applied to this instance of your database (which can be a development database).

When you deploy your application to production, or even run your specs, you would have to manually add the new column again to update the database schema.

Besides, when using migrations you will have a history of your database evolution schema over time.

1
votes

The simpliest way to add/remove columns to a table is the migration. One big advantage of the migrations is that you are able to set up your db to the exact progress of your app.

If you'll do it with a additional rake task - and there is no reason to do this - I promise you will forget to run these rake task in a few days/weeks if you need to set up your db from scratch. Especially if you delete your rake task after adding the cols.

HTH