If one were to have a database that was used by a lot of different code, what would be the most practical process to disseminating database changes throughout?
I have a personal mysql database that I’m continually “evolving”. However, I also have a lot of PHP code that’s already established to use specific column names in this database. Other than manually finding/replacing column names throughout the code, is there an established method/way/process for altering column names and disseminating that throughout the code?
From my limited view, I imagine it might need to be approached from the language side of the equation, i.e., perhaps some type of extension functionality, like with PDO.
Perhaps just a “buffer” layer of defining the current database column names as variables at the beginning of the code is the simplest way?
The best thing to do is to separate the persistence of data from how that data is used in your app. The structure of your database should not define the structure of your app. Inside your app, you pass data around via objects or defined array structures. At some specified point, you store these objects/arrays into the database because you want to persist them for later use. To do this you have one defined point where your data objects/arrays are put into the database and vice-versa. Which means this point is the only point where you are referring to database-specific names. If you need to change the database schema, you only need to update the thin layer that deals with database-object conversion; you won’t need to update “the whole app” because the rest of the application refers to the naming of your defined data objects.
This is typically known as Object-Relational Mapping, Data Access Layer and other related techniques.
The translation between the database structure and tangible data objects only happens in the DAL. The rest of the app just talks to the DAL to get or store data objects, it does not need to know or care what exactly the database structure looks like.