dc24e8b1a1
Fixes #826
22 lines
639 B
Python
22 lines
639 B
Python
import logging
|
|
|
|
from sqlalchemy.types import TypeDecorator, Text
|
|
from sqlalchemy.dialects.mysql import TEXT as MySQLText, LONGTEXT
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class UTF8LongText(TypeDecorator):
|
|
""" Platform-independent UTF-8 LONGTEXT type.
|
|
|
|
Uses MySQL's LongText with charset utf8mb4, otherwise uses TEXT, because
|
|
other engines default to UTF-8 and have longer TEXT fields.
|
|
"""
|
|
impl = Text
|
|
|
|
def load_dialect_impl(self, dialect):
|
|
if dialect.name == 'mysql':
|
|
return dialect.type_descriptor(LONGTEXT(charset='utf8mb4', collation='utf8mb4_unicode_ci'))
|
|
else:
|
|
return dialect.type_descriptor(Text())
|