mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
migration for tags and languages
This commit is contained in:
parent
516eafa1f3
commit
98207edb13
2 changed files with 96 additions and 0 deletions
|
@ -1294,6 +1294,33 @@ class Site(db.Model):
|
||||||
return User.query.filter_by(deleted=False, banned=False).join(user_role).filter(user_role.c.role_id == 4).all()
|
return User.query.filter_by(deleted=False, banned=False).join(user_role).filter(user_role.c.role_id == 4).all()
|
||||||
|
|
||||||
|
|
||||||
|
class Tag(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
name = db.Column(db.String(256))
|
||||||
|
|
||||||
|
|
||||||
|
class Language(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
code = db.Column(db.String(5), index=True)
|
||||||
|
name = db.Column(db.String(50))
|
||||||
|
|
||||||
|
|
||||||
|
post_language = db.Table('post_language', db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
|
||||||
|
db.Column('language_id', db.Integer, db.ForeignKey('language.id')),
|
||||||
|
db.PrimaryKeyConstraint('post_id', 'language_id')
|
||||||
|
)
|
||||||
|
|
||||||
|
community_language = db.Table('community_language', db.Column('community_id', db.Integer, db.ForeignKey('community.id')),
|
||||||
|
db.Column('language_id', db.Integer, db.ForeignKey('language.id')),
|
||||||
|
db.PrimaryKeyConstraint('community_id', 'language_id')
|
||||||
|
)
|
||||||
|
|
||||||
|
post_tag = db.Table('post_tag', db.Column('post_id', db.Integer, db.ForeignKey('post.id')),
|
||||||
|
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
|
||||||
|
db.PrimaryKeyConstraint('post_id', 'tag_id')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@login.user_loader
|
@login.user_loader
|
||||||
def load_user(id):
|
def load_user(id):
|
||||||
return User.query.get(int(id))
|
return User.query.get(int(id))
|
||||||
|
|
69
migrations/versions/fd2af23f4b1f_tags_and_languages.py
Normal file
69
migrations/versions/fd2af23f4b1f_tags_and_languages.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
"""tags and languages
|
||||||
|
|
||||||
|
Revision ID: fd2af23f4b1f
|
||||||
|
Revises: 91a931afd6d9
|
||||||
|
Create Date: 2024-04-16 21:15:07.225254
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'fd2af23f4b1f'
|
||||||
|
down_revision = '91a931afd6d9'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('language',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('code', sa.String(length=5), nullable=True),
|
||||||
|
sa.Column('name', sa.String(length=50), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('language', schema=None) as batch_op:
|
||||||
|
batch_op.create_index(batch_op.f('ix_language_code'), ['code'], unique=False)
|
||||||
|
|
||||||
|
op.create_table('tag',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=256), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('community_language',
|
||||||
|
sa.Column('community_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('language_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['community_id'], ['community.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['language_id'], ['language.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('community_id', 'language_id')
|
||||||
|
)
|
||||||
|
op.create_table('post_language',
|
||||||
|
sa.Column('post_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('language_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['language_id'], ['language.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('post_id', 'language_id')
|
||||||
|
)
|
||||||
|
op.create_table('post_tag',
|
||||||
|
sa.Column('post_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('tag_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('post_id', 'tag_id')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('post_tag')
|
||||||
|
op.drop_table('post_language')
|
||||||
|
op.drop_table('community_language')
|
||||||
|
op.drop_table('tag')
|
||||||
|
with op.batch_alter_table('language', schema=None) as batch_op:
|
||||||
|
batch_op.drop_index(batch_op.f('ix_language_code'))
|
||||||
|
|
||||||
|
op.drop_table('language')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in a new issue