diff --git a/manage.py b/manage.py index f592701f1c..1c83513166 100644 --- a/manage.py +++ b/manage.py @@ -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 + 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__': @@ -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'