From d5b8a3a2ae4cab43230906cdc50869485218146a Mon Sep 17 00:00:00 2001 From: nyaadev Date: Mon, 14 Aug 2017 19:08:36 +0200 Subject: [PATCH] Increase maximum comment size from 255 to 1024. DB change: Change comment text field from VARCHAR(255) to mysql.TEXT --- .../versions/b79d2fcafd88_comment_text.py | 33 +++++++++++++++++++ nyaa/forms.py | 2 +- nyaa/models.py | 8 ++--- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 migrations/versions/b79d2fcafd88_comment_text.py diff --git a/migrations/versions/b79d2fcafd88_comment_text.py b/migrations/versions/b79d2fcafd88_comment_text.py new file mode 100644 index 0000000..ec582ab --- /dev/null +++ b/migrations/versions/b79d2fcafd88_comment_text.py @@ -0,0 +1,33 @@ +"""Change comment text field from VARCHAR(255) to mysql.TEXT + +Revision ID: b79d2fcafd88 +Revises: ffd23e570f92 +Create Date: 2017-08-14 18:57:44.165168 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +# revision identifiers, used by Alembic. +revision = 'b79d2fcafd88' +down_revision = 'ffd23e570f92' +branch_labels = None +depends_on = None + +TABLE_PREFIXES = ('nyaa', 'sukebei') + +def upgrade(): + for prefix in TABLE_PREFIXES: + op.alter_column(prefix + '_comments', 'text', + existing_type=mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_bin', length=255), + type_=mysql.TEXT(collation='utf8mb4_bin'), + existing_nullable=False) + + +def downgrade(): + for prefix in TABLE_PREFIXES: + op.alter_column(prefix + '_comments', 'text', + existing_type=mysql.TEXT(collation='utf8mb4_bin'), + type_=mysql.VARCHAR(charset='utf8mb4', collation='utf8mb4_bin', length=255), + existing_nullable=False) diff --git a/nyaa/forms.py b/nyaa/forms.py index 879dbd8..bf0b2cf 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -142,7 +142,7 @@ class DisabledSelectField(SelectField): class CommentForm(FlaskForm): comment = TextAreaField('Make a comment', [ - Length(min=3, max=255, message='Comment must be at least %(min)d characters ' + Length(min=3, max=1024, message='Comment must be at least %(min)d characters ' 'long and %(max)d at most.'), DataRequired() ]) diff --git a/nyaa/models.py b/nyaa/models.py index bd14aed..c2afe8d 100644 --- a/nyaa/models.py +++ b/nyaa/models.py @@ -23,14 +23,14 @@ app = flask.current_app if config['USE_MYSQL']: from sqlalchemy.dialects import mysql BinaryType = mysql.BINARY - DescriptionTextType = mysql.TEXT + TextType = mysql.TEXT MediumBlobType = mysql.MEDIUMBLOB COL_UTF8_GENERAL_CI = 'utf8_general_ci' COL_UTF8MB4_BIN = 'utf8mb4_bin' COL_ASCII_GENERAL_CI = 'ascii_general_ci' else: BinaryType = db.Binary - DescriptionTextType = db.String + TextType = db.String MediumBlobType = db.BLOB COL_UTF8_GENERAL_CI = 'NOCASE' COL_UTF8MB4_BIN = None @@ -110,7 +110,7 @@ class TorrentBase(DeclarativeHelperBase): nullable=False, index=True) torrent_name = db.Column(db.String(length=255), nullable=False) information = db.Column(db.String(length=255), nullable=False) - description = db.Column(DescriptionTextType(collation=COL_UTF8MB4_BIN), nullable=False) + description = db.Column(TextType(collation=COL_UTF8MB4_BIN), nullable=False) filesize = db.Column(db.BIGINT, default=0, nullable=False, index=True) encoding = db.Column(db.String(length=32), nullable=False) @@ -433,7 +433,7 @@ class CommentBase(DeclarativeHelperBase): return db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE')) created_time = db.Column(db.DateTime(timezone=False), default=datetime.utcnow) - text = db.Column(db.String(length=255, collation=COL_UTF8MB4_BIN), nullable=False) + text = db.Column(TextType(collation=COL_UTF8MB4_BIN), nullable=False) @declarative.declared_attr def user(cls):