So one issue we have had with our otherwise excellent component upgrade module is that the versioning is handled only within each component. This can be a problem sometimes. For instance, say Component A defines a view that pulls in fields from a table defined in Component B. Then Component B is updated to remove one or more of those fields. This can lead to a failure to create the schema if you are running the components with an empty database (such as when you are setting up a new application instance for development). Our work around has been to pull a full snapshot of the upgraded database, clean out the component table and go from there. However, in order to be properly useful we needed a way to make sure that we can consistently build a correct schema from an empty database when provisioning a new application.
To do this I have introduce a mechanism for defining dependencies between components. The syntax within a sql schema file is
-- Depends On <component> <version>
If you have a dependency within a custom upgrade function you can call:
UpgradeManager::upgradeComponentToVersion($component, $version);
For a real-life example, there is an interdependency between the project component and the biz_dev component in the Griot code base (Griot is a product built by Sonjara using Fakoli). The project component pulls data from the biz_dev tables in several views. When I tried to provision a new Griot instance, I was met with the error:
Failed to upgrade project to version 1.6 - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bd.notes' in 'field list'
In the project_schema.sql file I found the version 1.6 schema update section and modified it to read:
-- START Version 1.6
-- Depends On biz_dev 1.3
Where version 1.3 is the compatible point in the upgrade path of the biz_dev component. Once this was in place the database schema auto-instantiated without a hitch.
Have a good weekend!