drop corresponding records from metadataStatus when deleting a metadata#8693
drop corresponding records from metadataStatus when deleting a metadata#8693landryb wants to merge 1 commit intogeonetwork:mainfrom
Conversation
|
not 100% sure but the same issue of 'leftover behind' records might also happen if a category was assigned to a metadata, deleting the metadata wont drop the entry from the i also have a fk constraint there, and i cant delete a metadata record if a metadatacateg is linked to it.. which is strange, since in my initial debugging/testing i saw the |
|
Thank you! At first sight this change looks good; could you try to come up with a test demonstrating this fix and preventing future regressions? I will try to do a more in-depth review |
|
i think creating a metadata, changing its status and deleting it, with that it should leave a record in the |
|
Right! But I meant a unit test in the code; it would make this easier to merge |
well, i dont think thats something i can do easily in a short timeframe. never wrote tests for GN (and i dunno if thats the case for GN, but when a test setup requires docker i give up).. so dont wait for me on that. might be able to look on the long term.. |
There was a problem hiding this comment.
I have tested with a new database and without this change and the metadata can be deleted successfully. The records in the metadata status table are preserved, so the metadata deleted can be restored.
I think with this change, as the metadata status table entries for the metadata are removed, it will not be possible to restore a deleted metadata.
It seems a database migration issue. I would suggest to check the table configuration for metadatastatus of your database and compare it with a new database so can be identified the difference.
Probably the pull request should remove the current change and add a migration script to remove a FK from metadatastatus to metadata table. With a new database I see these 2 FK, please compare with the table in your current database:
|
i have this table, as said it's been through.. a ton of migrations. dont ask me where those FK constraints come from, and which upgrade should have removed them and when, because upgrades have always been a rollercoaster... |
for some reason, on a catalog that went through several upgrades without a reinstall, i ended up with strong foreign key constraints between the metadata and metadatastatus tables (and other extra FK constraints that apparently shouldnt be here anymore either but that's another story):
in that current state of things, that prevents me from deleting a metadata, using 4.2.8. When going through the teardown of all the records in all related tables, the records in the metadatastatus table are left untouched
the
DELETE /geonetwork/srv/api/records/<id>REST call returns a 204 code, leaving one think the MD has been deleted.but in fact the metadata ends up being only removed from the ES index, left in the database tables. reindex the MD in ES, and the metadata you think you've just removed is back.
trying to manually delete the record in the
metadatatable clearly shows that the FK constraint is preventing the deletion:so maybe the FK constraint shouldn't be here, but there will still be leftover records in
metadataStatus.with that PR on top of 4.2.8, the records are dropped in the
metadataStatustable too:and the metadata is then completely removed from the DB.
the issue is probably present in 4.4 or main, just 'hidden' if you dont have the foreign constraint key. STR:
metadataStatustablemetadataStatustable, while the record has been dropped from the other tables.Checklist
mainbranch, backports managed with labelREADME.mdfilespom.xmldependency management. Update build documentation with intended library use and library tutorials or documentationFunded by @gipcraig