How to improve a legacy codebase
- Begin with a backup - copy everything to a safe place in read-only mode. And check if the codebase has a build process and that it actually produces what runs in production.
- Freeze the DB schema until you are done with the first level of improvements. It allows you to compare the effect your new business logic code has compared to the old business logic code.
- When adding instrumentation to the old platform in a completely new database table, add a simple counter for every event and a single function to increment these counters based on the name of the event.
- Never try improving both the maintainability of the code or the platform it runs on at the same time as adding new features or fixing bugs. It will invalidate some of the tests you made earlier.
- When migrating to a new platform, all business logic and interdependencies should remain exactly the same as before.
- Test the new DB with the new code and all the tests in place to ensure your migration goes off without a hitch.
Full post here, 11 mins read