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

Support trigger migrations #3134

Merged
merged 15 commits into from
Mar 20, 2024
Merged

Conversation

dato
Copy link
Contributor

@dato dato commented Nov 25, 2023

  • 0299f2e Add functional tests for search_vector triggers
  • e4d6886 Remove index for author.search_vector, which is never used
  • 44ef928 Alter object row IDs to force test failure in original code
  • 416a6ca Define author_search_vector_trigger via Author.Meta.triggers
  • bcb3a34 Fix JOIN in author_search_vector_trigger, add missing WHERE clause
  • 8df408e Define search_vector_trigger via Book.Meta.triggers
  • 9bcb5b8 Further simplify bookwyrm_author trigger
  • bbfbd1e Add tests for trigger code (i.e. how search_vector is computed)
  • b5805ac Minor improvements to bookwyrm_book trigger code
  • d6eb390 Add test that forces book_authors_search_vector_trigger to execute

This PR uses django-pgtrigger to define triggers as part of model metadata. With this, Django's migration mechanism can be used to keep track of changes.

Done:

  • tests for existing triggers (functional and structural)
  • migrate trigger on bookwyrm_book table
  • migrate trigger on bookwyrm_author table

In a later PR:

  • migrate trigger on bookwyrm_book_authors table

    (pgtriggers docs say the latter probably requires giving Book.authors its own "through" table, which we need anyway for things like Multiple Types of Authors #1120. But that's a more pervasive change, and I don't believe it belongs in this PR.)

    Also, about this trigger, see last commit.)

As metadata changes, search continues to work.
@dato dato force-pushed the trigger_migrations branch 3 times, most recently from 1fc5431 to be64c37 Compare November 25, 2023 01:45
Previously, triggers lived only in a particular migration file. With
this change, code for the triggers resides in the model, and their
lifecycle is managed through normal Django migrations.
@dato dato force-pushed the trigger_migrations branch 2 times, most recently from 4594de3 to 7472383 Compare November 25, 2023 20:02
- do not COALESCE columns that cannot be NULL
- do not bring bookwyrm_book to author names JOIN
- add comments documenting the four steps
@dato dato marked this pull request as ready for review November 26, 2023 00:59
@dato
Copy link
Contributor Author

dato commented Jan 2, 2024

fwiw, I think it might be a good idea to delay merging this until after having tagged the next release. I’m completely fine with that if you agree it makes sense.

@mouse-reeve
Copy link
Member

I agree! I think I'm going to make a release tomorrow morning with just what's already merged unless you think there's anything that should get in under the wire

@dato
Copy link
Contributor Author

dato commented Jan 2, 2024

Only #3096 comes to mind (very optional, just to get it out there?; but I didn’t quite understand what it fixes, so I have no technical opinion).

Current main sounds great!

@mouse-reeve
Copy link
Member

I considered that one and decided to wait because I have zero recollection of why I had it set to the current way, but I know I did it on purpose, and I don't want to have to re-debug it tomorrow. But another day, I will have the willpower to do so 😆

@dato
Copy link
Contributor Author

dato commented Jan 2, 2024 via email

These are tests I missed when first writing trigger tests in
test_book_search.py.
@Minnozz Minnozz mentioned this pull request Mar 19, 2024
5 tasks
@Minnozz Minnozz merged commit 7627868 into bookwyrm-social:main Mar 20, 2024
10 checks passed
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.

None yet

3 participants