Merge pull request #900 from jakedt/fixparent

Fix parent to be a relationship again
This commit is contained in:
Jake Moshenko 2015-11-17 16:18:17 -05:00
commit f0a9167275
3 changed files with 16 additions and 9 deletions

View file

@ -552,6 +552,9 @@ class UserRegion(BaseModel):
)
_ImageProxy = Proxy()
class Image(BaseModel):
# This class is intentionally denormalized. Even though images are supposed
# 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_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:
database = db
@ -587,6 +592,9 @@ class Image(BaseModel):
)
_ImageProxy.initialize(Image)
class RepositoryTag(BaseModel):
name = CharField()
image = ForeignKeyField(Image)

View file

@ -227,7 +227,7 @@ def _find_or_link_image(existing_image, repo_obj, username, translations, prefer
comment=existing_image.comment,
v1_json_metadata=existing_image.v1_json_metadata,
aggregate_size=existing_image.aggregate_size,
parent_id=translated_parent_id,
parent=translated_parent_id,
v1_checksum=existing_image.v1_checksum)
@ -327,7 +327,7 @@ def set_image_metadata(docker_image_id, namespace_name, repository_name, created
if parent:
fetched.ancestors = '%s%s/' % (parent.ancestors, parent.id)
fetched.parent_id = parent.id
fetched.parent = parent
fetched.save()
return fetched
@ -429,10 +429,8 @@ def synthesize_v1_image(repo, image_storage, docker_image_id, created_date_str,
specified metadata.
"""
ancestors = '/'
parent_id = None
if parent_image is not None:
ancestors = '{0}{1}/'.format(parent_image.ancestors, parent_image.id)
parent_id = parent_image.id
created = 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,
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):

View file

@ -48,10 +48,11 @@ def gen_sqlalchemy_metadata(peewee_model_list):
alchemy_type = Text
elif isinstance(field, ForeignKeyField):
alchemy_type = Integer
target_name = '%s.%s' % (field.to_field.model_class._meta.db_table,
field.to_field.db_column)
col_args.append(ForeignKey(target_name))
all_indexes.add(((field.name, ), field.unique))
if not field.deferred:
target_name = '%s.%s' % (field.to_field.model_class._meta.db_table,
field.to_field.db_column)
col_args.append(ForeignKey(target_name))
elif isinstance(field, BigIntegerField):
alchemy_type = BigInteger
elif isinstance(field, IntegerField):