From 178c5a7ac073843af294a5afc394d66eecc083d6 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 13 Nov 2014 12:51:50 -0500 Subject: [PATCH] Add an index to the docker_image_id for faster lookup --- data/database.py | 2 +- ...c4_add_an_index_to_the_docker_image_id_.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 data/migrations/versions/313d297811c4_add_an_index_to_the_docker_image_id_.py diff --git a/data/database.py b/data/database.py index c12d59f60..c3204f161 100644 --- a/data/database.py +++ b/data/database.py @@ -386,7 +386,7 @@ class Image(BaseModel): # to be globally unique we can't treat them as such for permissions and # security reasons. So rather than Repository <-> Image being many to many # each image now belongs to exactly one repository. - docker_image_id = CharField() + docker_image_id = CharField(index=True) repository = ForeignKeyField(Repository) # '/' separated list of ancestory ids, e.g. /1/2/6/7/10/ diff --git a/data/migrations/versions/313d297811c4_add_an_index_to_the_docker_image_id_.py b/data/migrations/versions/313d297811c4_add_an_index_to_the_docker_image_id_.py new file mode 100644 index 000000000..2ed6bd2f5 --- /dev/null +++ b/data/migrations/versions/313d297811c4_add_an_index_to_the_docker_image_id_.py @@ -0,0 +1,26 @@ +"""Add an index to the docker_image_id field + +Revision ID: 313d297811c4 +Revises: 204abf14783d +Create Date: 2014-11-13 12:40:57.414787 + +""" + +# revision identifiers, used by Alembic. +revision = '313d297811c4' +down_revision = '204abf14783d' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +def upgrade(tables): + ### commands auto generated by Alembic - please adjust! ### + op.create_index('image_docker_image_id', 'image', ['docker_image_id'], unique=False) + ### end Alembic commands ### + + +def downgrade(tables): + ### commands auto generated by Alembic - please adjust! ### + op.drop_index('image_docker_image_id', table_name='image') + ### end Alembic commands ###