Knex-migrator migrate not migrating new migrations on production for custom build

First, Ghost is awesome! Thank you!

Ghost-CLI version: 1.15.3
Ghost version: 3.41.6

Okay so here’s my issue. I have added migrations and have successfully used knex-migrator to run them in my development environment with no problem. In my production environment, not so smooth. If I use ghost update --zip /path/to/zip to update to my custom build, I can see that the new column/new table has not been added to my database – so migrations were not automatically run on update – okay no problem. But so if I manually run the migrations a la DEBUG=knex-migrator:* ./current/node_modules/knex-migrator/bin/knex-migrator migrate --mgpath=./current, they don’t run either. I can see that the new column/new table has not been added and I can see that the new migrations are also not added to the migrations table.

After banging my head against the wall for a bit, I tried just doing a fresh ghost install on a fresh new Digital Ocean droplet a la ghost install --zip /path/to/zip and, voila, the fresh new database had my new column and table in it. But I of course don’t want to do a fresh new install when I add migrations.

What am I doing wrong? Does knex-migrator look at something besides the migrations table to check if it has already run a given migration? Does ghost install successfully running the migrations provide any clue on why ghost update is not successful? Do you have any advice or random things I can try? Thanks so much in advance.

Okay phew finally figured it out.

So before I was running the following to try to migrate the db.

$ ./current/node_modules/knex-migrator/bin/knex-migrator migrate --v 3.92 --force --mgpath=./current

This runs in development mode by default which is expected behavior. I just didn’t think of it. I found out by prepending DEBUG=* to the command and seeing that the database configuration was way off – it was pointing to a sqlite3 db.

What worked is the following where I prepended NODE_ENV=production to run it in production mode which makes it respect the db config in config.production.json. I had to add the sudo too to get rid of a permission error that was popping up otherwise.

$ NODE_ENV=production sudo ./current/node_modules/knex-migrator/bin/knex-migrator migrate --v 3.92 --force --mgpath=./current

Hope this saves someone some time in the future.