phpBB

Development Wiki

Difference between revisions of "Migrations/Dependencies"

From phpBB Development Wiki

(depends_on creates a tree)
(Declaring Dependencies)
Line 10: Line 10:
 
All you must do is add the class name of the Migration that the current Migration depends on.<br />
 
All you must do is add the class name of the Migration that the current Migration depends on.<br />
 
<br />
 
<br />
For example, phpbb_db_migration_data_3_1_0_dev requires that 3.0.11, extensions, style update, and timezone are installed.
+
For example, phpbb\db\migration\data\v310\dev that 3.0.11, extensions, style update, reported posts display, and timezone are installed.
<php>static public function depends_on()
+
<php> static public function depends_on()
{
+
{
return array(
+
return array(
'phpbb_db_migration_data_3_0_11',
+
'\phpbb\db\migration\data\v310\extensions',
'phpbb_db_migration_data_extensions',
+
'\phpbb\db\migration\data\v310\style_update_p2',
'phpbb_db_migration_data_style_update_p2',
+
'\phpbb\db\migration\data\v310\timezone_p2',
'phpbb_db_migration_data_timezone_p2',
+
'\phpbb\db\migration\data\v310\reported_posts_display',
);
+
'\phpbb\db\migration\data\v310\migrations_table',
}</php>
+
);
 +
}}</php>
  
 
==depends_on creates a tree==
 
==depends_on creates a tree==

Revision as of 21:44, 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(
            
'\phpbb\db\migration\data\v310\extensions',
            
'\phpbb\db\migration\data\v310\style_update_p2',
            
'\phpbb\db\migration\data\v310\timezone_p2',
            
'\phpbb\db\migration\data\v310\reported_posts_display',
            
'\phpbb\db\migration\data\v310\migrations_table',
        );
    }}

depends_on creates a tree

Imagine the following situation:

Migration Dependencies Note
migration_1 phpbb_db_migration_data_3_1_0 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.