This commit is contained in:
rimu 2024-11-15 16:42:08 +13:00
parent 3e0c94c77c
commit d5ae01b456
2 changed files with 52 additions and 2 deletions

View file

@ -2058,7 +2058,7 @@ class UserRegistration(db.Model):
class PostVote(db.Model): class PostVote(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True) post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True)
effect = db.Column(db.Float, index=True) effect = db.Column(db.Float, index=True)
created_at = db.Column(db.DateTime, default=utcnow) created_at = db.Column(db.DateTime, default=utcnow)
@ -2068,7 +2068,7 @@ class PostVote(db.Model):
class PostReplyVote(db.Model): class PostReplyVote(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) # who voted user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) # who voted
author_id = db.Column(db.Integer, db.ForeignKey('user.id')) # the author of the reply voted on - who's reputation is affected author_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) # the author of the reply voted on - who's reputation is affected
post_reply_id = db.Column(db.Integer, db.ForeignKey('post_reply.id'), index=True) post_reply_id = db.Column(db.Integer, db.ForeignKey('post_reply.id'), index=True)
effect = db.Column(db.Float) effect = db.Column(db.Float)
created_at = db.Column(db.DateTime, default=utcnow) created_at = db.Column(db.DateTime, default=utcnow)

View file

@ -0,0 +1,50 @@
"""index on vote.author_id
Revision ID: d32ef1893ce4
Revises: 26138ecda7c3
Create Date: 2024-11-15 16:40:21.080337
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd32ef1893ce4'
down_revision = '26138ecda7c3'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('post_reply_vote', schema=None) as batch_op:
try:
batch_op.create_index(batch_op.f('ix_post_reply_vote_author_id'), ['author_id'], unique=False)
except:
...
with op.batch_alter_table('post_vote', schema=None) as batch_op:
try:
batch_op.create_index(batch_op.f('ix_post_vote_author_id'), ['author_id'], unique=False)
except:
...
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('post_vote', schema=None) as batch_op:
try:
batch_op.drop_index(batch_op.f('ix_post_vote_author_id'))
except:
...
with op.batch_alter_table('post_reply_vote', schema=None) as batch_op:
try:
batch_op.drop_index(batch_op.f('ix_post_reply_vote_author_id'))
except:
...
# ### end Alembic commands ###