-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The join that was used to match books to a changed author used the id column instead of the author_id column to join on authors. This migration re-calculates all book search vectors to fix any missed author name changes.
- Loading branch information
1 parent
304c478
commit adaf7a3
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookwyrm", "0195_alter_user_preferred_language"), | ||
] | ||
|
||
operations = [ | ||
# join on bookwyrm_book_authors.author_id instead of .id | ||
migrations.RunSQL( | ||
sql=""" | ||
CREATE OR REPLACE FUNCTION author_trigger() RETURNS trigger AS $$ | ||
begin | ||
WITH book AS ( | ||
SELECT bookwyrm_book.id as row_id | ||
FROM bookwyrm_author | ||
LEFT OUTER JOIN bookwyrm_book_authors | ||
ON bookwyrm_book_authors.author_id = new.id | ||
LEFT OUTER JOIN bookwyrm_book | ||
ON bookwyrm_book.id = bookwyrm_book_authors.book_id | ||
) | ||
UPDATE bookwyrm_book SET search_vector = '' | ||
FROM book | ||
WHERE id = book.row_id; | ||
return new; | ||
end | ||
$$ LANGUAGE plpgsql; | ||
UPDATE bookwyrm_book SET search_vector = NULL; | ||
""", | ||
reverse_sql=""" | ||
CREATE OR REPLACE FUNCTION author_trigger() RETURNS trigger AS $$ | ||
begin | ||
WITH book AS ( | ||
SELECT bookwyrm_book.id as row_id | ||
FROM bookwyrm_author | ||
LEFT OUTER JOIN bookwyrm_book_authors | ||
ON bookwyrm_book_authors.id = new.id | ||
LEFT OUTER JOIN bookwyrm_book | ||
ON bookwyrm_book.id = bookwyrm_book_authors.book_id | ||
) | ||
UPDATE bookwyrm_book SET search_vector = '' | ||
FROM book | ||
WHERE id = book.row_id; | ||
return new; | ||
end | ||
$$ LANGUAGE plpgsql; | ||
""", | ||
), | ||
] |