From 377d07a67e35977ecd60945b5b6c8d817b150612 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:29:56 +1300 Subject: [PATCH] deleted_by field on Post, PostReply and User --- app/models.py | 3 + .../versions/7fc066ad475a_deleted_by.py | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 migrations/versions/7fc066ad475a_deleted_by.py diff --git a/app/models.py b/app/models.py index 0a6dbf4c..0e649eb0 100644 --- a/app/models.py +++ b/app/models.py @@ -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) diff --git a/migrations/versions/7fc066ad475a_deleted_by.py b/migrations/versions/7fc066ad475a_deleted_by.py new file mode 100644 index 00000000..e50d4c34 --- /dev/null +++ b/migrations/versions/7fc066ad475a_deleted_by.py @@ -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 ###