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
Moved migration script in from core. #1071
Merged
leonardr
merged 5 commits into
master
from
prevent-audiobooks-from-being-treated-as-books
Oct 16, 2018
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29b8b97
Moved migration script in from core.
leonardr ee80161
Exclude a just-released version of urllib3 which causes problems.
leonardr 1acb3ec
Change urllib3 pin and add note to check when we can remove it.
leonardr 3725fc1
Update the search index when migrating.
leonardr 2edfbf8
Make sure that a Metdata object created for RBdigital always has a .m…
leonardr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Submodule core
updated
14 files
+2 −0 | entrypoint.py | |
+45 −8 | lane.py | |
+1 −1 | metadata_layer.py | |
+1 −0 | migration/20181015-size-by-entrypoint.sql | |
+16 −5 | model/constants.py | |
+9 −10 | model/edition.py | |
+1 −1 | model/licensing.py | |
+4 −4 | model/resource.py | |
+27 −18 | tests/models/test_edition.py | |
+49 −32 | tests/models/test_licensing.py | |
+3 −0 | tests/test_entrypoint.py | |
+92 −9 | tests/test_lane.py | |
+7 −0 | tests/test_metadata.py | |
+3 −3 | tests/test_scripts.py |
49 changes: 49 additions & 0 deletions
49
migration/20181016-recalculate-presentation-for-audiobooks-believed-to-be-books.py
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,49 @@ | ||
import os | ||
import sys | ||
from nose.tools import set_trace | ||
from sqlalchemy.sql import select | ||
from sqlalchemy.sql.expression import ( | ||
join, | ||
and_, | ||
) | ||
bin_dir = os.path.split(__file__)[0] | ||
package_dir = os.path.join(bin_dir, "..") | ||
sys.path.append(os.path.abspath(package_dir)) | ||
from core.model import ( | ||
dump_query, | ||
production_session, | ||
LicensePool, | ||
DataSource, | ||
Edition, | ||
PresentationCalculationPolicy, | ||
) | ||
|
||
# Find all books where the edition associated with the LicensePool has a | ||
# different medium from the presentation edition. | ||
_db = production_session() | ||
|
||
# Find all the LicensePools that aren't books. | ||
subq = select([LicensePool.id]).select_from( | ||
join(LicensePool, Edition, | ||
and_(LicensePool.data_source_id==Edition.data_source_id, | ||
LicensePool.identifier_id==Edition.primary_identifier_id) | ||
) | ||
).where(Edition.medium != Edition.BOOK_MEDIUM) | ||
|
||
# Of those LicensePools, find every LicensePool whose presentation | ||
# edition says it _is_ a book. | ||
qu = _db.query(LicensePool).join( | ||
Edition, LicensePool.presentation_edition_id==Edition.id | ||
).filter(LicensePool.id.in_(subq)).filter(Edition.medium == Edition.BOOK_MEDIUM) | ||
|
||
print "Recalculating presentation edition for %d LicensePools." % qu.count() | ||
|
||
for lp in qu: | ||
# Recalculate that LicensePool's presentation edition, and then its | ||
# work presentation. | ||
lp.set_presentation_edition() | ||
policy = PresentationCalculationPolicy(regenerate_opds_entries=True) | ||
work, is_new = lp.calculate_work() | ||
work.calculate_presentation(policy) | ||
print "New medium: %s" % lp.presentation_edition.medium | ||
_db.commit() |
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
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.
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'd do < 1.24 since there may be more releases with the same problem.