Phase 1 of migrating APPR-specific tables to tables with the Appr
prefix
Fixes https://jira.coreos.com/browse/QUAY-950
This commit is contained in:
parent
6622f27c93
commit
113bb96f29
28 changed files with 699 additions and 176 deletions
|
@ -3,7 +3,6 @@ import logging
|
|||
from peewee import IntegrityError
|
||||
|
||||
from data.model import db_transaction
|
||||
from data.database import Blob, BlobPlacementLocation, BlobPlacement
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -13,17 +12,20 @@ def _ensure_sha256_header(digest):
|
|||
return 'sha256:' + digest
|
||||
|
||||
|
||||
def get_blob(digest):
|
||||
def get_blob(digest, models_ref):
|
||||
""" Find a blob by its digest. """
|
||||
Blob = models_ref.Blob
|
||||
return Blob.select().where(Blob.digest == _ensure_sha256_header(digest)).get()
|
||||
|
||||
|
||||
def get_or_create_blob(digest, size, media_type_name, locations):
|
||||
def get_or_create_blob(digest, size, media_type_name, locations, models_ref):
|
||||
""" Try to find a blob by its digest or create it. """
|
||||
Blob = models_ref.Blob
|
||||
BlobPlacement = models_ref.BlobPlacement
|
||||
|
||||
# Get or create the blog entry for the digest.
|
||||
try:
|
||||
blob = get_blob(digest)
|
||||
blob = get_blob(digest, models_ref)
|
||||
logger.debug('Retrieved blob with digest %s', digest)
|
||||
except Blob.DoesNotExist:
|
||||
blob = Blob.create(digest=_ensure_sha256_header(digest),
|
||||
|
@ -38,13 +40,16 @@ def get_or_create_blob(digest, size, media_type_name, locations):
|
|||
BlobPlacement.create(blob=blob, location=location_id)
|
||||
except IntegrityError:
|
||||
logger.debug('Location %s already existing for blob %s', location_name, blob.id)
|
||||
pass
|
||||
|
||||
return blob
|
||||
|
||||
|
||||
def get_blob_locations(digest):
|
||||
def get_blob_locations(digest, models_ref):
|
||||
""" Find all locations names for a blob. """
|
||||
Blob = models_ref.Blob
|
||||
BlobPlacement = models_ref.BlobPlacement
|
||||
BlobPlacementLocation = models_ref.BlobPlacementLocation
|
||||
|
||||
return [x.name for x in
|
||||
BlobPlacementLocation
|
||||
.select()
|
||||
|
@ -53,7 +58,9 @@ def get_blob_locations(digest):
|
|||
.where(Blob.digest == _ensure_sha256_header(digest))]
|
||||
|
||||
|
||||
def ensure_blob_locations(*names):
|
||||
def ensure_blob_locations(models_ref, *names):
|
||||
BlobPlacementLocation = models_ref.BlobPlacementLocation
|
||||
|
||||
with db_transaction():
|
||||
locations = BlobPlacementLocation.select().where(BlobPlacementLocation.name << names)
|
||||
|
||||
|
|
Reference in a new issue