Skip to content

Commit

Permalink
Create a custom mysql backend and use it
Browse files Browse the repository at this point in the history
* Add a custom MySQL database backend based on django.db.backends.mysql,
  overriding only the sql_create_table template to add
  ROW_FORMAT=DYNAMIC in all CREATE TABLE statements to support indexes
  larger than 767 characters. This requires also that the MySQL server
  is configured with:
    innodb_file_per_table = 1
    innodb_file_format    = barracuda
    innodb_large_prefix   = 1
  unless it's a recent enough version in which those are the defaults.
* Use the custom MySQL backend instead of the Django's one.

Bug: T167504
Change-Id: Ia83844d7ca3e2c9afd9640d6319e9bca5623deef
  • Loading branch information
volans- committed Jun 1, 2018
1 parent b836e04 commit 6219784
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Empty file added debmonitor/mysql/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions debmonitor/mysql/base.py
@@ -0,0 +1,11 @@
from django.db.backends.mysql import base, schema


class DatabaseSchemaEditor(schema.DatabaseSchemaEditor):
"""Override the default MySQL database schema editor to add ROW_FORMAT=dynamic."""
sql_create_table = "CREATE TABLE %(table)s (%(definition)s) ROW_FORMAT=DYNAMIC"


class DatabaseWrapper(base.DatabaseWrapper):
"""Override the default MySQL database wrapper to use the custom schema editor class."""
SchemaEditorClass = DatabaseSchemaEditor
2 changes: 1 addition & 1 deletion debmonitor/settings/base.py
Expand Up @@ -87,7 +87,7 @@
if DEBMONITOR_CONFIG.get('MYSQL', {}):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'ENGINE': 'debmonitor.mysql',
'NAME': DEBMONITOR_CONFIG['MYSQL']['DB_NAME'],
'USER': DEBMONITOR_CONFIG['MYSQL']['DB_USER'],
'PASSWORD': DEBMONITOR_CONFIG['MYSQL']['DB_PASSWORD'],
Expand Down

0 comments on commit 6219784

Please sign in to comment.