programs: add the model for tags

[MIGRATION] This commit contains a new version of the schema.
This commit is contained in:
Lephe 2022-05-19 18:50:49 +01:00
parent 13ce27b682
commit 011ea3d2a6
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 56 additions and 0 deletions

View File

@ -4,3 +4,4 @@ from app.models.forum import Forum
from app.models.topic import Topic
from app.models.notification import Notification
from app.models.program import Program
from app.models.tag import Tag

View File

@ -19,6 +19,8 @@ class Program(Post):
thread = db.relationship('Thread', foreign_keys=thread_id,
back_populates='owner_program')
tags = db.relationship('Tag', back_populates='post', lazy='joined')
# TODO: Number of views, statistics, attached files, etc
def __init__(self, author, title, thread):

15
app/models/tag.py Normal file
View File

@ -0,0 +1,15 @@
from app import db
class Tag(db.Model):
__tablename__ = 'tag'
id = db.Column(db.Integer, primary_key=True)
# Tagged post
post_id = db.Column(db.Integer, db.ForeignKey('post.id'), index=True)
post = db.relationship('Post', back_populates='tags', foreign_keys=post_id)
# Tag name
name = db.Column(db.String(64), index=True)
def __init__(self, post, tag):
self.post = post
self.tag = tag

View File

@ -0,0 +1,38 @@
"""add tags for programs
Revision ID: 1de8b6b6aed8
Revises: fcf53f1a14e3
Create Date: 2022-05-19 18:50:12.894735
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1de8b6b6aed8'
down_revision = 'fcf53f1a14e3'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('tag',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('post_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(length=64), nullable=True),
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_tag_name'), 'tag', ['name'], unique=False)
op.create_index(op.f('ix_tag_post_id'), 'tag', ['post_id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_tag_post_id'), table_name='tag')
op.drop_index(op.f('ix_tag_name'), table_name='tag')
op.drop_table('tag')
# ### end Alembic commands ###