Closed jonasraoni closed 1 month ago
If you're looking into this, make sure you're looking at the master
branch -- the schema management has all moved to migrations rather than ADODB's schema management toolset.
I'd suggest adding the constraints, then only considering ON DELETE CASCADE
as a secondary step.
There will be quirks around the assoc_type
/assoc_id
pairs -- it's not possible to specify these as conventional foreign keys.
Draft PRs:
You can use SchemaSpy to generate documentation on the DB schema. See schemaspy.properties
in the OJS root for details.
Borrowed/rewrote some commits to pull pieces of this into master
in advance of solving all the various problems that still need attention:
A weird note about indexes:
MySQL/MariaDB requires that foreign key columns have indexes. If you don't specify one in the table creation, it'll create one for you. If you subsequently do create one, the implicit one will disappear and the one you created will remain. So there's no harm in specifying index creation alongside foreign key constraints when using MySQL/MariaDB.
I never saw this requirement in other databases, anyway that's a good procedure =]
@Vitaliy-1, and @jonasraoni, would you mind reviewing these two pull requests?
These involve a number of changes -- I kept the commit list clean in case it helps to read them separately.
In terms of introducing foreign key constraints, they only tackle the announcements tables. But they set patterns that I'd like to roll out in future PRs. Of note:
classes/migrations/install
(to match classes/migration/upgrade
).announcement_types
assoc_type
/ assoc_id
columns are removed in favour of just a context_id
column (the only use case we had for it). I'd like to get rid of assoc_type
/ assoc_id
where possible as they are confusing.Migration
class with a few common details. (For whatever reason, the Laravel Migration base class doesn't define what up()
/down()
function signatures should look like.)down()
functions can run successfully to back out the partial upgrade, the system's version is likewise set to the "fallback" version number. The user should once again be able to fix the problem and re-run the upgrade, though in this case the warning message does recommend a full restore from backup.If this all looks OK, I'll port to the other apps and continue with more foreign key constraints etc. along the same lines, in separate PRs.
Migration looks ok to me and, except for unrelated issues, it went fine on my test instance. Left a comment regarding down()
method.
Thanks, @Vitaliy-1, I've resolved the comments you had! @jonasraoni, could you have a quick look? Then I'll merge these PRs and move on with other foreign key declarations following this pattern.
I just left small comments. I didn't run the upgrade, but it would be useful to check it against real data to catch unexpected issues.
assoc_*
removal: that's great, the nomenclature was really confusing for me.Thanks, @jonasraoni!
Abort rather than attempt to correct data: If I were an user with no IT support, I'd like to have it automatically corrected, then a message like "orphan submissions were detected, setup a default section at xxxx to receive them", presented on failure or in the beginning of the process, would be great.
So far this is just theoretical, as the scripting I've done does clean (minor) things up automatically. But if it's anything that'll potentially change the scholarly record, I do think we should abort and let them fix it rather than make assumptions.
Additional PRs for OMP and OPS:
PRs for the Category classes:
I converted them to the EntityDAO toolset as that has better handling of null-but-that-doesn't-mean-unset constraints. This also fixes the storage of category IDs in publication data, which was broken.
PRs for controlled vocab tables and common migration:
FKs for user group relationships:
FKs for user group relationships:
FKs for submission file relationships:
All implemented -- the remaining special cases have been filed here: https://github.com/pkp/pkp-lib/issues/8333
@jonasraoni, a tweak is required on this one: you're using ALTER TABLE t RENAME INDEX old_name TO new_name
, which is only available in MariaDB as of version 10.5.2. My Ubuntu ships with 10.3.39 and I think there will probably be lots of ISPs using older versions too. Could you check if there's a workaround that'll support older MariaDBs?
^ Sorry, wrong issue. Moving to #8333.
(Note: Remaining special cases have been filed here: https://github.com/pkp/pkp-lib/issues/8333)
Describe the problem you would like to solve The tables are missing foreign key constraints, and that's a source of orphan data/unexpected statistics.
Describe the solution you'd like Add constraints everywhere, considering carefully if deletes in cascade are the best option (easier to deal with and also to have accidents).
Migrations to review/add constraints to:
pkp-lib
:lib/pkp/classes/migration/install/AnnouncementsMigration.inc.php
lib/pkp/classes/migration/install/CategoriesMigration.inc.php
lib/pkp/classes/migration/install/CommonMigration.inc.php
except:plugin_settings.context_id
(uses0
for site-wide)notifications.context_id
(uses0
for site-wide)notifications.user_id
(uses0
for "anyone" IIRC)lib/pkp/classes/migration/install/ControlledVocabMigration.inc.php
lib/pkp/classes/migration/install/DoiMigration.inc.php
lib/pkp/classes/migration/install/FailedJobsMigration.inc.php
lib/pkp/classes/migration/install/FilesMigration.inc.php
lib/pkp/classes/migration/install/GenresMigration.inc.php
lib/pkp/classes/migration/install/JobsMigration.inc.php
lib/pkp/classes/migration/install/LibraryFilesMigration.inc.php
lib/pkp/classes/migration/install/LogMigration.inc.php
except:email_log.sender_id
(uses0
for "nobody in particular")lib/pkp/classes/migration/install/MetadataMigration.inc.php
except:filters.context_id
(uses0
for site-wide)filters.parent_filter_id
(uses0
for none)lib/pkp/classes/migration/install/MetricsMigration.inc.php
[moved to apps, FKs added already)lib/pkp/classes/migration/install/NavigationMenusMigration.inc.php
, except:navigation_menus.context_id
(0
used for site-wide)navigation_menu_items.context_id
(0
used for site-wide)navigation_menu_items_assignments.parent_id
(0
apparently used for none, even though the field appears nullable)lib/pkp/classes/migration/install/NotesMigration.inc.php
lib/pkp/classes/migration/install/ReviewFormsMigration.inc.php
lib/pkp/classes/migration/install/ReviewsMigration.inc.php
lib/pkp/classes/migration/install/RolesAndUserGroupsMigration.inc.php
lib/pkp/classes/migration/install/ScheduledTasksMigration.inc.php
lib/pkp/classes/migration/install/SubmissionFilesMigration.inc.php
lib/pkp/classes/migration/install/SubmissionsMigration.inc.php
lib/pkp/classes/migration/install/TemporaryFilesMigration.inc.php
lib/pkp/classes/migration/install/TombstoneMigration.inc.php
lib/pkp/classes/migration/install/ViewsMigration.inc.php
ojs
:omp
:ops
: