from sqlalchemy import (MetaData, Table, Column, Boolean, SmallInteger,
Integer, Unicode, UnicodeText, DateTime,
- ForeignKey, Date)
+ ForeignKey, Date, Index)
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import and_
privilege_user_assoc.c.core__privilege_id.alter(name="user")
db.commit()
+
+@RegisterMigration(22, MIGRATIONS)
+def add_index_username_field(db):
+ """
+ This indexes the User.username field which is frequently queried
+ for example a user logging in. This solves the issue #894
+ """
+ metadata = MetaData(bind=db.bind)
+ user_table = inspect_table(metadata, "core__users")
+
+ new_index = Index("ix_core__users_uploader", user_table.c.username)
+ new_index.create()
+
+ db.commit()
__tablename__ = "core__users"
id = Column(Integer, primary_key=True)
- username = Column(Unicode, nullable=False, unique=True)
+ username = Column(Unicode, nullable=False, unique=True, index=True)
# Note: no db uniqueness constraint on email because it's not
# reliable (many email systems case insensitive despite against
# the RFC) and because it would be a mess to implement at this