I've been exploring the code base for Magento 2 and I've been trying to figure how you can control the order in which upgrade setup classes would run between setup versions. Yet, i'm stuck. As far as my digging has taken me I haven't been able to find a way to control the order of schema/data upgrades within my module.
To give a little context, let's say I release a module. Overtime we release updates. Let's say I have the following file structure:
Setup/InstallPostSchema.php
Setup/CreateAuthorsTableSchema.php
Setup/AddAuthorIdColumnToPostSchema.php
In this case I'd want Setup/CreateAuthorsTableSchema.php
to run before Setup/AddAuthorIdColumnToPostSchema.php
.
My question is, how do/should we deal with that?
In Magento 1.x the file naming convention handled this for us: upgrade-1.0.0-1.1.0.php
for example.
Frameworks like Laravel, or Rails (and others i'm sure) use a timestamp approach. However, they also have a migrations table which would tell you each migration that has run so far. Also allowing for easy rollback.
Update
I have found an example of managing versioning yourself within the Magento/Customer
module:
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
if (version_compare($context->getVersion(), '2.0.0.1') < 0) {
// Changes here.
}
if (version_compare($context->getVersion(), '2.0.1', '<')) {
// Changes here
}
$setup->endSetup();
}