<html><body><div>Taking a backup of the database is a good thing to do in case of spotting an issue immediately on release. But bugs with a release often don't get seen immediately. Restoring to a backup could potentially mean losing days worth of data that would be really difficult to recover, so it's worth ensuring that you have a means of rolling back your schema changes.
</div><div><br></div><div>There's a book out there on database refactorings, although it's not specifically related to how ActiveRecord does it. Their catalog of refactorings is here:</div><div><a href="http://www.agiledata.org/essays/databaseRefactoringCatalogStructural.html">http://www.agiledata.org/essays/databaseRefactoringCatalogStructural.html</a>
</div><div><br></div><div>If the destructive aspect is just about dropping columns, then the usual practise is to flag those columns for deletion, and possibly rename when you release the code that no longer uses them. Once the new code has been active for a reasonable amount of time and has been shown to have no need for those columns, then a subsequent migration can do the drop as a stand-alone release.</div><div><br></div><div>I hope that's useful...</div><div><br></div><div>Steve</div><div><br></div><div><br></div><div><blockquote type="cite"><div class="msg-quote"><p style="color: #A0A0A8;" data-mce-style="color: #a0a0a8;">On Friday, 16 March 2012 at 10:52, Ian Kynnersley wrote:</p><blockquote style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;" type="cite" data-mce-style="border-left-style: solid; border-width: 1px; margin-left: 0px; padding-left: 10px;"><div><div>Hi,<div><br></div><div>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.</div><div><br></div><div>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?<br><div><br></div><div>The API docs say:</div><div><div>"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."<br></div><div><br></div><div>This seems to go along with my first option but seems unsatisfactory for a production app.</div><div><br></div><div>This covers some nice options (like backing up to a file): <a href="http://stackoverflow.com/a/621363/264376" data-mce-href="http://stackoverflow.com/a/621363/264376">http://stackoverflow.com/a/621363/264376</a> but I'm interested in what people on here think.</div><div><br></div><div><br></div></div><div>Cheers<br></div><div>Ian</div><div><br></div><div><br></div>-- <br> <br>Ian Kynnersley<br><a href="http://iankynnersley.co.uk" data-mce-href="http://iankynnersley.co.uk">http://iankynnersley.co.uk</a> | +44 (0) 7973 420 829 | <a href="http://twitter.com/kpopper" data-mce-href="http://twitter.com/kpopper">http://twitter.com/kpopper</a><br></div></div><div><div>_______________________________________________</div><div>Chat mailing list</div><div><a href="mailto:Chat@lists.lrug.org" data-mce-href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a></div><div><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" data-mce-href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a></div></div></div></blockquote><div><br></div><div class="_stretch">_______________________________________________<br> Chat mailing list<br> <a href="mailto:Chat@lists.lrug.org" data-mce-href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br> <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" data-mce-href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></div></div></blockquote></div></body></html>