Merge "For utf8mb4 shorten teams.name and users.email"

This commit is contained in:
Zuul 2018-03-30 15:38:57 +00:00 committed by Gerrit Code Review
commit 9b1464ad33
2 changed files with 20 additions and 12 deletions

View File

@ -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)

View File

@ -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")