Using SQL Updateable Views to do live refactoring

Recently I inherited a project with a doubly ugly code base. Both the C# and the database were ugly.  To describe it simply, property information was gathered from various counties with the column names matching the terms each county used on their web site and each county given it’s own table.  A totally denormalized datamodel from purgatory.

 

The project is live and thus options for a refactor were reduced. The first step was to build an application that allowed everything to be mapped to standardized field names. Once that was done, the magic was to create an updatable view on each table using the new field names. Super-setting the fields ended up a UNION able set of views with the same field names. Voila, I could start doing new development or refactors against these views while not breaking the existing ugly code base as well as providing cross county queries easily

 

As more and more refactoring happens, I can then flip the views to tables and retire the tables from hell.  It’s a practical solution to a really messy problem with a relatively clean path.

Comments

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape