Open jonasraoni opened 3 months ago
@asmecher Please, take a look at the PRs:
Looks good, @jonasraoni. Can you port to OMP and OPS as well, and forward to main
?
@jonasraoni, I'm getting an error on an attempted upgrade from 3.2.1-x to 3.4.0 that didn't happen prior to these changes:
ERROR: Upgrade failed: DB: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '32-156-530-125' for key 'section_editors_unique' (SQL: insert into
subeditor_submission_group
(assoc_id
,assoc_type
,context_id
,user_group_id
,user_id
) values (6, 530, 5, 71, 16), (52, 530, 5, 71, 16), (53, 530, 5, 71, 16), (54, 530, 5, 71, 16), (55, 530, 5, 71, 16), (56, 530, 5, 71, 16), (57, 530, 5, 71, 16), (58, 530, 5, 71, 16), (59, 530, 5, 71, 16), (9, 530, 7, 111, 97), (130, 530, 7, 111, 97), (133, 530, 7, 111, 97), (134, 530, 7, 111, 97), (135, 530, 7, 111, 97), (137, 530, 7, 111, 97), (138, 530, 7, 111, 97), (140, 530, 7, 111, 97), (98, 530, 19, 310, 118), (99, 530, 19, 310, 118), (100, 530, 19, 310, 118), (101, 530, 19, 310, 118), (102, 530, 19, 310, 118), (103, 530, 19, 310, 118), (104, 530, 19, 310, 118), (105, 530, 19, 310, 118), (106, 530, 19, 310, 118), (107, 530, 19, 310, 118), (108, 530, 19, 310, 118), (109, 530, 19, 310, 118), (110, 530, 19, 310, 118), (111, 530, 19, 310, 118), (112, 530, 19, 310, 118), (148, 530, 27, 446, 110), (155, 530, 31, 514, 10), (156, 530, 32, 532, 125), (156, 530, 32, 538, 125), (168, 530, 39, 651, 168), (169, 530, 40, 668, 166))
I can provide a copy of the DB if you like.
@asmecher Thanks! I was planning to run an upgrade against a large installation to test this one better, together with another PR. Extra backups are always welcome.
I finally checked this issue and looks it's related to https://github.com/pkp/pkp-lib/issues/8737, I'll remove the migration that Touhidur created and move it to the I7191_EditorAssignments
, which is the place where the new field was introduced and should probably address the error above.
@asmecher If you still have the database in hands, you might try to re-test with the PRs below in place.
I've passed those on to SciELO for a test, thanks!
Great, once we get a confirmation, I'll merge and cherry pick. The large installation that I tested didn't have this issue.
Dear @jonasraoni ,
If found an issue with one migration belonging to this issue while doing upgrade test with one of our 3.2.1 OJS installations.
It seems the current stable_3_4_0
version of the migration: https://github.com/pkp/pkp-lib/blob/stable_3_4_0/classes/migration/upgrade/v3_4_0/I7191_EditorAssignments.php leads to the following SQL error during upgrade:
2024-07-02 18:28:19 [migration: APP\migration\upgrade\v3_4_0\InstallEmailTemplates]
2024-07-02 18:28:27 [migration: PKP\migration\upgrade\v3_4_0\I7874_NotificationMetadataModifiedRemove]
2024-07-02 18:28:27 [migration: APP\migration\upgrade\v3_4_0\I7191_EditorAssignments]
2024-07-02 18:28:28 [revert migration: PKP\migration\upgrade\v3_4_0\I7874_NotificationMetadataModifiedRemove]
2024-07-02 18:28:28 [revert migration: APP\migration\upgrade\v3_4_0\InstallEmailTemplates]
2024-07-02 18:28:28 [revert migration: APP\migration\upgrade\v3_4_0\I5716_EmailTemplateAssignments]
2024-07-02 18:28:28 [revert migration: PKP\migration\upgrade\v3_4_0\I7287_RemoveEmailTemplatesDefault]
2024-07-02 18:29:00 [revert migration: APP\migration\upgrade\v3_4_0\I7796_UpdateCrossrefSchema]
2024-07-02 18:29:00 [downgrade for "APP\migration\upgrade\v3_4_0\I7796_UpdateCrossrefSchema" unsupported: Downgrade not supported]
ERROR: Upgrade failed: DB: SQLSTATE[HY093]: Invalid parameter number (SQL: update `subeditor_submission_group` as `ssg` set `user_group_id` = (select `ug`.`user_group_id` from `user_groups` as `ug` where `ug`.`context_id` = `ssg`.`context_id` and `ug`.`role_id` = ? order by `ug`.`is_default` desc, `ug`.`permit_metadata_edit` desc limit 1) where `user_group_id` is null)
This was updated recently with the following commit: https://github.com/pkp/pkp-lib/commit/5d644008ff1c67a8c7d4defccf02a3853ab6c9d2
I am now testing if reverting this change back to whereRaw
fixes the issue.
Running the migration with the line of code before the commit https://github.com/pkp/pkp-lib/commit/5d644008ff1c67a8c7d4defccf02a3853ab6c9d2 works (using whereRaw
instead of where
).
I think it probably has to do with the fact, that its later used embedded as a raw SQL query inside the update query executed in line 90 to 92:
DB::table('subeditor_submission_group', 'ssg')
->whereNull('user_group_id')
->update(['user_group_id' => DB::raw("({$bestUserGroupIdQuery->toSql()})")]);
Thanks @nils-stefan-weiher! When I was updating, I suspected there was something smelling on this place (I'm the person who added this whereRaw
😁), but looks like I forgot to investigate further.
And FYI, this issue has extra pending PRs due to another problem that I found:
Describe the bug The migration
I7191_EditorAssignments
is causing data loss at the editor assignments.Problems:
setUserGroup()
is supposed to set theuser_group_id
for all existing assignments, but it's just taking a singlecontext_id
, see: https://github.com/pkp/pkp-lib/blob/1dae820fa8b07868f1efa999c25cc3745f19f30a/classes/migration/upgrade/v3_4_0/I7191_EditorAssignments.php#L78-L79section editor
role, but a pre-flight check to ask the user to create the role sounds like a better choice.addAutomatedAssignments()
seems to be assigning unexpected users (a user that had adesigner
/ROLE_ID_REVIEWER
role was assigned as section editor)To Reproduce
What application are you using? OJS 3.4