Browse Source

model: add a number of missing indexes

See #107.

[MIGRATION] This commit contains a new version of the schema.
master^2
Lephe 4 months ago
parent
commit
39748667ee
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
  1. 3
      app/models/attachment.py
  2. 3
      app/models/notification.py
  3. 2
      app/models/poll.py
  4. 5
      app/models/post.py
  5. 3
      app/models/topic.py
  6. 2
      app/models/trophy.py
  7. 40
      migrations/versions/bcfdb271b88d_add_a_number_of_missing_indexes.py

3
app/models/attachment.py

@ -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

3
app/models/notification.py

@ -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)

2
app/models/poll.py

@ -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)

5
app/models/post.py

@ -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__ = {

3
app/models/topic.py

@ -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)

2
app/models/trophy.py

@ -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))

40
migrations/versions/bcfdb271b88d_add_a_number_of_missing_indexes.py

@ -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 ###
Loading…
Cancel
Save