Plugin Database Migrations

Is there an automatic way of running the database migration for a custom plugin if it has not already been run? Instead of manually running a DB migration in a fresh Discourse installation?

How are you running Discourse?

This should be covered if you’re using our docker installation.

Running the Discourse development environment

You don’t run migrations from within a plugin.

In a Dev environment you perform them from the console.

Why? Because when you deploy a plugin the migrations are taken care of by the host app.

It’s out of scope of what a plugin should do.

(FYI that’s not to say you don’t include migrations within the plugin if you are e.g. modifying the database but the plugin is not going to perform the migrations)

That’s correct, I am using the console to run the migrations in the development environment. My question is that is this the way forward and do I also have to run these manually in the console for a production docker environment?

That would be done automatically as part of a (re)build.

3 Likes