Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

How to remove a table column in vanilla

Hi

I have a plugin that adds column in a table, how do I remove it when the plugin is disabled

Thanks

Comments

  • Look in here for some really nice things \applications\vanilla\settings\structure.php

    I am guessing it goes like this... emphasis on set($Explicit, $Drop);

    Gdn::database()->structure()->table('Discussion')->column('OldStuff')->set('', true);
    

    I did not test it because I did not want to blow up anything :)

    I would probably never use this self cleanup method in a private or public plugin just because...

    I go to the DB directly and do it manually.

    rloyola
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Normally you do not do that. A recommended way of updating a Vanilla installation is to disable all plugins. If plugins would delete data connected to them when disabled, the data could get lost. It's not the expected behaviour that columns are deleted automatically.


    donshakespearerloyola
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Okay, I think it has been long enough to be counted as a dramatic pause and it may be clear now why I think it shouldn't be done automatically. But if you need to delete a column, there is a way:

    if (Gdn::structure()->table->('User')->columnExists('Furuncle')) {
        Gdn::structure()->table('User')->dropColumn('Furuncle');
    }
    

    You might want to include an option in the plugin settings to clear all traces of this plugin and deactivate it at the end of the process and thus create a custom way to disable your plugin which informs/warns you about the consequences. In such a context you might need the code above.


    rloyolaBleistivt
  • My experimental plugin need this in the development environment, Thanks!

Sign In or Register to comment.