Database Migration / Deployment Questions

In the meantime here is what I did to make the missing pieces work. I created this knexfile.js into the root of my project:

  const strapi = require("strapi")({ serveAdminPanel: false });

  module.exports = {
   client: "pg",
   connection: strapi.config.database.connections[strapi.config.database.defaultConnection].settings,
   pool: {
     min: 2,
     max: 10,
   },
   migrations: {
     tableName: "knex_migrations",
   },
 };

This allows me to run the knex migration CLI commands so I can leave strapi with creating the columns as it usually does but also be able to generate migrations to delete columns or update them if needed.

So the above means that I can run: yarn knex migrate:make test to generate a new migration.

And I can later to this yarn knex migrate:latest to run set migration.

Read more here: http://knexjs.org/#Installation-migrations
Tutorial: Database Migrations with Knex

This should temporarily solve the problem for most people but I believe we still should try and address the plugin solution so we can have an option to stop strapi from generating new columns on it’s own or if it does that to generate a migration file instead of just adding the column and there is no actual history of it’s actions.

For me at least that would be enough. I don’t think we should try and solve the problem of renaming a column that is too complex and it requires knowing the past column name. If a rename happens we can have strapi generate a new column and then we can make a new migration as I did above that would copy the data from the old column and later drop that.

1 Like