I have a Node.js app running on Google App Engine.

I want to run sequelize migrations.

Is it possible to run a command from within the Instance of my node.js app?

Essentially something like heroko's run command which will run a one-off process inside a Heroku dyno.

If this isn't possible what's the best practice in running migrations?

I could always just add it to the gcp-build but this will run on every deploy.

1 Answers

0
Dan Cornilescu On

It's not possible to run standalone scripts/apps in GAE, see How do I run custom python script in Google App engine (in python context, but the general idea applies to all runtimes).

The way I ran my (datastore) migrations was to port the functionality of the migration script itself into the body of an admin-protected handler in my GAE app which I triggered with a HTTP request for a particular URL. I re-worked it a bit to split the potentially long-running migration operation into a sequence of smaller operations (using push task queues), much more GAE-friendly. This allowed me to live-test the migration one datastore entity set at a time and only go for multiple sets when completely confident with its operation. Also didn't have to worry about eventual consistency (I was using queries to determine the entities to be migrated) - I just repeatedly invoked the migration until there was nothing left to do.

Once the migration was completed I removed the respective code (but kept the handler itself for future migrations). As a positive side effect I pretty much had the migration history captured in my repository's history itself.

Potentially of interest: Handling Schema Migrations in App Engine