1

Lately I need to do an impact analysis on changing a DB column definition of a widely used table (like PRODUCT, USER, etc). I find it is a very time consuming, boring and difficult task. I would like to ask if there is any known methodology to do so?

The question also apply to changes on application, file system, search engine, etc. At first, I thought this kind of functional relationship should be pre-documented or some how keep tracked, but then I realize that everything can have changes, it would be impossible to do so.

I don't even know what should be tagged to this question, please help.

Sorry for my poor English.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
Levin Kwong
  • 393
  • 1
  • 3
  • 7
  • Yes, the relationships **must** be documented. It mainly depends on *how well* you or your predecessor(s) designed the application. Try to see the question from a software architect point of view rather from coder – usr-local-ΕΨΗΕΛΩΝ Feb 22 '16 at 11:27

3 Answers3

2

Sure. One can technically at least know what code touches the DB column (reads or writes it), by determining program slices.

Methodology: Find all SQL code elements in your sources. Determine which ones touch the column in question. (Careful: SELECT ALL may touch your column, so you need to know the schema). Determine which variables read or write that column. Follow those variables wherever they go, and determine the code and variables they affect; follow all those variables too. (This amounts to computing a forward slice). Likewise, find the sources of the variables used to fill the column; follow them back to their code and sources, and follow those variables too. (This amounts to computing a backward slice).

All the elements of the slice are potentially affecting/affected by a change. There may be conditions in the slice-selected code that are clearly outside the conditions expected by your new use case, and you can eliminate that code from consideration. Everything else in the slices you may have inspect/modify to make your change.

Now, your change may affect some other code (e.g., a new place to use the DB column, or combine the value from the DB column with some other value). You'll want to inspect up and downstream slices on the code you change too.

You can apply this process for any change you might make to the code base, not just DB columns.

Manually this is not easy to do in a big code base, and it certainly isn't quick. There is some automation to do for C and C++ code, but not much for other languages.

You can get a bad approximation by running test cases that involve you desired variable or action, and inspecting the test coverage. (Your approximation gets better if you run test cases you are sure does NOT cover your desired variable or action, and eliminating all the code it covers).

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
1

Eventually this task cannot be automated or reduced to an algorithm, otherwise there would be a tool to preview refactored changes. The better you wrote code in the beginning, the easier the task.

Let me explain how to reach the answer: isolation is the key. Mapping everything to object properties can help you automate your review.

I can give you an example. If you can manage to map your specific case to the below, it will save your life.

The OR/M change pattern

Like Hibernate or Entity Framework...

A change to a database column may be simply previewed by analysing what code uses a certain object's property. Since all DB columns are mapped to object properties, and assuming no code uses pure SQL, you are good to go for your estimations


This is a very simple pattern for change management.

In order to reduce a file system/network or data file issue to the above pattern you need other software patterns implemented. I mean, if you can reduce a complex scenario to a change in your objects' properties, you can leverage your IDE to detect the changes for you, including code that needs a slight modification to compile or needs to be rewritten at all.

  • If you want to manage a change in a remote service when you initially write your software, wrap that service in an interface. So you will only have to modify its implementation
  • If you want to manage a possible change in a data file format (e.g. length of field change in positional format, column reordering), write a service that maps that file to object (like using BeanIO parser)
  • If you want to manage a possible change in file system paths, design your application to use more runtime variables
  • If you want to manage a possible change in cryptography algorithms, wrap them in services (e.g. HashService, CryptoService, SignService)

If you do the above, your manual requirements review will be easier. Because the overall task is manual, but can be aided with automated tools. You can try to change the name of a class's property and see its side effects in the compiler

Worst case

Obviously if you need to change the name, type and length of a specific column in a database in a software with plain SQL hardcoded and shattered in multiple places around the code, and worse many tables present similar column namings, plus without project documentation (did I write worst case, right?) of a total of 10000+ classes, you have no other way than manually exploring your project, using find tools but not relying on them.

And if you don't have a test plan, which is the document from which you can hope to originate a software test suite, it will be time to make one.

Community
  • 1
  • 1
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
0

Just adding my 2 cents. I'm assuming you're working in a production environment so there's got to be some form of unit tests, integration tests and system tests already written.

If yes, then a good way to validate your changes is to run all these tests again and create any new tests which might be necessary.

And to state the obvious, do not integrate your code changes into the main production code base without running these tests.

Yet again changes which worked fine in a test environment may not work in a production environment. Have some form of source code configuration management system like Subversion, GitHub, CVS etc. This enables you to roll back your changes

pcodex
  • 1,812
  • 15
  • 16