General developer forum

Remove columns from plugin table on update

 
Picture of joseph malmsten
Remove columns from plugin table on update
Core developersPlugin developers

Hey,


An older version of our plugin had an extra column that stored a key that was already stored in the general plugin config. We changed the code to always use the up-to-date key in the plugin config so now this column is no longer used.


Is there any way in the upgrade.php where I can delete this column from the table, should I bother worrying about having an unused string column?



 
Average of ratings: -
Picture of Mark Johnson
Re: Remove columns from plugin table on update
Core developersParticularly helpful MoodlersPlugin developers

If you load your plugin in the XMLDB editor and open the table you want to remove the column from, you can use the "View PHP Code" link will give you the option to generate the code that removes the column.

Once you've put this in your upgrade.php, you should then delete the column in XMLDB Editor, and save the changes to your plugin's install.xml file.

 
Average of ratings: -
Picture of joseph malmsten
Re: Remove columns from plugin table on update
Core developersPlugin developers

Perfect, exactly what I am looking for. Thank you!

 
Average of ratings: -