1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why aren't add-on tables removed with the add-on?

Discussion in 'General XenForo Discussion and Feedback' started by CyclingTribe, Oct 16, 2012.

  1. CyclingTribe

    CyclingTribe Well-Known Member

    I've just noticed a number of tables in my XF database that belong to add-ons I've long since removed.

    Why aren't the tables removed with the add-on?

    Shaun :D
  2. Russ

    Russ Well-Known Member

    I'm guessing it would have to be handled by the add-on itself?
  3. CyclingTribe

    CyclingTribe Well-Known Member

    So it's up to each add-on maker to include a table removal instruction as part of the uninstall routine?
  4. Chris D

    Chris D XenForo Developer Staff Member


    Quite shoddy if that isn't included, tbh.
    bogus, Jake Bunce and Shelley like this.
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Correct. Addons are responsible for adding and removing their own custom tables and fields in the install / uninstall routines. For example, here is the install / uninstall code for Nodes As Tabs:

    class NodesAsTabs_Install
    	public static function install()
    		$db = XenForo_Application::get('db');
    			CREATE TABLE IF NOT EXISTS `nat_options` (
    				`node_id` int(10) unsigned NOT NULL,
    				`nat_display_tab` tinyint(3) unsigned NOT NULL,
    				`nat_display_tabperms` tinyint(3) unsigned NOT NULL,
    				`nat_tabtitle` varchar(50) NOT NULL,
    				`nat_display_order` int(10) unsigned NOT NULL,
    				`nat_position` enum('home','middle','end') NOT NULL,
    				`nat_childlinks` tinyint(3) unsigned NOT NULL,
    				`nat_childlinksperms` tinyint(3) unsigned NOT NULL,
    				`nat_markread` tinyint(3) unsigned NOT NULL,
    				`nat_linkstemplate` varchar(50) NOT NULL,
    				`nat_popup` tinyint(3) unsigned NOT NULL,
    				`nat_tabid` varchar(50) NOT NULL,
    				`nat_childnodes` text NOT NULL,
    				`nat_firstchildnodes` mediumblob NOT NULL,
    				UNIQUE KEY `node_id` (`node_id`)
    			) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='NodesAsTabs addon'
    		self::addColumnIfNotExists('nat_markread', 'tinyint(3) unsigned NOT NULL', 'nat_childlinksperms');
    		self::addColumnIfNotExists('nat_popup', 'tinyint(3) unsigned NOT NULL', 'nat_linkstemplate');
    		self::addColumnIfNotExists('nat_tabtitle', 'varchar(50) NOT NULL', 'nat_display_tabperms');
    		self::addColumnIfNotExists('nat_tabid', 'varchar(50) NOT NULL', 'nat_popup');
    		$optionsModel = XenForo_Model::create('NodesAsTabs_Model_Options');
    	public static function addColumnIfNotExists($fieldName, $fieldDef, $after)
    		$db = XenForo_Application::get('db');
    		$exists = $db->fetchRow("
    			FROM nat_options
    			WHERE Field = ?
    		", $fieldName);
    		if (!$exists)
    				ALTER TABLE nat_options ADD {$fieldName} {$fieldDef} AFTER {$after}
    	public static function uninstall()
    		$db = XenForo_Application::get('db');
    			DROP TABLE IF EXISTS `nat_options`
    		XenForo_Application::setSimpleCacheData('natCache', false);
    On the other hand, XenForo's addon system has many integrated data types that are automatically removed by the system including templates, phrases, nav links, listeners, etc. The system is very tight. Addons only need to worry about managing their custom data types like new tables.
    Shelley and Chris D like this.
  6. CyclingTribe

    CyclingTribe Well-Known Member

    Okay, great, thanks for the info guys. (y)

Share This Page