Merge pull request #1680 from coreos-inc/add-missing-index
Add various missing indexes
This commit is contained in:
commit
6716a2562b
2 changed files with 62 additions and 25 deletions
|
@ -375,7 +375,7 @@ class Team(BaseModel):
|
||||||
|
|
||||||
class TeamMember(BaseModel):
|
class TeamMember(BaseModel):
|
||||||
user = QuayUserField(allows_robots=True, index=True)
|
user = QuayUserField(allows_robots=True, index=True)
|
||||||
team = ForeignKeyField(Team, index=True)
|
team = ForeignKeyField(Team)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -390,7 +390,7 @@ class TeamMemberInvite(BaseModel):
|
||||||
# Note: Either user OR email will be filled in, but not both.
|
# Note: Either user OR email will be filled in, but not both.
|
||||||
user = QuayUserField(index=True, null=True)
|
user = QuayUserField(index=True, null=True)
|
||||||
email = CharField(null=True)
|
email = CharField(null=True)
|
||||||
team = ForeignKeyField(Team, index=True)
|
team = ForeignKeyField(Team)
|
||||||
inviter = ForeignKeyField(User, related_name='inviter')
|
inviter = ForeignKeyField(User, related_name='inviter')
|
||||||
invite_token = CharField(default=urn_generator(['teaminvite']))
|
invite_token = CharField(default=urn_generator(['teaminvite']))
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ class LoginService(BaseModel):
|
||||||
|
|
||||||
class FederatedLogin(BaseModel):
|
class FederatedLogin(BaseModel):
|
||||||
user = QuayUserField(allows_robots=True, index=True)
|
user = QuayUserField(allows_robots=True, index=True)
|
||||||
service = ForeignKeyField(LoginService, index=True)
|
service = ForeignKeyField(LoginService)
|
||||||
service_ident = CharField()
|
service_ident = CharField()
|
||||||
metadata_json = TextField(default='{}')
|
metadata_json = TextField(default='{}')
|
||||||
|
|
||||||
|
@ -449,8 +449,8 @@ class Repository(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class Star(BaseModel):
|
class Star(BaseModel):
|
||||||
user = ForeignKeyField(User, index=True)
|
user = ForeignKeyField(User)
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
created = DateTimeField(default=datetime.now)
|
created = DateTimeField(default=datetime.now)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -467,9 +467,9 @@ class Role(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class RepositoryPermission(BaseModel):
|
class RepositoryPermission(BaseModel):
|
||||||
team = ForeignKeyField(Team, index=True, null=True)
|
team = ForeignKeyField(Team, null=True)
|
||||||
user = QuayUserField(allows_robots=True, index=True, null=True)
|
user = QuayUserField(allows_robots=True, null=True)
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
role = ForeignKeyField(Role)
|
role = ForeignKeyField(Role)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -521,8 +521,8 @@ class BuildTriggerService(BaseModel):
|
||||||
|
|
||||||
class RepositoryBuildTrigger(BaseModel):
|
class RepositoryBuildTrigger(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator)
|
uuid = CharField(default=uuid_generator)
|
||||||
service = ForeignKeyField(BuildTriggerService, index=True)
|
service = ForeignKeyField(BuildTriggerService)
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
connected_user = QuayUserField()
|
connected_user = QuayUserField()
|
||||||
auth_token = CharField(null=True)
|
auth_token = CharField(null=True)
|
||||||
private_key = TextField(null=True)
|
private_key = TextField(null=True)
|
||||||
|
@ -559,7 +559,7 @@ class ImageStorageSignatureKind(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class ImageStorageSignature(BaseModel):
|
class ImageStorageSignature(BaseModel):
|
||||||
storage = ForeignKeyField(ImageStorage, index=True)
|
storage = ForeignKeyField(ImageStorage)
|
||||||
kind = ForeignKeyField(ImageStorageSignatureKind)
|
kind = ForeignKeyField(ImageStorageSignatureKind)
|
||||||
signature = TextField(null=True)
|
signature = TextField(null=True)
|
||||||
uploading = BooleanField(default=True, null=True)
|
uploading = BooleanField(default=True, null=True)
|
||||||
|
@ -612,7 +612,7 @@ class Image(BaseModel):
|
||||||
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
|
# '/' separated list of ancestory ids, e.g. /1/2/6/7/10/
|
||||||
ancestors = CharField(index=True, default='/', max_length=64535, null=True)
|
ancestors = CharField(index=True, default='/', max_length=64535, null=True)
|
||||||
|
|
||||||
storage = ForeignKeyField(ImageStorage, index=True, null=True)
|
storage = ForeignKeyField(ImageStorage, null=True)
|
||||||
|
|
||||||
created = DateTimeField(null=True)
|
created = DateTimeField(null=True)
|
||||||
comment = TextField(null=True)
|
comment = TextField(null=True)
|
||||||
|
@ -625,7 +625,7 @@ class Image(BaseModel):
|
||||||
security_indexed_engine = IntegerField(default=-1, index=True)
|
security_indexed_engine = IntegerField(default=-1, index=True)
|
||||||
|
|
||||||
# We use a proxy here instead of 'self' in order to disable the foreign key constraint
|
# 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')
|
parent = ForeignKeyField(_ImageProxy, null=True, related_name='children')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
@ -676,7 +676,7 @@ class RepositoryTag(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class TagManifest(BaseModel):
|
class TagManifest(BaseModel):
|
||||||
tag = ForeignKeyField(RepositoryTag, index=True, unique=True)
|
tag = ForeignKeyField(RepositoryTag, unique=True)
|
||||||
digest = CharField(index=True)
|
digest = CharField(index=True)
|
||||||
json_data = TextField()
|
json_data = TextField()
|
||||||
|
|
||||||
|
@ -711,30 +711,38 @@ class QueueItem(BaseModel):
|
||||||
|
|
||||||
class RepositoryBuild(BaseModel):
|
class RepositoryBuild(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator, index=True)
|
uuid = CharField(default=uuid_generator, index=True)
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
access_token = ForeignKeyField(AccessToken)
|
access_token = ForeignKeyField(AccessToken)
|
||||||
resource_key = CharField(index=True, null=True)
|
resource_key = CharField(index=True, null=True)
|
||||||
job_config = TextField()
|
job_config = TextField()
|
||||||
phase = CharField(default=BUILD_PHASE.WAITING)
|
phase = CharField(default=BUILD_PHASE.WAITING)
|
||||||
started = DateTimeField(default=datetime.now)
|
started = DateTimeField(default=datetime.now, index=True)
|
||||||
display_name = CharField()
|
display_name = CharField()
|
||||||
trigger = ForeignKeyField(RepositoryBuildTrigger, null=True, index=True)
|
trigger = ForeignKeyField(RepositoryBuildTrigger, null=True)
|
||||||
pull_robot = QuayUserField(null=True, related_name='buildpullrobot', allows_robots=True,
|
pull_robot = QuayUserField(null=True, related_name='buildpullrobot', allows_robots=True,
|
||||||
robot_null_delete=True)
|
robot_null_delete=True)
|
||||||
logs_archived = BooleanField(default=False)
|
logs_archived = BooleanField(default=False)
|
||||||
queue_id = CharField(null=True, index=True)
|
queue_id = CharField(null=True, index=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = db
|
||||||
|
read_slaves = (read_slave,)
|
||||||
|
indexes = (
|
||||||
|
(('repository', 'started', 'phase'), False),
|
||||||
|
(('started', 'logs_archived', 'phase'), False),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LogEntryKind(BaseModel):
|
class LogEntryKind(BaseModel):
|
||||||
name = CharField(index=True, unique=True)
|
name = CharField(index=True, unique=True)
|
||||||
|
|
||||||
|
|
||||||
class LogEntry(BaseModel):
|
class LogEntry(BaseModel):
|
||||||
kind = ForeignKeyField(LogEntryKind, index=True)
|
kind = ForeignKeyField(LogEntryKind)
|
||||||
account = QuayUserField(index=True, related_name='account')
|
account = QuayUserField(index=True, related_name='account')
|
||||||
performer = QuayUserField(allows_robots=True, index=True, null=True,
|
performer = QuayUserField(allows_robots=True, index=True, null=True,
|
||||||
related_name='performer', robot_null_delete=True)
|
related_name='performer', robot_null_delete=True)
|
||||||
repository = ForeignKeyField(Repository, index=True, null=True)
|
repository = ForeignKeyField(Repository, null=True)
|
||||||
datetime = DateTimeField(default=datetime.now, index=True)
|
datetime = DateTimeField(default=datetime.now, index=True)
|
||||||
ip = CharField(null=True)
|
ip = CharField(null=True)
|
||||||
metadata_json = TextField(default='{}')
|
metadata_json = TextField(default='{}')
|
||||||
|
@ -752,7 +760,7 @@ class LogEntry(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class RepositoryActionCount(BaseModel):
|
class RepositoryActionCount(BaseModel):
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
count = IntegerField()
|
count = IntegerField()
|
||||||
date = DateField(index=True)
|
date = DateField(index=True)
|
||||||
|
|
||||||
|
@ -802,7 +810,7 @@ class NotificationKind(BaseModel):
|
||||||
|
|
||||||
class Notification(BaseModel):
|
class Notification(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator, index=True)
|
uuid = CharField(default=uuid_generator, index=True)
|
||||||
kind = ForeignKeyField(NotificationKind, index=True)
|
kind = ForeignKeyField(NotificationKind)
|
||||||
target = QuayUserField(index=True)
|
target = QuayUserField(index=True)
|
||||||
metadata_json = TextField(default='{}')
|
metadata_json = TextField(default='{}')
|
||||||
created = DateTimeField(default=datetime.now, index=True)
|
created = DateTimeField(default=datetime.now, index=True)
|
||||||
|
@ -820,7 +828,7 @@ class ExternalNotificationMethod(BaseModel):
|
||||||
|
|
||||||
class RepositoryNotification(BaseModel):
|
class RepositoryNotification(BaseModel):
|
||||||
uuid = CharField(default=uuid_generator, index=True)
|
uuid = CharField(default=uuid_generator, index=True)
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
event = ForeignKeyField(ExternalNotificationEvent)
|
event = ForeignKeyField(ExternalNotificationEvent)
|
||||||
method = ForeignKeyField(ExternalNotificationMethod)
|
method = ForeignKeyField(ExternalNotificationMethod)
|
||||||
title = CharField(null=True)
|
title = CharField(null=True)
|
||||||
|
@ -829,7 +837,7 @@ class RepositoryNotification(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class RepositoryAuthorizedEmail(BaseModel):
|
class RepositoryAuthorizedEmail(BaseModel):
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
email = CharField()
|
email = CharField()
|
||||||
code = CharField(default=random_string_generator(), unique=True, index=True)
|
code = CharField(default=random_string_generator(), unique=True, index=True)
|
||||||
confirmed = BooleanField(default=False)
|
confirmed = BooleanField(default=False)
|
||||||
|
@ -844,7 +852,7 @@ class RepositoryAuthorizedEmail(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class BlobUpload(BaseModel):
|
class BlobUpload(BaseModel):
|
||||||
repository = ForeignKeyField(Repository, index=True)
|
repository = ForeignKeyField(Repository)
|
||||||
uuid = CharField(index=True, unique=True)
|
uuid = CharField(index=True, unique=True)
|
||||||
byte_count = IntegerField(default=0)
|
byte_count = IntegerField(default=0)
|
||||||
sha_state = ResumableSHA256Field(null=True, default=resumablehashlib.sha256)
|
sha_state = ResumableSHA256Field(null=True, default=resumablehashlib.sha256)
|
||||||
|
@ -931,7 +939,7 @@ class ServiceKey(BaseModel):
|
||||||
created_date = DateTimeField(default=datetime.utcnow)
|
created_date = DateTimeField(default=datetime.utcnow)
|
||||||
expiration_date = DateTimeField(null=True)
|
expiration_date = DateTimeField(null=True)
|
||||||
rotation_duration = IntegerField(null=True)
|
rotation_duration = IntegerField(null=True)
|
||||||
approval = ForeignKeyField(ServiceKeyApproval, index=True, null=True)
|
approval = ForeignKeyField(ServiceKeyApproval, null=True)
|
||||||
|
|
||||||
|
|
||||||
is_model = lambda x: inspect.isclass(x) and issubclass(x, BaseModel) and x is not BaseModel
|
is_model = lambda x: inspect.isclass(x) and issubclass(x, BaseModel) and x is not BaseModel
|
||||||
|
|
29
data/migrations/versions/790d91952fa8_add_missing_indexes.py
Normal file
29
data/migrations/versions/790d91952fa8_add_missing_indexes.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""Add missing indexes
|
||||||
|
|
||||||
|
Revision ID: 790d91952fa8
|
||||||
|
Revises: 1093d8b212bb
|
||||||
|
Create Date: 2016-08-03 17:05:06.675520
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '790d91952fa8'
|
||||||
|
down_revision = '1093d8b212bb'
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
def upgrade(tables):
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_index('repositorybuild_repository_id_started_phase', 'repositorybuild', ['repository_id', 'started', 'phase'], unique=False)
|
||||||
|
op.create_index('repositorybuild_started', 'repositorybuild', ['started'], unique=False)
|
||||||
|
op.create_index('repositorybuild_started_logs_archived_phase', 'repositorybuild', ['started', 'logs_archived', 'phase'], unique=False)
|
||||||
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(tables):
|
||||||
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('repositorybuild_started_logs_archived_phase', table_name='repositorybuild')
|
||||||
|
op.drop_index('repositorybuild_started', table_name='repositorybuild')
|
||||||
|
op.drop_index('repositorybuild_repository_id_started_phase', table_name='repositorybuild')
|
||||||
|
### end Alembic commands ###
|
Reference in a new issue