Fix LargeBinary column type for mysql

Currently sqlalchemy has a bug with mysql and LargeBinary type
fails to create LongBlob and creates Blob instead [1].

As a workaround it's recommended to explicitly specify column
type and size for mysql deployments [2].

[1] https://bitbucket.org/zzzeek/sqlalchemy/issues/3883/largebinary-type-fails-to-create-longblob
[2] https://stackoverflow.com/questions/43791725/sqlalchemy-how-to-make-a-longblob-column-in-mysql

Change-Id: I921a5ae86ced07ac0a04ba7e5dafcea07afebdb0
This commit is contained in:
Mike Fedosin 2017-06-19 17:20:32 +03:00
parent d9915469ab
commit 2d4e597ae4
2 changed files with 9 additions and 2 deletions

View File

@ -27,6 +27,7 @@ down_revision = '002'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
MYSQL_ENGINE = 'InnoDB'
MYSQL_CHARSET = 'utf8'
@ -36,7 +37,13 @@ def upgrade():
op.create_table(
'glare_blob_data',
sa.Column('id', sa.String(255), primary_key=True, nullable=False),
sa.Column('data', sa.LargeBinary(), nullable=False),
# Because of strange behavior of mysql LargeBinary is converted to
# BLOB instead of LONGBLOB. So we have to fix it explicitly with
# 'with_variant' call.
sa.Column(
'data',
sa.LargeBinary().with_variant(mysql.LONGBLOB(), 'mysql'),
nullable=False),
sa.PrimaryKeyConstraint('id'),
mysql_engine=MYSQL_ENGINE,
mysql_charset=MYSQL_CHARSET

View File

@ -252,7 +252,7 @@ class ArtifactBlobData(BASE, ArtifactBase):
__table_args__ = (
{'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'},)
id = Column(String(255), primary_key=True, nullable=False)
data = Column(LargeBinary, nullable=False)
data = Column(LargeBinary(length=(2 ** 32) - 1), nullable=False)
def register_models(engine):