model: add a number of missing indexes

See #107.

[MIGRATION] This commit contains a new version of the schema.
This commit is contained in:
Lephe 2022-04-21 17:54:30 +01:00
parent 19d90c6845
commit 39748667ee
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
7 changed files with 51 additions and 7 deletions

View File

@ -13,7 +13,8 @@ class Attachment(db.Model):
name = db.Column(db.Unicode(64))
# The comment linked with
comment_id = db.Column(db.Integer, db.ForeignKey('comment.id'), nullable=False)
comment_id = db.Column(db.Integer, db.ForeignKey('comment.id'),
nullable=False, index=True)
comment = db.relationship('Comment', backref=backref('attachments'))
# The size of the file

View File

@ -11,7 +11,8 @@ class Notification(db.Model):
href = db.Column(db.UnicodeText)
date = db.Column(db.DateTime, default=datetime.now())
owner_id = db.Column(db.Integer, db.ForeignKey('member.id'),nullable=False)
owner_id = db.Column(db.Integer, db.ForeignKey('member.id'),
nullable=False, index=True)
owner = db.relationship('Member', backref='notifications',
foreign_keys=owner_id)

View File

@ -103,7 +103,7 @@ class PollAnswer(db.Model):
id = db.Column(db.Integer, primary_key=True)
# Poll
poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'))
poll_id = db.Column(db.Integer, db.ForeignKey('poll.id'), index=True)
poll = db.relationship('Poll', backref=backref('answers'),
foreign_keys=poll_id)

View File

@ -14,10 +14,11 @@ class Post(db.Model):
# Creation and edition date
date_created = db.Column(db.DateTime)
date_modified = db.Column(db.DateTime)
date_modified = db.Column(db.DateTime, index=True)
# Post author
author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False,
index=True)
author = db.relationship('User', backref="posts", foreign_keys=author_id)
__mapper_args__ = {

View File

@ -23,7 +23,8 @@ class Topic(Post):
title = db.Column(db.Unicode(128))
# Parent forum
forum_id = db.Column(db.Integer, db.ForeignKey('forum.id'), nullable=False)
forum_id = db.Column(db.Integer, db.ForeignKey('forum.id'), nullable=False,
index=True)
forum = db.relationship('Forum',
backref=backref('topics', lazy='dynamic'), foreign_keys=forum_id)

View File

@ -59,4 +59,4 @@ class Title(Trophy):
# Many-to-many relation for users earning trophies
TrophyMember = db.Table('trophy_member', db.Model.metadata,
db.Column('tid', db.Integer, db.ForeignKey('trophy.id')),
db.Column('uid', db.Integer, db.ForeignKey('member.id')))
db.Column('uid', db.Integer, db.ForeignKey('member.id'), index=True))

View File

@ -0,0 +1,40 @@
"""Add a number of missing indexes
Revision ID: bcfdb271b88d
Revises: adcd1577f301
Create Date: 2022-04-21 17:45:09.787769
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'bcfdb271b88d'
down_revision = 'adcd1577f301'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_attachment_comment_id'), 'attachment', ['comment_id'], unique=False)
op.create_index(op.f('ix_notification_owner_id'), 'notification', ['owner_id'], unique=False)
op.create_index(op.f('ix_pollanswer_poll_id'), 'pollanswer', ['poll_id'], unique=False)
op.create_index(op.f('ix_post_author_id'), 'post', ['author_id'], unique=False)
op.create_index(op.f('ix_post_date_modified'), 'post', ['date_modified'], unique=False)
op.create_index(op.f('ix_topic_forum_id'), 'topic', ['forum_id'], unique=False)
op.create_index(op.f('ix_trophy_member_uid'), 'trophy_member', ['uid'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_trophy_member_uid'), table_name='trophy_member')
op.drop_index(op.f('ix_topic_forum_id'), table_name='topic')
op.drop_index(op.f('ix_post_date_modified'), table_name='post')
op.drop_index(op.f('ix_post_author_id'), table_name='post')
op.drop_index(op.f('ix_pollanswer_poll_id'), table_name='pollanswer')
op.drop_index(op.f('ix_notification_owner_id'), table_name='notification')
op.drop_index(op.f('ix_attachment_comment_id'), table_name='attachment')
# ### end Alembic commands ###