Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: series migration to be unique #3417
Add: series migration to be unique #3417
Changes from 10 commits
2711b98
c163f84
bedba39
8ae62da
868659a
fa451f3
999ada0
836d772
691ed88
8b95dd6
66b2905
8a7b5cc
c67b5e9
5154e31
e6e494a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's an issue here that the test doesn't uncover because the bookSeries table you create there is not set-up correctly.
If you examine an actual ABS database, you will see that the bookSeries table has a unique contraint on [bookId, seriesId].
This means that if some book with id
book1
points to two series duplicates with idsseriesDup1
andseriesDup2
, then before this query there are two bookSeries records[book1, seriesDup1]
and[book1, seriesDup2]
, but after this query there will be[book1, seriesDup2]
and[book1, seriesDup2]
, which violates the unique constraint and will throw an exception.I don't know if such a situation occurs in user databases, but we have to assume it does.
Your test won't uncover this (even if it has the right test) since it creates the bookSeries table without the unique constraint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing the unique constraint on [bookId, seriesId]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I was basing my tables off of. If you look at the actual SQLite database, you can see the table is created as below (the unique constraint at the very end of the line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@advplyr where is the statement above coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably here?
audiobookshelf/server/models/BookSeries.js
Lines 32 to 66 in b35fabb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that in itself indicates that databases started at different points in time are not consistent (sigh)...
This requires another migration...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the migration manager support multiple migration scripts for the same release? Or, do I need to change something else in this migration script? I'm a little confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, mutliple migrations scripts in the same version aren't supported.
To be clear, I am not requiring any additional changes in your migration. I was just saying that fact that we have the existing codebase running databases with different schemas is worrying, but wasn't suggesting that we do anything immediate about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how that could have happened since that relationship has always been setup like that since the first release of that table. It could be that I'm the only one with that difference and it happened during the initial development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks!