πŸ• Reading time: 3 minutes

Over the past few months, my team and I carried out a complex migration of the data model that involved both the database and the various backend layers querying it. It was an intricate process, touching the very foundations of the project and running in parallel with the platform's functional evolution.

Layered backend architecture: Controller, Converter, Service, ServiceImpl, Repository, Database

πŸ“Œ Refactoring and decoupling – from model objects to DTOs

The first challenge was refactoring the repository layer: we rewrote the pre-existing queries, shared across several services, taking a horizontal approach to query the new schema consistently. For the upper layers (service and converter) we moved domain by domain with a vertical approach, gradually aligning the system with the new model. Crucial, from the start, was the decoupling between model objects and DTOs, which let us isolate the database changes without impacting the FE.

πŸ“Œ A robust test suite against regressions

To prevent regressions compared to the old model and ensure maximum stability, we extended and updated the already robust existing test suite. It includes around 100 integration tests, runnable both on Docker-containerised databases and on a local DB, and over 500 unit tests covering every layer of the project, reaching a code coverage above 90%.

πŸ“Œ Branch management – organising and isolating the new developments

To handle the migration without blocking ongoing development, we relied on a four-level GIT repository:

We created a separate branch (migration) running parallel to develop/sprint, where we concentrated the migration changes. Once the manual QA tests and the final refinements are done, we'll merge it into develop.

πŸ“Š The migration in numbers

To give an idea of the scale, the final git diff --shortstat speaks for itself:

687 files changed, 17.508 insertions(+), 16.649 deletions(-)

In conclusion, this migration wasn't just a technical change, but a real test bed for our architectural and code-management strategies. Through a methodical approach, we showed how it's possible to tackle complex challenges without compromising the system's stability.

See you at the next pill! β˜•