# How to properly alter the database?

**URL:** <https://meta.discourse.org/t/how-to-properly-alter-the-database/60659>\
**Category:** Development\
**Created:** [8. April 2017 um 19:31 UTC](https://meta.discourse.org/t/how-to-properly-alter-the-database/60659 "2017-04-08T19:31:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)\
**Post date:** [8. April 2017 um 20:13 UTC](https://meta.discourse.org/t/how-to-properly-alter-the-database/60659/2 "2017-04-08T20:13:22Z")

</div>

Step 1: don’t. Most of the common objects in Discourse have the ability to store “custom fields”, and typically you’ll do a whole lot better if you use those.

Step 2: no, really, don’t. If per-object custom fields won’t do it for you, there’s also [PluginStore](http://www.rubydoc.info/github/discourse/discourse/PluginStore) that maintains per-plugin data seamlessly.

Step 3: if you absolutely, positively need your own database tables, you can change the schema by creating your own ActiveRecord migrations in `db/migrate` in your plugin. They get included [by core](https://github.com/discourse/discourse/blob/master/lib/plugin/instance.rb#L354) if they exist.

The caveats to modifying the schema are many, and include, but are not limited to:

- Cleaning up your schema changes if your plugin is uninstalled is an unsolved problem.
- If your schema change conflicts with that of another plugin, or core, you’ve just broken the install of everyone who uses your plugin.
- The combination of the above two points means that you could, at some unknown point in the future, break the install of everyone who _ever_ used your plugin, even if they uninstalled it a long time ago.
- Once you’ve broken things, it will require SQL command line experience from everyone who has ever used your plugin to fix.

Please, just use PluginStore. Think of the kittens.

---

_[View the full topic](https://meta.discourse.org/t/how-to-properly-alter-the-database/60659)._
