Once your application or service is running in production you have a lot more to consider when making database changes. It can be tricky, here are a few things to keep in mind that should reduce or eliminate downtime.
If you need to rename a column, to reduce downtime you cannot do the rename all in one release. Let’s say that we want to rename
first_name in our users table. Assuming there is already data in that column in our database we need to take a 3 step approach to complete the renaming process.
- Create a new
first_namecolumn (keeping the old
- Ensure application is writing to both columns. Perform a backfill, copying values from the old
firstNamecolumn to the new
- Cleanup. Once all data has been copied (may require several runs of the backfill), update application to only write to new
first_namecolumn. Delete old
If you’re adding columns, start with updating the database with the new column. If you intend for the new column to not allow for
NULL values you will need to ensure a default value is supplied when creating the column. After the database has been updated then we can deploy new application or service code to use the new column.
If you need to remove a column we need to configure application or service code to no longer use the old column. Once we deploy our code changes then we can remove the old column.