Browse Source

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.
master^2
Lephe 2 months ago
parent
commit
8098642d4b
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
  1. 2
      app/models/post.py
  2. 28
      migrations/versions/d2227d2479e2_add_an_index_on_post_type.py

2
app/models/post.py

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

28
migrations/versions/d2227d2479e2_add_an_index_on_post_type.py

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