For utf8mb4 shorten teams.name and users.email
Because the InnoDB default max key length is 767 bytes in MySQL 2.5 and 2.6, switch teams.name and users.email columns from top_large_length (255 characters) to top_middle_length (100 characters). These are probably still sane lengths for these fields and gets them below the 767/4=191 mark so that we can continue to set them unique under utf8mb4. Also, set the default database-wide character set to utf8mb4 so that any new tables will inherit this. While modifying a migration is generally taboo, this was the last to merge and couldn't have applied successfully in production without this modification anyway. Change-Id: I6a571ac78f917866c14f541283e2bc0738ecf4c9
This commit is contained in:
parent
2764f43344
commit
27b208b8a6
@ -11,7 +11,7 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""convert to charset utf8mb4
|
||||
"""convert to charset utf8mb4 shortening teams.name and users.email
|
||||
|
||||
Revision ID: 062
|
||||
Revises: 061
|
||||
@ -25,20 +25,28 @@ down_revision = '061'
|
||||
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade(active_plugins=None, options=None):
|
||||
dialect = op.get_bind().engine.dialect
|
||||
if dialect.name == 'mysql' and dialect.supports_alter:
|
||||
for table in inspect(op.get_bind()).get_table_names():
|
||||
op.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8mb4' %
|
||||
table)
|
||||
if dialect.supports_alter:
|
||||
op.alter_column('teams', 'name', type_=sa.Unicode(100))
|
||||
op.alter_column('users', 'email', type_=sa.String(100))
|
||||
if dialect.name == 'mysql':
|
||||
op.execute('ALTER DATABASE CHARACTER SET utf8mb4')
|
||||
for table in sa.inspect(op.get_bind()).get_table_names():
|
||||
op.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8mb4' %
|
||||
table)
|
||||
|
||||
|
||||
def downgrade(active_plugins=None, options=None):
|
||||
dialect = op.get_bind().engine.dialect
|
||||
if dialect.name == 'mysql' and dialect.supports_alter:
|
||||
for table in inspect(op.get_bind()).get_table_names():
|
||||
op.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8' %
|
||||
table)
|
||||
if dialect.supports_alter:
|
||||
op.alter_column('teams', 'name', type_=sa.Unicode(255))
|
||||
op.alter_column('users', 'email', type_=sa.String(255))
|
||||
if dialect.name == 'mysql':
|
||||
op.execute('ALTER DATABASE CHARACTER SET utf8')
|
||||
for table in sa.inspect(op.get_bind()).get_table_names():
|
||||
op.execute('ALTER TABLE %s CONVERT TO CHARACTER SET utf8' %
|
||||
table)
|
||||
|
@ -145,7 +145,7 @@ class User(FullText, ModelBuilder, Base):
|
||||
__fulltext_columns__ = ['full_name', 'email']
|
||||
|
||||
full_name = Column(Unicode(CommonLength.top_large_length), nullable=True)
|
||||
email = Column(String(CommonLength.top_large_length))
|
||||
email = Column(String(CommonLength.top_middle_length))
|
||||
openid = Column(String(CommonLength.top_large_length))
|
||||
is_staff = Column(Boolean, default=False)
|
||||
is_active = Column(Boolean, default=True)
|
||||
@ -210,7 +210,7 @@ class Team(ModelBuilder, Base):
|
||||
__table_args__ = (
|
||||
schema.UniqueConstraint('name', name='uniq_team_name'),
|
||||
)
|
||||
name = Column(Unicode(CommonLength.top_large_length))
|
||||
name = Column(Unicode(CommonLength.top_middle_length))
|
||||
users = relationship("User", secondary="team_membership")
|
||||
permissions = relationship("Permission", secondary="team_permissions",
|
||||
backref="teams")
|
||||
|
Loading…
x
Reference in New Issue
Block a user