π 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.
π 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:
master: stable code, production-readydevelop: collects the changes to release at the end of the sprint and any urgent fixessprint: the active branch for the current sprint (archived and recreated every two weeks)feature/fix: branches dedicated to single features, integrated intosprintwith squash merges
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! β
