Run migrations against preview database

I really like the preview environments, and makes my life a lot easier. However I have not yet figured out how to run migrations against the preview database.

We often need migrations to preview a new feature, say adding a comment feature, and would like to first run the migrations against the preview db to see the changes before running them against the prod db.

However I don’t have a connection string to run the migrations in a github action, and the provided initialDeployHook field in the blueprint only works for the initial deploy, but if we find an error in our migration files, and have to run migrations again, this will not work.

What is the right way to do this?

Hi @SorenHolstHansen,

Is there a reason you wouldn’t just run your migrations as a part of your build command? You can see an example of this in our Rails Quickstart, the build script runs the database migration.

If you’re spinning up a database with each Preview Environment, you can configure your application to use the “preview” database’s connection string. See for more info on that. That will ensure your preview migrations are running against the correct database.

I hope that helps. Let me know if I’ve misunderstood your question.



Arrrh, had not thought about that at all, but yes, that works perfectly!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.