Refactoring Databases

Evolutionary Database Design

by Scott J Ambler and Pramod J. Sadalage

2006

A decade ago 'refactoring' was a word only known to a few people, mostly in the Smalltalk community. It's been wonderful to watch more and more people learn how to use refactoring to modify working code in a disciplined and effective manner. As a result many people now see code refactoring as an essential part of software development.

I live in the world of enterprise applications, and a big part of enterprise application development is working with databases. In my original book on refactoring I picked out databases as a major problem area in refactoring since refactoring databases introduces a new set of problems. These problems are exacerbated by the sad division that's developed in the enterprise software world where database professionals and software developers are separated by a wall of mutual incomprehension and contempt.

One of the things I like about Scott and Pramod is that, in different ways, they have both worked hard to try and cross this division. Scott's writings on databases have been a consistent attempt to bridge the gap, his work on object-relational mapping has been a great influence on my own writings on enterprise application architecture. Pramod may be less known, but his impact has been just as great on me. When he started work on a project with me at Thoughtworks we were told that refactoring of databases was impossible. Pramod rejected that notion, taking some sketchy ideas and turning them into a disciplined program that kept the database schema in constant, but controlled motion. This freed up the application developers to use evolutionary design in the code too. Pramod has since taken these techniques to many of our clients, spreading them around our Thoughtworks colleagues and, at least for us, forever banishing databases from the list of roadblocks to continual design.

This book assembles the lessons of two people who have lived in the no-mans land between applications and data and presents a guide on how to use refactoring techniques for databases. If you're familiar with refactoring you'll notice that the major change is that not just do you have to change program and data structures, you also have to manage continual migration of the data itself. This book tells you how to do that, backed by the project experience (and scars) that these two have accumulated.

Much though I'm delighted by the appearance of this book, I also hope it's only a first step. After my refactoring book appeared I was delighted to find sophisticated tools appear with automated many refactoring tasks. I hope the same thing happens with databases, and we begin to see vendors offer tools that make continual migrations of schema and data easier for everyone. Before that happens this book will help you build your own processes and tools to help; afterwards this book will have lasting value as a foundation for using such tools successfully.

Further Reading

Database Refactoring Website

Website for the book with summaries of the refactorings.

Data Management Guide

More material on this site on databases and data management