Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add management commands to merge a pair of editions or authors #2821

Merged
merged 4 commits into from
Apr 25, 2023

Conversation

bpeel
Copy link
Contributor

@bpeel bpeel commented Apr 15, 2023

This is mostly a request for comments because I’m not sure if it’s a good idea. I made this because I wanted to remove a duplicate author and book from my instance. The existing deduplicate_book_data management command should be able to do the trick but it has a scary warning about proceeding with caution and I was too scared to let the whole script run on my live instance. This branch adds commands which use the same code to merge objects but the pair of objects are specified explicitly with command line arguments so that if it goes horribly wrong then at least the damage is limited to a small set of things.

If you use this branch you can for example merge two editions with a command like this:

docker-compose run --rm web python manage.py merge_editions --canonical=27 --other=38

All the information from the “other” edition that is missing in the “canoncial” edition will be copied over and all comments, lists and reviews etc will be changed to point to the canonical edition. Then the “other” edition will be deleted. You can find the numbers to set by visiting the page for a book and then looking at the number in the URL.

There is a second command to merge two authors like this:

docker-compose run --rm web python manage.py merge_authors --canonical=37 --other=96

Note that this branch includes the commit from PR #2818 because it’s not very useful without it.

bpeel and others added 4 commits April 15, 2023 11:59
Previously when the deduplicate_book_data script tried to merge an
edition that was on a shelf or in a list then it would fail because when
the canonical book was added to the shelf or the list then it wouldn’t
set the extra fields of the linking table for the “through” model of the
field. These would end up defaulting to NULL, but that is not valid for
some of the fields in ShelfItem and ListItem so postgres wouldn’t accept
it.

To fix that, this patch makes it skip updating fields that have a
non-autogenerated linking table. The linking table would appear as a
separate model anyway so the book will be moved via that instead.

Fixes: bookwyrm-social#2817
That way it can be used in a new command to merge individual items.
get rid of the black error.
@jaschaurbach
Copy link
Member

@mouse-reeve @chdorner I just tried it and it works like a charm. Is there anything against merging this into main? This is a feature we really need.

Maybe someone needs to write a test for it.

@mouse-reeve
Copy link
Member

Let me take a look before merging! I should be able to this afternoon

@bpeel
Copy link
Contributor Author

bpeel commented Apr 22, 2023

I’ve added another command on a separate branch that can be used to merge works. This has the effect of combining editions so that they are just editions of the same work instead of being separate works. Eg, if you do this:

docker-compose run --rm web python manage.py merge_works --canonical=37 --other=96

Then it will merge the works corresponding to the editions with the numbers 37 and 96. Note that the IDs are the edition numbers, not the work numbers so you can still look up the numbers by looking at the URL for a book. I don’t think the work numbers are readily accessible via the web interface.

I’ve been recklessly using all of these commands on my instance to clean up some books that got imported badly and so far I haven’t had any problems.

@mouse-reeve
Copy link
Member

That was a longer than planned afternoon! Looks good and thank you

@mouse-reeve mouse-reeve merged commit 8fa89f5 into bookwyrm-social:main Apr 25, 2023
@mouse-reeve
Copy link
Member

You can expose the work id in the UI by going to the list of editions; the url is to the work id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants