From 16996e3a204b194f2c0f4dc50ed114176b4093c6 Mon Sep 17 00:00:00 2001 From: freamon Date: Sun, 31 Mar 2024 02:15:10 +0100 Subject: [PATCH] Upgrade DB for cross_posts field --- app/models.py | 3 ++ .../versions/08b3f718df5d_cross_posts.py | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 migrations/versions/08b3f718df5d_cross_posts.py diff --git a/app/models.py b/app/models.py index d3b44a99..f6100f15 100644 --- a/app/models.py +++ b/app/models.py @@ -10,6 +10,8 @@ from werkzeug.security import generate_password_hash, check_password_hash from flask_babel import _, lazy_gettext as _l from sqlalchemy.orm import backref from sqlalchemy_utils.types import TSVectorType # https://sqlalchemy-searchable.readthedocs.io/en/latest/installation.html +from sqlalchemy.dialects.postgresql import ARRAY +from sqlalchemy.ext.mutable import MutableList from flask_sqlalchemy import BaseQuery from sqlalchemy_searchable import SearchQueryMixin from app import db, login, cache, celery @@ -869,6 +871,7 @@ class Post(db.Model): language = db.Column(db.String(10)) edited_at = db.Column(db.DateTime) reports = db.Column(db.Integer, default=0) # how many times this post has been reported. Set to -1 to ignore reports + cross_posts = db.Column(MutableList.as_mutable(ARRAY(db.Integer))) ap_id = db.Column(db.String(255), index=True) ap_create_id = db.Column(db.String(100)) diff --git a/migrations/versions/08b3f718df5d_cross_posts.py b/migrations/versions/08b3f718df5d_cross_posts.py new file mode 100644 index 00000000..4da16409 --- /dev/null +++ b/migrations/versions/08b3f718df5d_cross_posts.py @@ -0,0 +1,32 @@ +"""cross posts + +Revision ID: 08b3f718df5d +Revises: 04697ae91fac +Create Date: 2024-03-31 02:10:19.726154 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '08b3f718df5d' +down_revision = '04697ae91fac' +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('cross_posts', postgresql.ARRAY(sa.Integer()), nullable=True)) + + # ### 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_column('cross_posts') + + # ### end Alembic commands ###