How to Uninstall the Database of Your Plugin During Deletion of the Plugin

In case admin user of your plugin is deleting your plugin and you want your plugin to uninstall its database, this is what you must do:

  • Create a directory named install. The name of this directory must be exactly install and must not change.

  • Put the install directory inside your plugin's directory. For example, if your plugin's directory is my_plugin, then you must put the install directory inside the my_plugin directory like this: my_plugin/install.

  • You must have an SQL file with a .sql extension which contains the various statements to drop tables and/or delete rows or perform other operations on the database. This SQL should be named uninstall.sql.

  • Put the uninstall.sql file inside the install directory like so: my_plugin/install/uninstall.sql.

  • That will be it. During the deletion of your plugin, the uninstall.sql will be run to execute the statements in it on the database.