What is this article for

This article shows you how to make DB structure or data manipulations for new CB releases and the same for customization projects.

Concept

For any code you commit that needs DB changes, you make an upgrade script (in a certain directory). CB checks for new upgrade scripts and processes them on app init. So when you commit or deploy code on the involved remote installations, your scripts will handle all DB changes.

Behaviour on upgrade failures 

Update Scripts for customizations

There is an upgrade script system analogue to the system's upgrade script.

Examples

Say you mean to add a table #__configbox_external_product_appends for a customization. You check the directory customizationDir/updates and find the next version number - say it’ll be 1.0.11.

Create the 1.0.11.php

<?php
defined('CB_VALID_ENTRY') or die();

if (ConfigboxUpdateHelper::tableExists('#__configbox_external_product_appends') == false) {
  $db = KenedoPlatform::getDb();
  $query = "...sql query to create the table...use #__ as table prefix..";
  $db->setQuery($query);
  $db->query();
}

Useful methods for checking the current DB structure

$tableName always needs the #__ table prefix:

ConfigboxUpdateHelper::tableExists($tableName) : boolean

ConfigboxUpdateHelper::tableFieldExists($tableName, $columnName) : boolean

ConfigboxUpdateHelper::getKeyNames($tableName, $columnName) : string[] - Returns an array of SQL key names for the given column

ConfigboxUpdateHelper::getColumnNames($tableName) : string[] - Returns an array of column names for the given table

ConfigboxUpdateHelper::getFkConstraintName($tableName, $columnName) : string[] - Returns an array of foreign key constraints related to the given column

Best Practices