Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Add-ons that need adding DB columns or tables

edited September 2006 in Vanilla 1.0 Help
How does one handle database table changes in an extension? Suppose I need to add a column to the comments table for my extension to work. How would I do this? does it have to be done manually before installing the extension? if NOT, does it have to be removed afterwards? I appreciate any explanation, to further my understanding of Vanilla ^^


  • Options
    edited September 2006
    That look like something like that:
    //test if the extension is already installed if (!array_key_exists('YOUR_EXTENSION_VERSION', $Context->Configuration)) { //Part of the error message if the creation failed $senderObj = 'Your extension Installer'; $senderMethod = 'OpenConnection'; //don't know exactly what it is for //request //you can test the alter request in phpmyadmin first $AlterTable = "ALTER TABLE `". $DatabaseTables['TableName'] ."` ADD `ColumnName` INT( 11 )"; //The methode to execute the request $Context->Database->Execute($AlterTable , $senderObj, $senderMethod, 'Could not create ColumnName'); // If the column is created, add the extension version to settings.php // Next time the extension won't try to create the column if ($Context->ErrorManager->Iif()) { AddConfigurationSetting($Context, 'YOUR_EXTENSION_VERSION', '1.0'); } else { $Context->WarningCollector->Add($Context->GetDefinition('YourExtensionErrInstallation')); } } //Map to this new Column, usefull if you want to use the sqlbuider class in your extension. $Context->DatabaseColumns['TableName']['ColumnName'] = 'ColumnName';
  • Options
    hey cool... I'd have to remove the column manually if I wanted to get rid of it afterwards, right? no way for an extension to "uninstall" itself? ehmm I just recalled the Meta-extension... is it related to this kinda stuff?
  • Options
    You can leave the column after, but set a default value if you create acolumn with the "NOT NUL" option.

    I don't know for the Meta-extension.
  • Options
    Thanks, a whole bunch of em ^^
This discussion has been closed.