<p>Having to upgrade a database schema makes installing a new release of software a lot trickier.  What are the best practices for doing this?</p>

<p>I'm looking for a checklist or timeline of action items, such as</p>

<ul>
<li>8:30 shut down apps</li>
<li>8:45 modify schema</li>
<li>9:15 install new apps</li>
<li>9:30 restart db</li>
</ul>

<p>etc, showing how to minimize risk and downtime.  Issues such as</p>

<ul>
<li>backing out of the upgrade if things go awry</li>
<li>minimizing impact to existing apps</li>
<li>"hot" updates while the database is running</li>
<li>promoting from dev to test to production servers</li>
</ul>

<p>are especially of interest.</p>

[{'answer_id': 31309, 'author': 'neslekkiM', 'author_id': 3308, 'author_profile': 'https://Stackoverflow.com/users/3308', 'pm_score': 2, 'selected': False, 'text': '<p>I guess you have considered the reads of Scott Ambler?\n<a href="http://www.agiledata.org/essays/databaseRefactoring.html" rel="nofollow noreferrer">http://www.agiledata.org/essays/databaseRefactoring.html</a></p>\n'}, {'answer_id': 31469, 'author': 'mk.', 'author_id': 1797, 'author_profile': 'https://Stackoverflow.com/users/1797', 'pm_score': 1, 'selected': False, 'text': '<p>This is a topic that I was just talking about at work. Mainly the problem is that unless database migrations is handled for you nicely by your framework, eg rails and their migration scripts, then it is left up to you. </p>\n\n<p>The current way that we do it has apparent flaws, and I am open to other suggestions. </p>\n\n<ol>\n<li>Have a schema dump with static data that is required to be there kept up to date and in version control. </li>\n<li>Every time you do a schema changing action, ALTER, CREATE, etc. dump it to a file and throw it in version control. </li>\n<li>Make sure you update the original sql db dump. </li>\n<li>When doing pushes to live make sure you or your script applies the sql files to the db. </li>\n<li>Clean up old sql files that are in version control as they become old.</li>\n</ol>\n\n<p>This is by no means optimal and is really not intended as a "backup" db. It\'s simply to make pushes to live easy, and to keep developers on the same page. There is probably something cool you could setup with capistrano as far as automating the application of the sql files to the db. </p>\n\n<p>Db specific version control would be pretty awesome. There is probably something that does that and if there isn\'t there probably should be. </p>\n'}, {'answer_id': 31481, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 4, 'selected': True, 'text': "<p>I have a lot of experience with this.  My application is highly iterative, and schema changes happen frequently.  I do a production release roughly every 2 to 3 weeks, with 50-100 items cleared from my FogBugz list for each one.  Every release we've done over the last few years has required schema changes to support new features.</p>\n\n<p>The key to this is to practice the changes several times in a test environment before actually making them on the live servers.</p>\n\n<p>I keep a deployment checklist file that is copied from a template and then heavily edited for each release with anything that is out of the ordinary.</p>\n\n<p>I have two scripts that I run on the database, one for schema changes, one for programmability (procedures, views, etc).  The changes script is coded by hand, and the one with the procs is scripted via Powershell.  The change script is run when everything is turned off (you have to pick a time that annoys the least amount of users for this), and it is run command by command, manually, just in case anything goes weird.  The most common problem I have run into is adding a unique constraint that fails due to duplicate rows.</p>\n\n<p>When preparing for an integration testing cycle, I go through my checklist on a test server, as if that server was production.  Then, in addition to that, I go get an actual copy of the production database (this is a good time to swap out your offsite backups), and I run the scripts on a restored local version (which is also good because it proves my latest backup is sound).  I'm killing a lot of birds with one stone here.</p>\n\n<p>So that's 4 databases total:</p>\n\n<ol>\n<li>Dev: all changes must be made in the change script, never with studio.</li>\n<li>Test: Integration testing happens here</li>\n<li>Copy of production: Last minute deployment practice</li>\n<li>Production</li>\n</ol>\n\n<p>You really, really need to get it right when you do it on production.  Backing out schema changes is hard.</p>\n\n<p>As far as hotfixes, I will only ever hotfix procedures, never schema, unless it's a very isolated change and crucial for the business.</p>\n"}, {'answer_id': 31562, 'author': 'andy47', 'author_id': 2661, 'author_profile': 'https://Stackoverflow.com/users/2661', 'pm_score': 1, 'selected': False, 'text': '<p>And if the Scott Ambler paper whets your appetite I can recommend his book with Pramod J Sadolage called \'Refactoring Databases\' - <a href="http://www.ambysoft.com/books/refactoringDatabases.html" rel="nofollow noreferrer">http://www.ambysoft.com/books/refactoringDatabases.html</a></p>\n\n<p>There is also a lot of useful advice and information at the Agile Database group at Yahoo - <a href="http://tech.groups.yahoo.com/group/agileDatabases/" rel="nofollow noreferrer">http://tech.groups.yahoo.com/group/agileDatabases/</a></p>\n'}, {'answer_id': 31677, 'author': 'Tyler Gooch', 'author_id': 1372, 'author_profile': 'https://Stackoverflow.com/users/1372', 'pm_score': 1, 'selected': False, 'text': '<p>Two quick notes:</p>\n\n<ol>\n<li><p>It goes without saying... So I\'ll say it twice.<br>\nVerify that you have a valid backup.<br>\nVerify that you have a valid backup.</p></li>\n<li><p>@mk.  Check out <a href="http://www.codinghorror.com/blog/archives/000743.html" rel="nofollow noreferrer">Jeff\'s blog post</a> on database version control (if you haven\'t already)</p></li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/31303', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/116/']