9 ms·
How do you manage things like database schema (except by switching to schema-less database :) ), is it your software which is suppose to create it if non existi
by allan_s 11y ago
How do you manage things like database schema (except by switching to schema-less database :) ), is it your software which is suppose to create it if non existing ?
In case the database is pristine, ok I see, I do a "create table if not exist"
But if the database is at version N and I want to go version N+1 , what do I do? I mean I do know about database migration tools, but how does it integrates in your "pure 12factor" deployement, as it means when you deploy you need to have at least this order:
1. bring up the database
2. run the migration script
3. bring up the application
and the article was advocating to make things in a way that you don't need to have a "you MUST first run this, then that"
- spotman 11y agoOne way to think about this that maybe overlaps with the theme of this article, but also stands on its own with specific regard to database modifications is that you often need to have the ability to have multiple versions of everything alive at one point in time. So maybe that's a schema A and a schema B, or maybe you have applied schema B which only app version 1.1 is optimized for , but version 1.0 is what is in production immediately following your database migration. So you can't make changes in schema B that would immediately render app 1.0 broken, which means you need to not box yourself into a corner with future assumptions as much as possible. Ultimately if downtime is not an option you end up writing these capabilities in at every layer. Whether it's an api endpoint or code talking to a database you often have to make carefully thought out changes incrementally to ensure that things can all operate simultaneously, and often this ends up having metadata about the versions of everything as an option for taking different code paths. This article touches on this in the way that if suggests making your app deal with an available database and one that is not available. Same with a field in a schema or a payload. To make your code less brittle instruct it what to do in both cases.
- zimbatm 11y agoThreat your database like an API and only introduce backward-compatible changes. For example if you want to rename a column, make a new column with the target name and a trigger that keeps both columns in sync. Once the new code is deployed everywhere you can remove the trigger and the old column.