You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[v3.1.2] Cover letters created before migrating to v3 show up separatly in patch list #556
Ah, right, they will be different since you have new cover letters. You probably need to add a limit to this. We don't track our own created_at/updated_at fields so we need to use date as a stand-in. This should do the trick (or at least the PostgreSQL equivalent will):
Both queries now return the same number of rows:
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULLORDER BYpatch.id;
id
--------4069140702
[..]
129709129712
(8138 rows)
SELECTcover.idFROM patchwork_cover cover
WHEREcover.date<= (
SELECTMAX(patch.date) FROM patchwork_patch patch WHEREpatch.state_id IS NULL
) ORDER BYcover.id;
id
--------4069140702
[..]
129709129712
(8138 rows)
Whoops, I forgot about the events. How about if you add the following after the first step?
# migrate any erroneous patch-comment-created events to cover-comment-created eventsUPDATE patchwork_event
SET cover_id = patch_id, category ='cover-comment-created', patch_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
Deleting duplicate patch comments still fails:
INSERT INTO patchwork_covercomment (msgid, date, headers, content, cover_id, submitter_id)
SELECT msgid, date, headers, content, patch_id, submitter_id
FROM patchwork_patchcomment
WHEREpatchwork_patchcomment.patch_idIN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
INSERT 0 26
UPDATE patchwork_event
SET cover_id = patch_id, category ='cover-comment-created', patch_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
UPDATE 26
DELETEFROM patchwork_patchcomment AS patch_comment
WHEREpatch_comment.patch_idIN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
ERROR: update or delete on table "patchwork_patchcomment" violates foreign key constraint "patchwork_event_patch_comment_id_4123011e_fk_patchwork" on table "patchwork_event"
DETAIL: Key (id)=(162805) is still referenced from table "patchwork_event".
ERROR: update or delete on table "patchwork_patchcomment" violates foreign key constraint "patchwork_event_patch_comment_id_4123011e_fk_patchwork" on table "patchwork_event"
DETAIL: Key (id)=(162805) is still referenced from table "patchwork_event".
That field should have been unset in the previous statement. Perhaps it needs to be split into two statements. Can you check if it was unset?
SELECT cover_id, patch_id FROM patchwork_event WHERE id=162805;
By the way, I noticed that new cover IDs started counting from 1 after the migration: patches.dpdk.org/api/covers/1 The last cover ID was 40691 before the migration: patches.dpdk.org/api/covers/40691 I guess it's an expected side effect of removing the old CoverLetter model?
Yes, that's expected behavior. I'm going to guess PostgreSQL was restarted at some point? I know MySQL restarts the autoincrement counter at the lowest available value when it's restarted. It shouldn't matter since the ID has no significance and we've intentionally started hiding it in recent releases (at least in the web UI: the REST API and deprecated XML-RPC API still need work)
# migrate any erroneous patch-comment-created events to cover-comment-created eventsUPDATE patchwork_event
SET cover_id = patch_id, category ='cover-comment-created', patch_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
with:
# migrate any erroneous patch-comment-created events to cover-comment-created eventsUPDATE patchwork_event
SET
cover_id = patch_id,
cover_comment_id = patch_comment_id,
category ='cover-comment-created',
patch_id =NULL,
patch_comment_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
I get a different error right now:
UPDATE patchwork_event
SET
cover_id = patch_id,
cover_comment_id = patch_comment_id,
category ='cover-comment-created',
patch_id =NULL,
patch_comment_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
ERROR: insert or update on table "patchwork_event" violates foreign key constraint "patchwork_event_cover_comment_id_861b3ec2_fk_patchwork"
DETAIL: Key (cover_comment_id)=(162801) is not present in table "patchwork_covercomment".
By the way, I noticed that new cover IDs started counting from 1 after the migration: patches.dpdk.org/api/covers/1 The last cover ID was 40691 before the migration: patches.dpdk.org/api/covers/40691 I guess it's an expected side effect of removing the old CoverLetter model?
Yes, that's expected behavior. I'm going to guess PostgreSQL was restarted at some point? I know MySQL restarts the autoincrement counter at the lowest available value when it's restarted. It shouldn't matter since the ID has no significance and we've intentionally started hiding it in recent releases (at least in the web UI: the REST API and deprecated XML-RPC API still need work)
Thanks for the confirmation. I don't recall restarting the database server. The counter was reset right after the migration.
Lovely. So when we did the first step in the migration
# copy any recent patch comments that should have been assigned to a cover letter insteadINSERT INTO patchwork_covercomment (msgid, date, headers, content, cover_id, submitter_id)
SELECT msgid, date, headers, content, patch_id, submitter_id
FROM patchwork_patchcomment
WHEREpatchwork_patchcomment.patch_idIN (
SELECTpatch.idFROM patchwork_patch patch WHERE ISNULL(patch.state_id)
);
we will have got a new, likely different ID for each new entry in patchwork_covercomment. As such, we need to set cover_comment_id to the ID of the row in patchwork_covercomment which corresponds to the old patchwork_patchcomment row. I'm not actually entirely sure how to do that. The best I could come up with is this horribly inefficient query.
# migrate any erroneous patch-comment-created events to cover-comment-created eventsUPDATE patchwork_event
SET
cover_id = patch_id,
cover_comment_id = (
SELECTpatchwork_covercomment.idFROM patchwork_covercomment
INNER JOIN patchwork_patchcomment
ONpatchwork_covercomment.msgid=patchwork_patchcomment.msgidWHEREpatchwork_patchcomment.id=patchwork_event.patch_comment_id
),
category ='cover-comment-created',
patch_id =NULL,
patch_comment_id =NULLWHERE patch_id IN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
I've no idea if that will work or not as I still haven't got a full reproducer locally for these follow-up issues.
we will have got a new, likely different ID for each new entry in patchwork_covercomment. As such, we need to set cover_comment_id to the ID of the row in patchwork_covercomment which corresponds to the old patchwork_patchcomment row. I'm not actually entirely sure how to do that. The best I could come up with is this horribly inefficient query.
The UPDATE statement fails with:
ERROR: more than one row returned by a subquery used as an expression
I'm having a difficult time constructing a query to find the problematic IDs though.
Sorry for the late response @stephenfin, I missed your last suggestion.
The suggested query failed with:
ERROR: column "event" of relation "patchwork_event" does not exist
LINE 3: event.cover_id = event.patch_id,
I got it to work with these changes:
UPDATE patchwork_event AS event
SET
cover_id =event.patch_id,
cover_comment_id =cover_comment.id,
category ='cover-comment-created',
patch_id =NULLFROM patchwork_patchcomment patch_comment
INNER JOIN patchwork_covercomment cover_comment
ONpatch_comment.msgid=cover_comment.msgidWHEREpatch_comment.id=event.patch_comment_idANDevent.patch_idIN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
UPDATE 26
Removing duplicate patch comments still fails though:
DELETEFROM patchwork_patchcomment AS patch_comment
WHEREpatch_comment.patch_idIN (
SELECTpatch.idFROM patchwork_patch patch WHEREpatch.state_id IS NULL
);
ERROR: update or delete on table "patchwork_patchcomment" violates foreign key constraint "patchwork_event_patch_comment_id_4123011e_fk_patchwork" on table "patchwork_event"
DETAIL: Key (id)=(162805) is still referenced from table "patchwork_event".
Activity
alialnu commentedon Aug 24, 2023
Both queries now return the same number of rows:
alialnu commentedon Aug 24, 2023
Deleting duplicate patch comments still fails:
stephenfin commentedon Aug 26, 2023
That field should have been unset in the previous statement. Perhaps it needs to be split into two statements. Can you check if it was unset?
alialnu commentedon Aug 26, 2023
That id belongs to a
check-createdevent, so I guess it shouldn't have been affected by the previous query:alialnu commentedon Aug 26, 2023
By the way,
I noticed that new cover IDs started counting from
1after the migration:https://patches.dpdk.org/api/covers/1/
The last cover ID was
40691before the migration:https://patches.dpdk.org/api/covers/40691/
I guess it's an expected side effect of removing the old
CoverLettermodel?stephenfin commentedon Aug 30, 2023
Apologies:
162805refers to a row in thepatchwork_patchcommenttable (I see https://patches.dpdk.org/comment/162805/ resolves to https://patches.dpdk.org/project/dpdk/patch/cover.1640838702.git.songyl@ramaxel.com/#162805). We need to migrate thepatch_comment_idfield tocover_comment_idfield, in addition to migratingpatch_idtocover_id.Let's replace:
with:
stephenfin commentedon Aug 30, 2023
Yes, that's expected behavior. I'm going to guess PostgreSQL was restarted at some point? I know MySQL restarts the autoincrement counter at the lowest available value when it's restarted. It shouldn't matter since the ID has no significance and we've intentionally started hiding it in recent releases (at least in the web UI: the REST API and deprecated XML-RPC API still need work)
alialnu commentedon Aug 30, 2023
I get a different error right now:
alialnu commentedon Aug 30, 2023
Thanks for the confirmation. I don't recall restarting the database server. The counter was reset right after the migration.
stephenfin commentedon Sep 4, 2023
Lovely. So when we did the first step in the migration
we will have got a new, likely different ID for each new entry in
patchwork_covercomment. As such, we need to setcover_comment_idto the ID of the row inpatchwork_covercommentwhich corresponds to the oldpatchwork_patchcommentrow. I'm not actually entirely sure how to do that. The best I could come up with is this horribly inefficient query.I've no idea if that will work or not as I still haven't got a full reproducer locally for these follow-up issues.
stephenfin commentedon Sep 4, 2023
Also, just for my own sanity, I think we're now at the following migration script.
alialnu commentedon Sep 4, 2023
The UPDATE statement fails with:
I'm having a difficult time constructing a query to find the problematic IDs though.
stephenfin commentedon Sep 5, 2023
How about if we drop the subquery and do joins?
Again, disclaimer that this is not beyond validating that it's valid (MySQL) syntax.
alialnu commentedon Sep 5, 2023
Quick update while I try to rewrite the query:
Doesn't seem like it's valid syntax:
https://www.postgresql.org/docs/current/sql-update.html
stephenfin commentedon Sep 5, 2023
Guess that is MySQL only then. I was thinking as much but didn't want to go read the ANSI SQL docs (wherever they live) 😅
EDIT: StackOverflow suggests this might be the equivalent syntax?
?
alialnu commentedon Sep 27, 2023
Sorry for the late response @stephenfin, I missed your last suggestion.
The suggested query failed with:
I got it to work with these changes:
Removing duplicate patch comments still fails though: