deleted_by field on Post, PostReply and User

This commit is contained in:
rimu 2024-10-14 12:29:56 +13:00
parent f2af615d02
commit 377d07a67e
2 changed files with 59 additions and 0 deletions

View file

@ -634,6 +634,7 @@ class User(UserMixin, db.Model):
verification_token = db.Column(db.String(16), index=True)
banned = db.Column(db.Boolean, default=False)
deleted = db.Column(db.Boolean, default=False)
deleted_by = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
about = db.Column(db.Text) # markdown
about_html = db.Column(db.Text) # html
keywords = db.Column(db.String(256))
@ -1077,6 +1078,7 @@ class Post(db.Model):
microblog = db.Column(db.Boolean, default=False)
comments_enabled = db.Column(db.Boolean, default=True)
deleted = db.Column(db.Boolean, default=False, index=True)
deleted_by = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
mea_culpa = db.Column(db.Boolean, default=False)
has_embed = db.Column(db.Boolean, default=False)
reply_count = db.Column(db.Integer, default=0)
@ -1352,6 +1354,7 @@ class PostReply(db.Model):
created_at = db.Column(db.DateTime, index=True, default=utcnow)
posted_at = db.Column(db.DateTime, index=True, default=utcnow)
deleted = db.Column(db.Boolean, default=False, index=True)
deleted_by = db.Column(db.Integer, db.ForeignKey('user.id'), index=True)
ip = db.Column(db.String(50))
from_bot = db.Column(db.Boolean, default=False)
up_votes = db.Column(db.Integer, default=0)

View file

@ -0,0 +1,56 @@
"""deleted_by
Revision ID: 7fc066ad475a
Revises: 238d7c60d676
Create Date: 2024-10-14 12:28:51.315599
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7fc066ad475a'
down_revision = '238d7c60d676'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('post', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True))
batch_op.create_index(batch_op.f('ix_post_deleted_by'), ['deleted_by'], unique=False)
batch_op.create_foreign_key(None, 'user', ['deleted_by'], ['id'])
with op.batch_alter_table('post_reply', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True))
batch_op.create_index(batch_op.f('ix_post_reply_deleted_by'), ['deleted_by'], unique=False)
batch_op.create_foreign_key(None, 'user', ['deleted_by'], ['id'])
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('deleted_by', sa.Integer(), nullable=True))
batch_op.create_index(batch_op.f('ix_user_deleted_by'), ['deleted_by'], unique=False)
batch_op.create_foreign_key(None, 'user', ['deleted_by'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_index(batch_op.f('ix_user_deleted_by'))
batch_op.drop_column('deleted_by')
with op.batch_alter_table('post_reply', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='foreignkey')
batch_op.drop_index(batch_op.f('ix_post_reply_deleted_by'))
batch_op.drop_column('deleted_by')
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_deleted_by'))
batch_op.drop_column('deleted_by')
# ### end Alembic commands ###