Strapi model schema management

I have the exact same issues.

The only predictable and safe approach I’ve found so far is to basically follow this one rule: Never rename a column over the span of a single deployment.

If you need to rename a column, do it in two phases:

  1. First create a new column, update the code to use the new column with a fallback to the old column (necessary for any architecture with multiple servers, whether for pods in kubernetes or just servers behind a load balancer), and then deploy. Write a script (to run after deployment) or migration (to run during deployment) to copy the data from the old column to the new one.
  2. After the deployment has completed, the script/migration has been run, and all the pods/servers are guaranteed to access the new column, delete the old column and deploy.

It’s cumbersome and time-consuming, requires extra planning, and discourages schema updates, but it works.

2 Likes