From dd836c65326a0cb209d5c9895d3ba8a280358ef3 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 6 Jul 2024 14:50:49 +0800 Subject: [PATCH] Mod log migration #21 --- app/models.py | 14 +++++ migrations/versions/ea5a07acf23c_mod_log.py | 59 +++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 migrations/versions/ea5a07acf23c_mod_log.py diff --git a/app/models.py b/app/models.py index 5fc77836..cb593d67 100644 --- a/app/models.py +++ b/app/models.py @@ -1465,6 +1465,19 @@ class PostReplyBookmark(db.Model): created_at = db.Column(db.DateTime, default=utcnow) +class ModLog(db.Model): + id = db.Column(db.Integer, primary_key=True) + user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) + community_id = db.Column(db.Integer, db.ForeignKey('community.id'), index=True) + type = db.Column(db.String(10)) # 'mod' or 'admin' + action = db.Column(db.String(30)) # 'removing post', 'banning from community', etc + reason = db.Column(db.String(512)) + link = db.Column(db.String(512)) + link_text = db.Column(db.String(512)) + public = db.Column(db.Boolean, default=False) + created_at = db.Column(db.DateTime, default=utcnow) + + class IpBan(db.Model): id = db.Column(db.Integer, primary_key=True) ip_address = db.Column(db.String(50), index=True) @@ -1506,6 +1519,7 @@ class Site(db.Model): logo_152 = db.Column(db.String(40), default='') logo_32 = db.Column(db.String(40), default='') logo_16 = db.Column(db.String(40), default='') + show_inoculation_block = db.Column(db.Boolean, default=True) @staticmethod def admins() -> List[User]: diff --git a/migrations/versions/ea5a07acf23c_mod_log.py b/migrations/versions/ea5a07acf23c_mod_log.py new file mode 100644 index 00000000..29835c24 --- /dev/null +++ b/migrations/versions/ea5a07acf23c_mod_log.py @@ -0,0 +1,59 @@ +"""mod log + +Revision ID: ea5a07acf23c +Revises: 5bee0ac7d99f +Create Date: 2024-07-06 14:47:40.409922 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ea5a07acf23c' +down_revision = '5bee0ac7d99f' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('mod_log', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('user_id', sa.Integer(), nullable=True), + sa.Column('community_id', sa.Integer(), nullable=True), + sa.Column('type', sa.String(length=10), nullable=True), + sa.Column('action', sa.String(length=30), nullable=True), + sa.Column('reason', sa.String(length=512), nullable=True), + sa.Column('link', sa.String(length=512), nullable=True), + sa.Column('link_text', sa.String(length=512), nullable=True), + sa.Column('public', sa.Boolean(), nullable=True), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.ForeignKeyConstraint(['community_id'], ['community.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('mod_log', schema=None) as batch_op: + batch_op.create_index(batch_op.f('ix_mod_log_community_id'), ['community_id'], unique=False) + batch_op.create_index(batch_op.f('ix_mod_log_user_id'), ['user_id'], unique=False) + + with op.batch_alter_table('site', schema=None) as batch_op: + batch_op.add_column(sa.Column('show_inoculation_block', sa.Boolean(), nullable=True)) + + # ### end Alembic commands ### + + op.execute(sa.DDL('UPDATE "site" SET show_inoculation_block = true')) + + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('site', schema=None) as batch_op: + batch_op.drop_column('show_inoculation_block') + + with op.batch_alter_table('mod_log', schema=None) as batch_op: + batch_op.drop_index(batch_op.f('ix_mod_log_user_id')) + batch_op.drop_index(batch_op.f('ix_mod_log_community_id')) + + op.drop_table('mod_log') + # ### end Alembic commands ###