Typically you would stage the deployment of each of these changes and the steps you use would be the same in dev as production. In the case you describe where you are adding a column these are the steps I would take first testing them in development then applying them in production
- Add the column to the table in the database allowing nulls
- Update the application code to start writing to the new column
- If every row is expected to have data in that column then start
running a background process/scripts/sql to backfill the missing
data
- Update the column in the table to not allow nulls
- Updated the application code to start reading from the new column
The above steps come with the following assumptions:
None of the application code is completing any SELECT *
queries. These can break if you add new unknown columns in step 1 and it's generally considered bad practice to have SELECT *
queries for this reason.
I'm assuming you have a tool that manages deployment of the code and versions. You should also consider having a database change management tool to track, version and deploy these types of database changes. I've used liquibase in the past for this.