[LRUG] Destructive Migrations - best practices

Jon Wood jon at blankpad.net
Fri Mar 16 03:55:12 PDT 2012


The approach I would recommend depends how sure you are that you don't need those columns, and won't in the future. If they really are unnecessary, take a backup of the database, and then remove them. It'll save you a world of confusion a few years down the line when trying to work out which bits of the database you actually use.

However, if it's more of a trial run, and there's a good likelihood of needing the data back again leave the columns in place for now, but do make a note to review that at some point in the future.  


On Friday, 16 March 2012 at 10:52, Ian Kynnersley wrote:

> Hi,
> 
> In one of my current projects, the implementation of one of the models is changing a reasonable amount. There will be a batch of new fields and a couple that are no longer required.
> 
> What is the best practice for writing migrations that remove columns from tables? I'm thinking specifically of providing the ability to rollback the changes. Should I ignore this and just write an "up" migration to delete the columns? Should I create a duplicate table at the point of the migration to keep a history of the data in those columns? Should I leave them in the database to fester while removing references to them from the code?
> 
> The API docs say:
> "Some transformations are destructive in a manner that cannot be reversed. Migrations of that kind should raise an ActiveRecord::IrreversibleMigration exception in their down method."
> 
> This seems to go along with my first option but seems unsatisfactory for a production app.
> 
> This covers some nice options (like backing up to a file): http://stackoverflow.com/a/621363/264376 but I'm interested in what people on here think. 
> 
> 
> Cheers
> Ian
> 
> 
> -- 
> 
> Ian Kynnersley
> http://iankynnersley.co.uk | +44 (0) 7973 420 829 | http://twitter.com/kpopper
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org (mailto:Chat at lists.lrug.org)
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120316/4afba004/attachment-0003.html>


More information about the Chat mailing list