I maintain a large legacy app working with SQL database. The app uses raw SQL queries to query the database. Together with app rewrite I plan to introduce ORM to work with the database.
The simplest solution would be to keep the database in current state and build ORM mappings based on the existing database. It seems to be quite common approach, and many tools exist on different platforms to automatically reverse-engineer the database into the ORM (e.g. Django - inspectdb, MikroORM - Entity Generator, Entity Framework Scaffolding).
Another opinion however says that one should always design ORM entities first and create database schema based on them and that the reverse engineering idea is perverted and leads to enormous problems. I don't quite understand this. When the existing database is logically designed and normalized, how would it conceptually differ from ORM entities?
Some ideas that come to my mind:
- ORM may use its own naming conventions in the db. schema
- ORM may implement table relations (1:N, M:N) differently
- ORM may offer some functionality for which the existing schema isn't designed (e.g. entities inheritance)
- existing schema relies on database functionalities that ORM doesn't support (unusual data types, stored functions, triggers...)
- existing database tables aren't designed with OOP in mind, i.e. database entities don't correspond to programming language objects and their behaviour (but how? this is still vague for me)
- design of the existing database may assume that the data will be queried using raw SQL queries rather than much simpler ORM manipulation
I understand that ORM creates db. schema automatically and that the resulting schema is often a "black-box" for the developer. However building ORM on top of existing schema is still possible (the complications mentioned above aren't very common) and it seems to be better solution than break the whole database structure of existing app.
Is preserving the existing database worth even when doing complete app rewrite?
(The question is platform independent, however I am personally interested mainly in Node.js and PHP.)