I don’t know much about migrations, but this is a specific question I’m not sure how to answer.
In production, how can one change the database format/schema when there is already user data in there? (Is the answer different for our Meteor app on MongoDB vs our master Postgres database?) Basically, if you write new code that introduces a new field, and new code that expects that new field to be present, then the system will not work when pulling data from the database that was there prior to the changeover.
For Mongo at least, a possible solution is to write a script to update the database layout with the data in it, but I wonder if this is too error prone for a production database, and infeasible when you just don’t have the necessary information (like if you didn’t collect a certain info field from the user before.)
4
if you write new code that introduces a new field, and new code that expects that new field to be present, then the system will not work when pulling data from the database that was there prior to the changeover.
You have to take that into account when you are writing your code. You could run a script when you deploy the new changes to populate this field with a default value. You could write your code so that it is able to handle the situation where the field is no present/populated.
Exactly what you do will probably depend on the details of your situation, but you’re correct: you have to do something to handle this.
…And it goes without saying that you should test this migration process thoroughly (on a copy of production, if possible) before running it in a production system. 😉
Be sure to act atomically and keep the update time short
- Prepare the migration
- Prepare the code modification to the new schema
- Migrations should contains new field with default value or null allowances, foresight for column alteration size limit or data casting (eventually dropping it and creating it on a new column as before), delete all the needed columns straight
- Code should introduce null-safety checks when needed
- Publish the new code and run the migration simultaneously (eventually with minimal production downtime)
Search online for correct migration tools and script to do not exceed your appropriate time slot.