Refactoring Has Proven Its Value in a Wide Range of Development
Total Page:16
File Type:pdf, Size:1020Kb
Refactoring Databases: Evolutionary Database Design By Scott W. Ambler, Pramod J. Sadalage ............................................... Publisher: Addison Wesley Professional Pub Date: March 06, 2006 Print ISBN-10: 0-321-29353-3 Print ISBN-13: 978-0-321-29353-4 Pages: 384 Table of Contents | Index Refactoring has proven its value in a wide range of development projectshelping software professionals improve system designs, maintainability, extensibility, and performance. Now, for the first time, leading agile methodologist Scott Ambler and renowned consultant Pramodkumar Sadalage introduce powerful refactoring techniques specifically designed for database systems. Ambler and Sadalage demonstrate how small changes to table structures, data, stored procedures, and triggers can significantly enhance virtually any database designwithout changing semantics. You'll learn how to evolve database schemas in step with source codeand become far more effective in projects relying on iterative, agile methodologies. This comprehensive guide and reference helps you overcome the practical obstacles to refactoring real-world databases by covering every fundamental concept underlying database refactoring. Using start-to-finish examples, the authors walk you through refactoring simple standalone database applications as well as sophisticated multi-application scenarios. You'll master every task involved in refactoring database schemas, and discover best practices for deploying refactorings in even the most complex production environments. The second half of this book systematically covers five major categories of database refactorings. You'll learn how to use refactoring to enhance database structure, data quality, and referential integrity; and how to refactor both architectures and methods. This book provides an extensive set of examples built with Oracle and Java and easily adaptable for other languages, such as C#, C++, or VB.NET, and other databases, such as DB2, SQL Server, MySQL, and Sybase. Using this book's techniques and examples, you can reduce waste, rework, risk, and costand build database systems capable of evolving smoothly, far into the future. Refactoring Databases: Evolutionary Database Design By Scott W. Ambler, Pramod J. Sadalage ............................................... Publisher: Addison Wesley Professional Pub Date: March 06, 2006 Print ISBN-10: 0-321-29353-3 Print ISBN-13: 978-0-321-29353-4 Pages: 384 Table of Contents | Index Copyright Praise for Refactoring Databases The Addison-Wesley Signature Series The Addison-Wesley Signature Series About the Authors Forewords Preface Why Evolutionary Database Development? Agility in a Nutshell How to Read This Book About the Cover Acknowledgments Chapter 1. Evolutionary Database Development Section 1.1. Database Refactoring Section 1.2. Evolutionary Data Modeling Section 1.3. Database Regression Testing Section 1.4. Configuration Management of Database Artifacts Section 1.5. Developer Sandboxes Section 1.6. Impediments to Evolutionary Database Development Techniques Section 1.7. What You Have Learned Chapter 2. Database Refactoring Section 2.1. Code Refactoring Section 2.2. Database Refactoring Section 2.3. Categories of Database Refactorings Section 2.4. Database Smells Section 2.5. How Database Refactoring Fits In Section 2.6. Making It Easier to Refactor Your Database Schema Section 2.7. What You Have Learned Chapter 3. The Process of Database Refactoring Section 3.1. Verify That a Database Refactoring Is Appropriate Section 3.2. Choose the Most Appropriate Database Refactoring Section 3.3. Deprecate the Original Database Schema Section 3.4. Test Before, During, and After Section 3.5. Modify the Database Schema Section 3.6. Migrate the Source Data Section 3.7. Refactor External Access Program(s) Section 3.8. Run Your Regression Tests Section 3.9. Version Control Your Work Section 3.10. Announce the Refactoring Section 3.11. What You Have Learned Chapter 4. Deploying into Production Section 4.1. Effectively Deploying Between Sandboxes Section 4.2. Applying Bundles of Database Refactorings Section 4.3. Scheduling Deployment Windows Section 4.4. Deploying Your System Section 4.5. Removing Deprecated Schema Section 4.6. What You Have Learned Chapter 5. Database Refactoring Strategies Section 5.1. Smaller Changes Are Easier to Apply Section 5.2. Uniquely Identify Individual Refactorings Section 5.3. Implement a Large Change by Many Small Ones Section 5.4. Have a Database Configuration Table Section 5.5. Prefer Triggers over Views or Batch Synchronization Section 5.6. Choose a Sufficient Transition Period Section 5.7. Simplify Your Database Change Control Board (CCB) Strategy Section 5.8. Simplify Negotiations with Other Teams Section 5.9. Encapsulate Database Access Section 5.10. Be Able to Easily Set Up a Database Environment Section 5.11. Do Not Duplicate SQL Section 5.12. Put Database Assets Under Change Control Section 5.13. Beware of Politics Section 5.14. What You Have Learned Online Resources Chapter 6. Structural Refactorings Common Issues When Implementing Structural Refactorings Drop Column Drop Table Drop View Introduce Calculated Column Introduce Surrogate Key Merge Columns Merge Tables Move Column Rename Column Rename Table Rename View Replace LOB With Table Replace Column Replace One-To-Many With Associative Table Replace Surrogate Key With Natural Key Split Column Split Table Chapter 7. Data Quality Refactorings Common Issues When Implementing Data Quality Refactorings Add Lookup Table Apply Standard Codes Apply Standard Type Consolidate Key Strategy Drop Column Constraint Drop Default Value Drop Non-Nullable Introduce Column Constraint Introduce Common Format Introduce Default Value Make Column Non-Nullable Move Data Replace Type Code With Property Flags Chapter 8. Referential Integrity Refactorings Add Foreign Key Constraint Add Trigger For Calculated Column Access Program Update Mechanics Drop Foreign Key Constraint Introduce Cascading Delete Introduce Hard Delete Introduce Soft Delete Introduce Trigger For History Chapter 9. Architectural Refactorings Add CRUD Methods Add Mirror Table Add Read Method Encapsulate Table With View Introduce Calculation Method Introduce Index Introduce Read-Only Table Migrate Method From Database Migrate Method To Database Replace Method(s) With View Replace View With Method(s) Use Official Data Source Chapter 10. Method Refactorings Section 10.1. Interface Changing Refactorings Section 10.2. Internal Refactorings Chapter 11. Transformations Insert Data Introduce New Column Introduce New Table Introduce View Update Data The UML Data Modeling Notation Glossary References and Recommended Reading List of Refactorings and Transformations Index Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 [email protected] For sales outside the United States, please contact: International Sales [email protected] Visit us on the Web: www.awprofessional.com Library of Congress Cataloging-in-Publication Data Ambler, Scott W., 1966- Refactoring databases : evolutionary database design / Scott W. Ambler and Pramod J. Sadalage. p. cm. Includes index. ISBN 0-321-29353- 3 (hardback : alk. paper) 1. Database design. 2. Computer softwareDevelopment. 3. Evolutionary programming (Computer science) I. Sadalage, Pramod J. II. Title. QA76.9.D26A52 2006 005.74dc22 2005031959 Copyright © 2006 Scott W. Ambler and Pramodkumar J. Sadalage All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to: Pearson Education, Inc. Rights and Contracts Department 75 Arlington Street, Suite 300 Boston, MA 02116 Fax: (617) 848-7047 Text printed in the United States on recycled paper at R. R. Donnelley in Crawfordsville, Indiana. First printing, March 2006 Dedication Scott: For Beverley, my lovely new bride. Pramod: To the women I love most, Rupali and our daughter, Arula. Praise for Refactoring Databases "This groundbreaking book finally reveals why database schemas need not be difficult to change, why data need not be difficult to migrate, and why database professionals need not be overburdened by change requests from customers and developers. Evolutionary design is at the heart of agility. Ambler and Sadalage have now shown the world how to evolve agile databases. Bravo!" Joshua Kerievsky,