mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 09:10:00 +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:
parent
1c3724cae1
commit
d5b8a3a2ae
33
migrations/versions/b79d2fcafd88_comment_text.py
Normal file
33
migrations/versions/b79d2fcafd88_comment_text.py
Normal 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)
|
|
@ -142,7 +142,7 @@ class DisabledSelectField(SelectField):
|
||||||
|
|
||||||
class CommentForm(FlaskForm):
|
class CommentForm(FlaskForm):
|
||||||
comment = TextAreaField('Make a comment', [
|
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.'),
|
'long and %(max)d at most.'),
|
||||||
DataRequired()
|
DataRequired()
|
||||||
])
|
])
|
||||||
|
|
|
@ -23,14 +23,14 @@ app = flask.current_app
|
||||||
if config['USE_MYSQL']:
|
if config['USE_MYSQL']:
|
||||||
from sqlalchemy.dialects import mysql
|
from sqlalchemy.dialects import mysql
|
||||||
BinaryType = mysql.BINARY
|
BinaryType = mysql.BINARY
|
||||||
DescriptionTextType = mysql.TEXT
|
TextType = mysql.TEXT
|
||||||
MediumBlobType = mysql.MEDIUMBLOB
|
MediumBlobType = mysql.MEDIUMBLOB
|
||||||
COL_UTF8_GENERAL_CI = 'utf8_general_ci'
|
COL_UTF8_GENERAL_CI = 'utf8_general_ci'
|
||||||
COL_UTF8MB4_BIN = 'utf8mb4_bin'
|
COL_UTF8MB4_BIN = 'utf8mb4_bin'
|
||||||
COL_ASCII_GENERAL_CI = 'ascii_general_ci'
|
COL_ASCII_GENERAL_CI = 'ascii_general_ci'
|
||||||
else:
|
else:
|
||||||
BinaryType = db.Binary
|
BinaryType = db.Binary
|
||||||
DescriptionTextType = db.String
|
TextType = db.String
|
||||||
MediumBlobType = db.BLOB
|
MediumBlobType = db.BLOB
|
||||||
COL_UTF8_GENERAL_CI = 'NOCASE'
|
COL_UTF8_GENERAL_CI = 'NOCASE'
|
||||||
COL_UTF8MB4_BIN = None
|
COL_UTF8MB4_BIN = None
|
||||||
|
@ -110,7 +110,7 @@ class TorrentBase(DeclarativeHelperBase):
|
||||||
nullable=False, index=True)
|
nullable=False, index=True)
|
||||||
torrent_name = db.Column(db.String(length=255), nullable=False)
|
torrent_name = db.Column(db.String(length=255), nullable=False)
|
||||||
information = 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)
|
filesize = db.Column(db.BIGINT, default=0, nullable=False, index=True)
|
||||||
encoding = db.Column(db.String(length=32), nullable=False)
|
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'))
|
return db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'))
|
||||||
|
|
||||||
created_time = db.Column(db.DateTime(timezone=False), default=datetime.utcnow)
|
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
|
@declarative.declared_attr
|
||||||
def user(cls):
|
def user(cls):
|
||||||
|
|
Loading…
Reference in a new issue