# Plugin Database Migrations

**URL:** https://meta.discourse.org/t/plugin-database-migrations/259521
**Category:** Development
**Created:** [March 27, 2023, 8:50am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521 "2023-03-27T08:50:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bstgmr02](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bstgmr02](https://meta.discourse.org/u/bstgmr02)
#### Post date: [March 27, 2023, 8:50am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/1 "2023-03-27T08:50:37Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 27, 2023, 9:03am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/2 "2023-03-27T09:03:37Z")

</div>

How are you running Discourse?

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

---

<div class="post-metadata">

### Author: ![bstgmr02](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bstgmr02](https://meta.discourse.org/u/bstgmr02)
#### Post date: [March 27, 2023, 9:15am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/3 "2023-03-27T09:15:43Z")

</div>

Running the Discourse development environment

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [March 27, 2023, 9:30am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/4 "2023-03-27T09:30:35Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![bstgmr02](https://avatars.discourse-cdn.com/v4/letter/b/858c86/32.png) [@bstgmr02](https://meta.discourse.org/u/bstgmr02)
#### Post date: [March 27, 2023, 9:34am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/5 "2023-03-27T09:34:42Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [March 27, 2023, 9:35am UTC](https://meta.discourse.org/t/plugin-database-migrations/259521/6 "2023-03-27T09:35:51Z")

</div>

> [@bstgmr02](#):
>
> 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.
