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

Moved migration script in from core. #1071

Merged
merged 5 commits into from Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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()
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -5,6 +5,7 @@ elasticsearch-dsl<2.0.0
pillow
psycopg2
requests==2.18.4
urllib3!=1.24
Copy link
Collaborator

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.

sqlalchemy==1.2.0
flask-sqlalchemy-session
lxml
Expand Down