Development Wiki

Difference between revisions of "Migrations/Dependencies"

From phpBB Development Wiki

(Declaring Dependencies)
Line 30: Line 30:
| migration_1
| migration_1
| phpbb_db_migration_data_3_1_0
| phpbb\db\migration\data\v310\dev
| Initial release, 1.0.0, requires phpBB 3.1.0
| Initial release, 1.0.0, requires phpBB 3.1.0

Revision as of 21:46, 26 August 2014

Dependencies tell the Migrator what order Migrations must be installed in.

Declaring Dependencies

In your Migration file, add a static public function named depends_on(), returning an array.

static public function depends_on()
    return array();

All you must do is add the class name of the Migration that the current Migration depends on.

For example, phpbb\db\migration\data\v310\dev that 3.0.11, extensions, style update, reported posts display, and timezone are installed.

static public function depends_on()
        return array(

depends_on creates a tree

Imagine the following situation:

Migration Dependencies Note
migration_1 phpbb\db\migration\data\v310\dev Initial release, 1.0.0, requires phpBB 3.1.0
migration_2 migration_1 New feature for 1.0.1 (during development)
migration_3 migration_1 Another new feature for 1.0.1 (during development)
migration_4 migration_2 Modifying the feature in migration_2
migration_5 migration_3, migration_4 Release 1.0.1

This dependency setup would cause the following Migrations to be installed when an individual Migration was installed.
Assumes phpbb_db_migration_data_3_1_0 is already installed.

Install Migrations that are installed
migration_1 migration_1
migration_2 migration_1, migration_2
migration_3 migration_1, migration_3
migration_4 migration_1, migration_2, migration_4
migration_5 migration_1, migration_3, migration_2, migration_4, migration_5

What does this mean for me?

You must specify all dependencies that the current Migration has, but not any that the dependencies list as dependencies for their own installation.

This means that migration_5 doesn't need to list migration_1 through migration_4 as a dependency, only migration_3 and migration_4 because those Migrations require migration_1 and migration_2.

This also means that the desired order of operations is preserved. In the above example, migration_4 modifies the feature in migration_2 and must be applied after migration_2 is installed. Similarly, in the above example, migration_5 is the release of 1.0.1, which requires both of the two new features to be installed before it is 1.0.1.