model: add an index on Post.type

This is useful to quickly browse a list of polymorphic Posts for topics,
programs, etc. The main application is from Member.posts, since
polymorphic collection seems both difficult and edgy.

[MIGRATION] This commit contains a new version of the schema.
This commit is contained in:
Lephe 2022-04-25 16:45:21 +01:00
parent 8eee0ad236
commit 8098642d4b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 29 additions and 1 deletions

View File

@ -10,7 +10,7 @@ class Post(db.Model):
# Unique Post ID for the whole site
id = db.Column(db.Integer, primary_key=True)
# Post type (polymorphic discriminator)
type = db.Column(db.String(20))
type = db.Column(db.String(20), index=True)
# Creation and edition date
date_created = db.Column(db.DateTime)

View File

@ -0,0 +1,28 @@
"""Add an index on Post.type
Revision ID: d2227d2479e2
Revises: bcfdb271b88d
Create Date: 2022-04-25 16:44:51.241965
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd2227d2479e2'
down_revision = 'bcfdb271b88d'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_post_type'), 'post', ['type'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_post_type'), table_name='post')
# ### end Alembic commands ###