1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:19:59 +00:00

Increase maximum comment size from 255 to 1024.

DB change: Change comment text field from VARCHAR(255) to mysql.TEXT
This commit is contained in:
nyaadev 2017-08-14 19:08:36 +02:00
parent 1c3724cae1
commit d5b8a3a2ae
3 changed files with 38 additions and 5 deletions

View file

@ -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)

View file

@ -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()
])

View file

@ -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):