Update the model and test db to fix tag support.

This commit is contained in:
yackob03 2013-09-25 17:46:42 -04:00
parent 08446ef59e
commit 5151ea4412
3 changed files with 11 additions and 11 deletions

View file

@ -91,7 +91,7 @@ class RepositoryImage(BaseModel):
def initialize_db(): def initialize_db():
create_model_tables([User, Repository, Image, RepositoryImage, AccessToken, create_model_tables([User, Repository, Image, RepositoryImage, AccessToken,
Role, RepositoryPermission, Visibility]) Role, RepositoryPermission, Visibility, RepositoryTag])
Role.create(name='admin') Role.create(name='admin')
Role.create(name='write') Role.create(name='write')
Role.create(name='read') Role.create(name='read')

View file

@ -114,8 +114,8 @@ def list_repository_tags(namespace_name, repository_name):
select = RepositoryTag.select(RepositoryTag, Image) select = RepositoryTag.select(RepositoryTag, Image)
with_repo = select.join(Repository) with_repo = select.join(Repository)
with_image = with_repo.switch(RepositoryTag).join(Image) with_image = with_repo.switch(RepositoryTag).join(Image)
return joined.where(Repository.name == repository_name and return with_image.where(Repository.name == repository_name and
Repository.namespace == namespace_name) Repository.namespace == namespace_name)
def get_tag_image(namespace_name, repository_name, tag_name): def get_tag_image(namespace_name, repository_name, tag_name):
@ -127,13 +127,13 @@ def get_tag_image(namespace_name, repository_name, tag_name):
def create_or_update_tag(namespace_name, repository_name, tag_name, def create_or_update_tag(namespace_name, repository_name, tag_name,
tag_image_id): tag_image_id):
repo = Repository.get(Repository.name == name and repo = Repository.get(Repository.name == repository_name and
Repository.namespace == namespace) Repository.namespace == namespace_name)
image = Image.get(Image.image_id == tag_image_id) image = Image.get(Image.image_id == tag_image_id)
try: try:
tag = RepositoryTag.get(RepositoryTag.repository == repo and tag = RepositoryTag.get(RepositoryTag.repository == repo and
RepositoryTag.tag_name == tag_name) RepositoryTag.name == tag_name)
tag.image = image tag.image = image
tag.save() tag.save()
except RepositoryTag.DoesNotExist: except RepositoryTag.DoesNotExist:
@ -143,16 +143,16 @@ def create_or_update_tag(namespace_name, repository_name, tag_name,
def delete_tag(namespace_name, repository_name, tag_name): def delete_tag(namespace_name, repository_name, tag_name):
repo = Repository.get(Repository.name == name and repo = Repository.get(Repository.name == repository_name and
Repository.namespace == namespace) Repository.namespace == namespace_name)
tag = RepositoryTag.get(RepositoryTag.repository == repo and tag = RepositoryTag.get(RepositoryTag.repository == repo and
RepositoryTag.tag_name == tag_name) RepositoryTag.name == tag_name)
tag.delete_instance() tag.delete_instance()
def delete_all_repository_tags(namespace_name, repository_name): def delete_all_repository_tags(namespace_name, repository_name):
repo = Repository.get(Repository.name == name and repo = Repository.get(Repository.name == repository_name and
Repository.namespace == namespace) Repository.namespace == namespace_name)
RepositoryTag.delete().where(RepositoryTag.repository == repo) RepositoryTag.delete().where(RepositoryTag.repository == repo)

BIN
test.db

Binary file not shown.