Database Changes in ExpressionEngine

Determining Database Changes in ExpressionEngine Updates

April 11, 2015 by Ryan Masuga

A question was recently posted asking if an ExpressionEngine upgrade from 2.9.2 to 2.9.3 affects the database. It's easy to determine what changes are made to the database during an ExpressionEngine update by looking at the core update files in the system folder.

How do you know if there are database changes made when you're upgrading an ExpressionEngine site? The easiest way to know is to look in the /system/installer/updates directory. There you'll find an update file associated with every ExpressionEngine version.

For example, we know there were no database updates for ExpressionEngine 2.9.2, because the do_update() function in the ud_292.php file is empty.

class Updater {

    var $version_suffix = '';

    /**
     * Do Update
     *
     * @return TRUE
     */
    public function do_update()
    {
        return TRUE;
    }
}

Going back a bit to ExpressionEngine 2.9.0 (see the ud_290.php file) you'll notice that this upgrade has 5 changes involved.

public function do_update()
{
    ee()->load->dbforge();

    $steps = new ProgressIterator(
        array(
            '_update_template_routes_table',
            '_set_hidden_template_indicator',
            '_ensure_channel_combo_loader_action_integrity',
            '_convert_template_conditional_flag',
            '_warn_about_layout_contents'
        )
    );

    foreach ($steps as $k => $v)
    {
        $this->$v();
    }

    return TRUE;
}

Each of those lines in the array corresponds to a function further down in the file. Sometimes these functions do things other than change the database. Here, the _set_hidden_template_indicator function adds or updates a variable in the config file. The _update_template_routes_table clearly affects the database, though, because it's adding a column to the template_routes table.

If you want to see an example where ExpressionEngine had a lot of work to do during an update, look at all 2,167 lines of the ud_200.php file. This is when ExpressionEngine made the jump from the EE1 branch to EE2. 

To answer Nathan Reed's specific question, we need to look at the ud_293.php file included in the latest download of ExpressionEngine.

public function do_update()
{
    ee()->load->dbforge();

    $steps = new ProgressIterator(
        array(
            '_extract_cache_driver_config',
            '_recompile_template_routes',
            '_date_format_years'
        )
    );

    foreach ($steps as $k => $v)
    {
        $this->$v();
    }

    return TRUE;
}

There we can see that ExpressionEngine will loop through three functions. Browsing each of those functions will give us an idea of what tables are involved.

It's probably a good idea to review the files in this directory every time you need to run an ExpressionEngine update so you get an idea of what is supposed to happen behind the scenes during the update.

You Might Also Like

More from Masuga Design

Subscribe to receive our newsletter.