Switch parent back to a ForeignKeyField without a constraint
This commit is contained in:
parent
3374e8c812
commit
e252397292
2 changed files with 12 additions and 6 deletions
|
@ -552,6 +552,9 @@ class UserRegion(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_ImageProxy = Proxy()
|
||||||
|
|
||||||
|
|
||||||
class Image(BaseModel):
|
class Image(BaseModel):
|
||||||
# This class is intentionally denormalized. Even though images are supposed
|
# This class is intentionally denormalized. Even though images are supposed
|
||||||
# to be globally unique we can't treat them as such for permissions and
|
# to be globally unique we can't treat them as such for permissions and
|
||||||
|
@ -574,7 +577,9 @@ class Image(BaseModel):
|
||||||
|
|
||||||
security_indexed = BooleanField(default=False)
|
security_indexed = BooleanField(default=False)
|
||||||
security_indexed_engine = IntegerField(default=-1)
|
security_indexed_engine = IntegerField(default=-1)
|
||||||
parent_id = IntegerField(index=True, null=True)
|
|
||||||
|
# We use a proxy here instead of 'self' in order to disable the foreign key constraint
|
||||||
|
parent = ForeignKeyField(_ImageProxy, index=True, null=True, related_name='children')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -587,6 +592,9 @@ class Image(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_ImageProxy.initialize(Image)
|
||||||
|
|
||||||
|
|
||||||
class RepositoryTag(BaseModel):
|
class RepositoryTag(BaseModel):
|
||||||
name = CharField()
|
name = CharField()
|
||||||
image = ForeignKeyField(Image)
|
image = ForeignKeyField(Image)
|
||||||
|
|
|
@ -227,7 +227,7 @@ def _find_or_link_image(existing_image, repo_obj, username, translations, prefer
|
||||||
comment=existing_image.comment,
|
comment=existing_image.comment,
|
||||||
v1_json_metadata=existing_image.v1_json_metadata,
|
v1_json_metadata=existing_image.v1_json_metadata,
|
||||||
aggregate_size=existing_image.aggregate_size,
|
aggregate_size=existing_image.aggregate_size,
|
||||||
parent_id=translated_parent_id,
|
parent=translated_parent_id,
|
||||||
v1_checksum=existing_image.v1_checksum)
|
v1_checksum=existing_image.v1_checksum)
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ def set_image_metadata(docker_image_id, namespace_name, repository_name, created
|
||||||
|
|
||||||
if parent:
|
if parent:
|
||||||
fetched.ancestors = '%s%s/' % (parent.ancestors, parent.id)
|
fetched.ancestors = '%s%s/' % (parent.ancestors, parent.id)
|
||||||
fetched.parent_id = parent.id
|
fetched.parent = parent
|
||||||
|
|
||||||
fetched.save()
|
fetched.save()
|
||||||
return fetched
|
return fetched
|
||||||
|
@ -429,10 +429,8 @@ def synthesize_v1_image(repo, image_storage, docker_image_id, created_date_str,
|
||||||
specified metadata.
|
specified metadata.
|
||||||
"""
|
"""
|
||||||
ancestors = '/'
|
ancestors = '/'
|
||||||
parent_id = None
|
|
||||||
if parent_image is not None:
|
if parent_image is not None:
|
||||||
ancestors = '{0}{1}/'.format(parent_image.ancestors, parent_image.id)
|
ancestors = '{0}{1}/'.format(parent_image.ancestors, parent_image.id)
|
||||||
parent_id = parent_image.id
|
|
||||||
|
|
||||||
created = None
|
created = None
|
||||||
if created_date_str is not None:
|
if created_date_str is not None:
|
||||||
|
@ -444,7 +442,7 @@ def synthesize_v1_image(repo, image_storage, docker_image_id, created_date_str,
|
||||||
|
|
||||||
return Image.create(docker_image_id=docker_image_id, ancestors=ancestors, comment=comment,
|
return Image.create(docker_image_id=docker_image_id, ancestors=ancestors, comment=comment,
|
||||||
command=command, v1_json_metadata=v1_json_metadata, created=created,
|
command=command, v1_json_metadata=v1_json_metadata, created=created,
|
||||||
storage=image_storage, repository=repo, parent_id=parent_id)
|
storage=image_storage, repository=repo, parent=parent_image)
|
||||||
|
|
||||||
|
|
||||||
def ensure_image_locations(*names):
|
def ensure_image_locations(*names):
|
||||||
|
|
Reference in a new issue