<p>Every time Craft notices that a plugin's version number has changed (I imagine quite near the start of every request,) it checks for any new <strong><a href="http://buildwithcraft.com/docs/plugins/migrations">Database Migrations</a></strong> in that plugin that might need running in order get the database schema caught up to the code. That link, and <a href="http://buildwithcraft.com/docs/plugins/database">this one for database queries</a> should be enough to get you started.</p>

CC BY-SA 3.0
2015-03-13T14:31:12.723Z
Cheers Mike migration info was just what I required. Just one other q on plugin dbs though. Does craft automatically delete the database if a plugin is un-installed or do you need to implement code to remove it's DB as per EE?
Lettie
CC BY-SA 3.0
2015-03-13T15:50:08.667Z
If you **disable** a plugin, the database table (and all existing data) will remain in place. However, if you **uninstall** a plugin, the table will be automatically deleted for you.
Lindsey D
CC BY-SA 3.0
2015-03-13T14:20:52.243Z
2015-03-13T14:20:52.243Z
Mike Pepper
<p>Quick scenario.</p>

<p>I build a plugin with a database. Few months down the line I want to upgrade this plugin which will alter the plugin DB. If installing an update to a plugin how does craft deal with not over writing the existing database data? I know in EE you set up separate install and update functions but I can't find anything in the documentation in craft regarding this and the plugins I've pulled apart don't seem to include anything to deal with updates?</p>

<p>Any advice or pointers to some good documentation on this would be appreciated.</p>

<p>Cheers</p>

<plugin-development><plugins>
How does craft deal with Plugin databases when updating plugin versions?
# How does craft deal with Plugin databases when updating plugin versions?

(Asked by: username_0 on 2015-03-13)

Quick scenario.

I build a plugin with a database. Few months down the line I want to upgrade this plugin which will alter the plugin DB. If installing an update to a plugin how does craft deal with not over writing the existing database data? I know in EE you set up separate install and update functions but I can't find anything in the documentation in craft regarding this and the plugins I've pulled apart don't seem to include anything to deal with updates?

Any advice or pointers to some good documentation on this would be appreciated.

Cheers

**Tags:** plugin-development, plugins


---

## 1 answers

### Answer by username_1 on 2015-03-13. Score: 6 | Accepted answer

Every time Craft notices that a plugin's version number has changed (I imagine quite near the start of every request,) it checks for any new **[Database Migrations](http://buildwithcraft.com/docs/plugins/migrations)** in that plugin that might need running in order get the database schema caught up to the code. That link, and [this one for database queries](http://buildwithcraft.com/docs/plugins/database) should be enough to get you started.

> **Comments:**
> **username_0**: Cheers Mike migration info was just what I required. Just one other q on plugin dbs though. Does craft automatically delete the database if a plugin is un-installed or do you need to implement code to remove it's DB as per EE?  
> **username_2**: If you **disable** a plugin, the database table (and all existing data) will remain in place. However, if you **uninstall** a plugin, the table will be automatically deleted for you.  

---

