Skip to content

Commit

Permalink
patch with django 1.10 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
artragis committed Jul 24, 2017
1 parent 5104190 commit 57b9b01
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,19 @@
import sys


def patch_mysql_sql_create_model(original):
def patch_create_suffix(original):
"""
Inspired by github.com/miyagi389/zipcode-django-python - The MIT License - Copyright (c) 2014 miyagi389
Patch mysql creation policy to handle the "utf8mb4" facility. This appears tricky but it's necessary
due to the conception of "extended utf-8" in mysql. If we do not patch, the mysql backend is not even run !
see <http://bd808.com/blog/2017/04/17/making-django-migrations-that-work-with-mysql-55-and-utf8mb4/>
for explanations
:param :class:`django.db.backends.creation.BaseDatabaseCreation` original: BaseDatabaseCreation
:return: BaseDatabaseCreation
:rtype: :class:`django.db.backends.creation.BaseDatabaseCreation`
:param original: the original function we are patching
:return: the patched function
"""


def revised(self, model, style, known_models=set()):
"""
:class:`django.db.backends.creation.BaseDatabaseCreation`
"""
fullname = self.__module__ + '.' + self.__class__.__name__

if fullname == 'django.db.backends.mysql.creation.DatabaseCreation':
# the migration will run MySQL
sql_statements, pending_references = original(self, model, style, known_models)
final_output = []

for statement in sql_statements:
if not statement.startswith('CREATE TABLE'):
continue
end = ''
if statement.endswith(';'):
end = ';'
statement = statement[:-1]
statement += 'ROW_FORMAT=DYNAMIC{}'.format(end)

final_output.append(statement)
return final_output, pending_references
else:
return original(self, model, style, known_models)
return revised
def patch(self):
return original(self) + 'ROW_FORMAT=DYNAMIC'
return patch


if __name__ == '__main__':
Expand All @@ -45,7 +23,9 @@ def revised(self, model, style, known_models=set()):
if len(sys.argv) > 1 and sys.argv[1] in ['migrate', 'test']:

from django.db.backends.mysql.creation import BaseDatabaseCreation
BaseDatabaseCreation.sql_create_model = patch_mysql_sql_create_model(BaseDatabaseCreation.sql_create_model)

BaseDatabaseCreation.sql_table_creation_suffix = \
patch_create_suffix(BaseDatabaseCreation.sql_table_creation_suffix)
from django.db.backends.mysql.schema import DatabaseSchemaEditor

DatabaseSchemaEditor.sql_create_table += ' ROW_FORMAT=DYNAMIC'
Expand Down

0 comments on commit 57b9b01

Please sign in to comment.