Merge pull request #1680 from coreos-inc/add-missing-index

Add various missing indexes
This commit is contained in:
josephschorr 2016-08-08 12:34:58 -04:00 committed by GitHub
commit 6716a2562b
2 changed files with 62 additions and 25 deletions

View file

@ -375,7 +375,7 @@ class Team(BaseModel):
class TeamMember(BaseModel):
user = QuayUserField(allows_robots=True, index=True)
team = ForeignKeyField(Team, index=True)
team = ForeignKeyField(Team)
class Meta:
database = db
@ -390,7 +390,7 @@ class TeamMemberInvite(BaseModel):
# Note: Either user OR email will be filled in, but not both.
user = QuayUserField(index=True, null=True)
email = CharField(null=True)
team = ForeignKeyField(Team, index=True)
team = ForeignKeyField(Team)
inviter = ForeignKeyField(User, related_name='inviter')
invite_token = CharField(default=urn_generator(['teaminvite']))
@ -401,7 +401,7 @@ class LoginService(BaseModel):
class FederatedLogin(BaseModel):
user = QuayUserField(allows_robots=True, index=True)
service = ForeignKeyField(LoginService, index=True)
service = ForeignKeyField(LoginService)
service_ident = CharField()
metadata_json = TextField(default='{}')
@ -449,8 +449,8 @@ class Repository(BaseModel):
class Star(BaseModel):
user = ForeignKeyField(User, index=True)
repository = ForeignKeyField(Repository, index=True)
user = ForeignKeyField(User)
repository = ForeignKeyField(Repository)
created = DateTimeField(default=datetime.now)
class Meta:
@ -467,9 +467,9 @@ class Role(BaseModel):
class RepositoryPermission(BaseModel):
team = ForeignKeyField(Team, index=True, null=True)
user = QuayUserField(allows_robots=True, index=True, null=True)
repository = ForeignKeyField(Repository, index=True)
team = ForeignKeyField(Team, null=True)
user = QuayUserField(allows_robots=True, null=True)
repository = ForeignKeyField(Repository)
role = ForeignKeyField(Role)
class Meta:
@ -521,8 +521,8 @@ class BuildTriggerService(BaseModel):
class RepositoryBuildTrigger(BaseModel):
uuid = CharField(default=uuid_generator)
service = ForeignKeyField(BuildTriggerService, index=True)
repository = ForeignKeyField(Repository, index=True)
service = ForeignKeyField(BuildTriggerService)
repository = ForeignKeyField(Repository)
connected_user = QuayUserField()
auth_token = CharField(null=True)
private_key = TextField(null=True)
@ -559,7 +559,7 @@ class ImageStorageSignatureKind(BaseModel):
class ImageStorageSignature(BaseModel):
storage = ForeignKeyField(ImageStorage, index=True)
storage = ForeignKeyField(ImageStorage)
kind = ForeignKeyField(ImageStorageSignatureKind)
signature = TextField(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/
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)
comment = TextField(null=True)
@ -625,7 +625,7 @@ class Image(BaseModel):
security_indexed_engine = IntegerField(default=-1, index=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')
parent = ForeignKeyField(_ImageProxy, null=True, related_name='children')
class Meta:
database = db
@ -676,7 +676,7 @@ class RepositoryTag(BaseModel):
class TagManifest(BaseModel):
tag = ForeignKeyField(RepositoryTag, index=True, unique=True)
tag = ForeignKeyField(RepositoryTag, unique=True)
digest = CharField(index=True)
json_data = TextField()
@ -711,30 +711,38 @@ class QueueItem(BaseModel):
class RepositoryBuild(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
access_token = ForeignKeyField(AccessToken)
resource_key = CharField(index=True, null=True)
job_config = TextField()
phase = CharField(default=BUILD_PHASE.WAITING)
started = DateTimeField(default=datetime.now)
started = DateTimeField(default=datetime.now, index=True)
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,
robot_null_delete=True)
logs_archived = BooleanField(default=False)
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):
name = CharField(index=True, unique=True)
class LogEntry(BaseModel):
kind = ForeignKeyField(LogEntryKind, index=True)
kind = ForeignKeyField(LogEntryKind)
account = QuayUserField(index=True, related_name='account')
performer = QuayUserField(allows_robots=True, index=True, null=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)
ip = CharField(null=True)
metadata_json = TextField(default='{}')
@ -752,7 +760,7 @@ class LogEntry(BaseModel):
class RepositoryActionCount(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
count = IntegerField()
date = DateField(index=True)
@ -802,7 +810,7 @@ class NotificationKind(BaseModel):
class Notification(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
kind = ForeignKeyField(NotificationKind, index=True)
kind = ForeignKeyField(NotificationKind)
target = QuayUserField(index=True)
metadata_json = TextField(default='{}')
created = DateTimeField(default=datetime.now, index=True)
@ -820,7 +828,7 @@ class ExternalNotificationMethod(BaseModel):
class RepositoryNotification(BaseModel):
uuid = CharField(default=uuid_generator, index=True)
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
event = ForeignKeyField(ExternalNotificationEvent)
method = ForeignKeyField(ExternalNotificationMethod)
title = CharField(null=True)
@ -829,7 +837,7 @@ class RepositoryNotification(BaseModel):
class RepositoryAuthorizedEmail(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
email = CharField()
code = CharField(default=random_string_generator(), unique=True, index=True)
confirmed = BooleanField(default=False)
@ -844,7 +852,7 @@ class RepositoryAuthorizedEmail(BaseModel):
class BlobUpload(BaseModel):
repository = ForeignKeyField(Repository, index=True)
repository = ForeignKeyField(Repository)
uuid = CharField(index=True, unique=True)
byte_count = IntegerField(default=0)
sha_state = ResumableSHA256Field(null=True, default=resumablehashlib.sha256)
@ -931,7 +939,7 @@ class ServiceKey(BaseModel):
created_date = DateTimeField(default=datetime.utcnow)
expiration_date = DateTimeField(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

View 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 ###