Create indices that we will probably need.
This commit is contained in:
parent
540dfd5343
commit
d680a9d173
1 changed files with 20 additions and 8 deletions
|
@ -15,14 +15,14 @@ class BaseModel(Model):
|
|||
|
||||
|
||||
class User(BaseModel):
|
||||
username = CharField(unique=True)
|
||||
username = CharField(unique=True, index=True)
|
||||
password_hash = CharField()
|
||||
email = CharField(unique=True)
|
||||
email = CharField(unique=True, index=True)
|
||||
verified = BooleanField(default=False)
|
||||
|
||||
|
||||
class Visibility(BaseModel):
|
||||
name = CharField()
|
||||
name = CharField(index=True)
|
||||
|
||||
|
||||
class Repository(BaseModel):
|
||||
|
@ -40,14 +40,20 @@ class Repository(BaseModel):
|
|||
|
||||
|
||||
class Role(BaseModel):
|
||||
name = CharField()
|
||||
name = CharField(index=True)
|
||||
|
||||
|
||||
class RepositoryPermission(BaseModel):
|
||||
user = ForeignKeyField(User)
|
||||
repository = ForeignKeyField(Repository)
|
||||
user = ForeignKeyField(User, index=True)
|
||||
repository = ForeignKeyField(Repository, index=True)
|
||||
role = ForeignKeyField(Role)
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
indexes = (
|
||||
(('user', 'repository'), True),
|
||||
)
|
||||
|
||||
|
||||
def random_string_generator(length=16):
|
||||
def random_string():
|
||||
|
@ -58,14 +64,14 @@ def random_string_generator(length=16):
|
|||
|
||||
|
||||
class AccessToken(BaseModel):
|
||||
code = CharField(default=random_string_generator(), unique=True)
|
||||
code = CharField(default=random_string_generator(), unique=True, index=True)
|
||||
user = ForeignKeyField(User)
|
||||
repository = ForeignKeyField(Repository)
|
||||
created = DateTimeField(default=datetime.now)
|
||||
|
||||
|
||||
class EmailConfirmation(BaseModel):
|
||||
code = CharField(default=random_string_generator(), unique=True)
|
||||
code = CharField(default=random_string_generator(), unique=True, index=True)
|
||||
user = ForeignKeyField(User)
|
||||
pw_reset = BooleanField(default=False)
|
||||
email_confirm = BooleanField(default=False)
|
||||
|
@ -96,6 +102,12 @@ class RepositoryTag(BaseModel):
|
|||
image = ForeignKeyField(Image)
|
||||
repository = ForeignKeyField(Repository)
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
indexes = (
|
||||
(('repository', 'name'), True),
|
||||
)
|
||||
|
||||
|
||||
def initialize_db():
|
||||
create_model_tables([User, Repository, Image, AccessToken, Role,
|
||||
|
|
Reference in a new issue