Merge pull request #740 from jzelinskie/utf8mb4
Migrate v1_json_metadata & comment to UTF-8
This commit is contained in:
commit
6e518a3333
3 changed files with 21 additions and 19 deletions
|
@ -15,28 +15,13 @@ import sqlalchemy as sa
|
||||||
|
|
||||||
from sqlalchemy.types import TypeDecorator, Text
|
from sqlalchemy.types import TypeDecorator, Text
|
||||||
from sqlalchemy.dialects.mysql import LONGTEXT
|
from sqlalchemy.dialects.mysql import LONGTEXT
|
||||||
import uuid
|
|
||||||
|
|
||||||
class EngineLongText(TypeDecorator):
|
from util.migrate import UTF8LongText
|
||||||
"""Platform-independent LongText type.
|
|
||||||
|
|
||||||
Uses MySQL's LONGTEXT type, otherwise uses
|
|
||||||
Text, because other engines are not as limited
|
|
||||||
as MySQL.
|
|
||||||
|
|
||||||
"""
|
|
||||||
impl = Text
|
|
||||||
|
|
||||||
def load_dialect_impl(self, dialect):
|
|
||||||
if dialect.name == 'mysql':
|
|
||||||
return dialect.type_descriptor(LONGTEXT())
|
|
||||||
else:
|
|
||||||
return dialect.type_descriptor(Text())
|
|
||||||
|
|
||||||
def upgrade(tables):
|
def upgrade(tables):
|
||||||
### commands auto generated by Alembic - please adjust! ###
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
op.drop_column(u'tagmanifest', 'json_data')
|
op.drop_column(u'tagmanifest', 'json_data')
|
||||||
op.add_column(u'tagmanifest', sa.Column('json_data', EngineLongText(), nullable=False))
|
op.add_column(u'tagmanifest', sa.Column('json_data', UTF8LongText(), nullable=False))
|
||||||
### end Alembic commands ###
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,15 @@ down_revision = '3a3bb77e17d5'
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
from util.migrate import UTF8LongText
|
||||||
|
|
||||||
def upgrade(tables):
|
def upgrade(tables):
|
||||||
### commands auto generated by Alembic - please adjust! ###
|
### commands auto generated by Alembic - please adjust! ###
|
||||||
op.add_column('image', sa.Column('aggregate_size', sa.BigInteger(), nullable=True))
|
op.add_column('image', sa.Column('aggregate_size', sa.BigInteger(), nullable=True))
|
||||||
op.add_column('image', sa.Column('command', sa.Text(), nullable=True))
|
op.add_column('image', sa.Column('command', sa.Text(), nullable=True))
|
||||||
op.add_column('image', sa.Column('comment', sa.Text(), nullable=True))
|
op.add_column('image', sa.Column('comment', UTF8LongText(), nullable=True))
|
||||||
op.add_column('image', sa.Column('created', sa.DateTime(), nullable=True))
|
op.add_column('image', sa.Column('created', sa.DateTime(), nullable=True))
|
||||||
op.add_column('image', sa.Column('v1_json_metadata', sa.Text(), nullable=True))
|
op.add_column('image', sa.Column('v1_json_metadata', UTF8LongText(), nullable=True))
|
||||||
### end Alembic commands ###
|
### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
from sqlalchemy.types import TypeDecorator, Text
|
||||||
|
from sqlalchemy.dialects.mysql import TEXT as MySQLText, LONGTEXT
|
||||||
|
|
||||||
|
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())
|
Reference in a new issue