feat: Implement proper schema migration structure (Issue #94)#138
Conversation
- Split migration into install/ and upgrade/ following PLN plugin pattern - Add getInstallMigration() to hook into OJS Installer::postInstall - Consolidate all 4 tables into single install migration entry point - Add I94_AddMissingColumns for defensive column-level upgrades - Remove drop-based down() — replaced with explicit resetSchema() - Remove old classes/migration/CodecheckSchemaMigration.php - Bump version.xml to 1.0.0.0
nuest
left a comment
There was a problem hiding this comment.
Thanks for the first iteration. Can you please update the documentation as well?
What I find especially important: Where is the order of the upgrade scripts configured?
If I understand correctly, that would be in the up() function.
Also make clear in the documentation that "adding a column" is only one thing that could happen, an upgrade script may also process all records (e.g., rename an allowed value), insert content, e.g., for settings, or remove fields/columns/tables that are not used anymore.
Correct?
- Add CodecheckMigration abstract base class with start/end logging - Subclasses implement runUp() instead of up() - down() and DowngradeNotSupportedException consolidated into base class - Document upgrade script ordering and scope in install migration - Revert version.xml to 0.0.0.0
Added a docblock to the install migration explaining that the order of calls at the bottom of |
Closes #94
Implements a proper versioned schema migration structure for the CODECHECK plugin, replacing the previous ad-hoc approach where table creation was split across three disconnected methods called manually from
setEnabled().Approach
This implementation follows the pattern used by the PKP PLN plugin (pkp/pln), which is the only official PKP plugin with a full install + upgrade migration structure. The pattern is compatible with OJS 3.5, confirmed via
pkp-lib/stable-3_5_0/classes/plugins/Plugin.php.Changes
New structure
How it works
Fresh install:
setEnabled()callsgetInstallMigration()->up()which creates all 4 tables (codecheck_metadata,codecheck_orcid_tokens,codecheck_issue_labels,codecheck_status) and then runs all upgrade migrations. Since columns already exist in the freshly created table, the upgrade migrations do nothing extra.Existing install (upgrade):
Schema::hasTable()is true so table creation is skipped, existing data is untouched. Upgrade migrations then run and useSchema::hasColumn()guards to add only the columns that are missing from older installs.OJS Plugin Gallery install:
getInstallMigration()hooks into OJS's ownInstaller::postInstallevent automatically via the parentPluginclass, no manual intervention needed.Adding future columns: Create a new
classes/migration/upgrade/I{issue}_Description.phpwith ahasColumnguard, then add one line calling it at the bottom of the install migration.Both fresh installs and existing installs converge to the same schema state.
Key fixes compared to before
setEnabled()getInstallMigration()I94_AddMissingColumnsadds missing columns safelyInstaller::postInstallautomaticallydown()DowngradeNotSupportedExceptiondown()from migrationresetSchema(), separate from migration systemOther changes
classes/migration/CodecheckSchemaMigration.php(old file)CodecheckSchemaMigrationimport fromManage.phpprivate $migrationproperty fromCodecheckPluginversion.xmlfrom0.0.0.0to1.0.0.0References
Plugin::getInstallMigration(): https://github.com/pkp/pkp-lib/blob/stable-3_5_0/classes/plugins/Plugin.php#L236