Modifications to the model and relational database

4

The requirements for developing a system in general change over time. Several approaches to software development such as agile methods and Domain-Driven Design even encourage an iterative approach in which we delve into the real needs of a system over time.

In addition, when building any system it is very important to know the domain of the problem being solved and, in this case, this knowledge deepens over time.

As end users are using the developed system it also happens that they recognize points that need to be modified because there are some requirements that have been forgotten or not well understood. In fact, from what I've already read there are approaches that encourage the software to be developed by parties and that as they already have working parts users already have access to validate what was done and provide that feedback.

So far so good. The bigger problem is this: when the system is already being used there is a real production database containing the actual data of the users. These data, considering relational databases, are table representations of domain model objects.

Now, let's assume that a modification is required in the domain model that strips some properties and / or places others. An example would be a data that is currently represented in a single property, but will be represented in several, or some data that did not exist before and was placed.

Modifying the domain model is relatively easy, especially if we are using object orientation the right way. Of course, the larger the system, the more modification can have an impact, but it is still more treatable because it can be fully worked on in the development environment.

On the other hand, when applying such modifications, the template is no longer synchronized with the database. A new table structure would be needed to accommodate the new data. And the fact that there are user data that simply can not be thrown away and need to accommodate the new model is a huge headache.

In this case, the relational database ends up hampering domain model improvement.

My approach in some situations was to create a utility that transforms the old bank into the new one: we implemented mapping classes that take an object from the old model and return one from the new model. From there we make a utility that runs through the production database converts the objects and persists in a new bank.

This approach, however, does not seem to be the most efficient.

So I ask: how to deal with this situation? How can I work with the domain model freely and at the same time synchronize with the data in the production database?

    
asked by anonymous 15.02.2016 / 19:01

1 answer

1

Your concern to not let there be a great distance between the relational data model and the domain model is really important , however we have that Domain model:

  • Contains knowledge about a problem / knowledge, fruit the collaboration between business experts and development;
  • Enables the developer to communicate with business experts in a natural language;
  • You are connected to the implementation of your code and not to your database.

Quote: I found the following passage in the book ...

  

Technically, the design of relational tables does not have to reflect the   domain model. The mapping tools are sophisticated enough to handle significant direrences.

That is, the DDD does not say to keep your domain model or your business object synchronized with the database , it would be great if your business object was synchronized with your DB, but , this is not always possible, you are not always developing the bank as you develop your code. On the contrary, it has cases that this synchronization really is not possible, like a DB that was created for another system for example.

So, thinking of a case where you have a field in the relational DB and you for some reason need to keep it, but that field no longer exists in your object because of a new requested change, an interesting alternative is to stop mapping the field would not be retrieved again, it would be as if the field did not even exist in the DB.

    
15.02.2016 / 20:43