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.


1 Answer 1


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 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 should be enough to get you started.

  • 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
    Commented Mar 13, 2015 at 14:31
  • 1
    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
    Commented Mar 13, 2015 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.