mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
post licence model and migration
This commit is contained in:
parent
2e9720539c
commit
88d28c1464
3 changed files with 50 additions and 1 deletions
|
@ -225,6 +225,11 @@ class Tag(db.Model):
|
||||||
banned = db.Column(db.Boolean, default=False, index=True)
|
banned = db.Column(db.Boolean, default=False, index=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Licence(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
name = db.Column(db.String(50))
|
||||||
|
|
||||||
|
|
||||||
class Language(db.Model):
|
class Language(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
code = db.Column(db.String(5), index=True)
|
code = db.Column(db.String(5), index=True)
|
||||||
|
@ -1073,6 +1078,7 @@ class Post(db.Model):
|
||||||
image_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True)
|
image_id = db.Column(db.Integer, db.ForeignKey('file.id'), index=True)
|
||||||
domain_id = db.Column(db.Integer, db.ForeignKey('domain.id'), index=True)
|
domain_id = db.Column(db.Integer, db.ForeignKey('domain.id'), index=True)
|
||||||
instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True)
|
instance_id = db.Column(db.Integer, db.ForeignKey('instance.id'), index=True)
|
||||||
|
licence_id = db.Column(db.Integer, db.ForeignKey('licence.id'), index=True)
|
||||||
slug = db.Column(db.String(255))
|
slug = db.Column(db.String(255))
|
||||||
title = db.Column(db.String(255))
|
title = db.Column(db.String(255))
|
||||||
url = db.Column(db.String(2048))
|
url = db.Column(db.String(2048))
|
||||||
|
@ -1118,6 +1124,7 @@ class Post(db.Model):
|
||||||
community = db.relationship('Community', lazy='joined', overlaps='posts', foreign_keys=[community_id])
|
community = db.relationship('Community', lazy='joined', overlaps='posts', foreign_keys=[community_id])
|
||||||
replies = db.relationship('PostReply', lazy='dynamic', backref='post')
|
replies = db.relationship('PostReply', lazy='dynamic', backref='post')
|
||||||
language = db.relationship('Language', foreign_keys=[language_id])
|
language = db.relationship('Language', foreign_keys=[language_id])
|
||||||
|
licence = db.relationship('Licence', foreign_keys=[language_id], lazy='dynamic')
|
||||||
|
|
||||||
# db relationship tracked by the "read_posts" table
|
# db relationship tracked by the "read_posts" table
|
||||||
# this is the Post side, so its referencing the User side
|
# this is the Post side, so its referencing the User side
|
||||||
|
|
|
@ -111,7 +111,7 @@ def show_post(post_id: int):
|
||||||
'name': reply.language_name()
|
'name': reply.language_name()
|
||||||
},
|
},
|
||||||
'contentMap': {
|
'contentMap': {
|
||||||
'en': reply.body_html
|
reply.language_code(): reply.body_html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
create_json = {
|
create_json = {
|
||||||
|
|
42
migrations/versions/e23ce3d53def_post_licence.py
Normal file
42
migrations/versions/e23ce3d53def_post_licence.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
"""post licence
|
||||||
|
|
||||||
|
Revision ID: e23ce3d53def
|
||||||
|
Revises: 7fc066ad475a
|
||||||
|
Create Date: 2024-11-02 15:12:05.885114
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'e23ce3d53def'
|
||||||
|
down_revision = '7fc066ad475a'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('licence',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=50), nullable=True),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
with op.batch_alter_table('post', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('licence_id', sa.Integer(), nullable=True))
|
||||||
|
batch_op.create_index(batch_op.f('ix_post_licence_id'), ['licence_id'], unique=False)
|
||||||
|
batch_op.create_foreign_key(None, 'licence', ['licence_id'], ['id'])
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('post', schema=None) as batch_op:
|
||||||
|
batch_op.drop_constraint(None, type_='foreignkey')
|
||||||
|
batch_op.drop_index(batch_op.f('ix_post_licence_id'))
|
||||||
|
batch_op.drop_column('licence_id')
|
||||||
|
|
||||||
|
op.drop_table('licence')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Add table
Reference in a new issue