From 0fa8c674b2d3608de254d0be2670654105a2319b Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:18:11 +1300 Subject: [PATCH] post vote effect index --- app/models.py | 2 +- .../versions/aaf434e9e7bf_post_vote_index.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/aaf434e9e7bf_post_vote_index.py diff --git a/app/models.py b/app/models.py index bc9be476..8e33d3bd 100644 --- a/app/models.py +++ b/app/models.py @@ -835,7 +835,7 @@ class PostVote(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('user.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) - effect = db.Column(db.Float) + effect = db.Column(db.Float, index=True) created_at = db.Column(db.DateTime, default=utcnow) post = db.relationship('Post', foreign_keys=[post_id]) diff --git a/migrations/versions/aaf434e9e7bf_post_vote_index.py b/migrations/versions/aaf434e9e7bf_post_vote_index.py new file mode 100644 index 00000000..40d13487 --- /dev/null +++ b/migrations/versions/aaf434e9e7bf_post_vote_index.py @@ -0,0 +1,32 @@ +"""post vote index + +Revision ID: aaf434e9e7bf +Revises: 5b4a967f9988 +Create Date: 2024-01-10 10:17:47.397781 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'aaf434e9e7bf' +down_revision = '5b4a967f9988' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('post_vote', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_post_vote_effect'), ['effect'], unique=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('post_vote', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_post_vote_effect')) + + # ### end Alembic commands ###