summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
authorJoseph Schorr <josephschorr@users.noreply.github.com>2017-01-17 10:02:17 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-01-17 10:21:47 -0500
commit1f407c2a47150ddd550d3167015a9315e018d7bc (patch)
treec6ed3a906b9e7d0a0e52afd2aa586ab71c737639 /lib/sqlalchemy/dialects/mysql/base.py
parent46828cc157a48d73352a3a910798b705aa23f0d5 (diff)
downloadsqlalchemy-1f407c2a47150ddd550d3167015a9315e018d7bc.tar.gz
Add support for prefixes on CREATE INDEX statements in MySQL
Added a new parameter ``mysql_prefix`` supported by the :class:`.Index` construct, allows specification of MySQL-specific prefixes such as "FULLTEXT". Pull request courtesy Joseph Schorr. Change-Id: I5a21fa466fdfd4d9e39e1fb4ecec1eab93b92c36 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/339
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 1654ff327..8b0d00a63 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -391,6 +391,25 @@ BLOB.
.. versionadded:: 0.8.2 ``mysql_length`` may now be specified as a dictionary
for use with composite indexes.
+Index Prefixes
+~~~~~~~~~~~~~~
+
+MySQL storage engines permit you to specify an index prefix when creating
+an index. SQLAlchemy provides this feature via the
+``mysql_prefix`` parameter on :class:`.Index`::
+
+ Index('my_index', my_table.c.data, mysql_prefix='FULLTEXT')
+
+The value passed to the keyword argument will be simply passed through to the
+underlying CREATE INDEX, so it *must* be a valid index prefix for your MySQL
+storage engine.
+
+.. versionadded:: 1.1.5
+
+.. seealso::
+
+ `CREATE INDEX <http://dev.mysql.com/doc/refman/5.0/en/create-index.html>`_ - MySQL documentation
+
Index Types
~~~~~~~~~~~~~
@@ -1039,6 +1058,11 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
text = "CREATE "
if index.unique:
text += "UNIQUE "
+
+ index_prefix = index.kwargs.get('mysql_prefix', None)
+ if index_prefix:
+ text += index_prefix + ' '
+
text += "INDEX %s ON %s " % (name, table)
length = index.dialect_options['mysql']['length']
@@ -1468,6 +1492,7 @@ class MySQLDialect(default.DefaultDialect):
(sa_schema.Index, {
"using": None,
"length": None,
+ "prefix": None,
})
]