summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-01-17 10:48:39 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-01-17 10:48:39 -0500
commita0de2bfa1044db5fa894fdbab5b15d5add2ca0d0 (patch)
treecb48adc92e1700cda07b66ad240e57597d4595cd
parent00b24eb0f4759abcca518dd1683c3aa50abc4c1d (diff)
parent99d65925e6aebaea25a0a9f2fc7fa0217974fa7f (diff)
downloadsqlalchemy-a0de2bfa1044db5fa894fdbab5b15d5add2ca0d0.tar.gz
Merge branch 'master' into rel_1_1
-rw-r--r--doc/build/changelog/changelog_11.rst16
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py25
-rw-r--r--lib/sqlalchemy/dialects/mysql/reflection.py1
-rw-r--r--test/dialect/mysql/test_compiler.py8
-rw-r--r--test/dialect/mysql/test_reflection.py12
5 files changed, 62 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index ead292570..619eb00ab 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -21,6 +21,13 @@
.. changelog::
:version: 1.1.5
+ .. change:: mysql_index_prefix
+ :tags: feature, 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:: 3854
:tags: bug, orm
:tickets: 3854
@@ -139,6 +146,15 @@
:class:`.Engine`, concealing the URL password. Pull request courtesy
Valery Yundin.
+ .. change:: 3867
+ :tags: bug, mysql
+ :tickets: 3867
+
+ The MySQL dialect now will not warn when a reflected column has a
+ "COMMENT" keyword on it, but note however the comment is not yet
+ reflected; this is on the roadmap for a future release. Pull request
+ courtesy Lele Long.
+
.. change:: pg_timestamp_zero_prec
:tags: bug, postgresql
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,
})
]
diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py
index d020fb296..f5f09b80b 100644
--- a/lib/sqlalchemy/dialects/mysql/reflection.py
+++ b/lib/sqlalchemy/dialects/mysql/reflection.py
@@ -359,6 +359,7 @@ class MySQLTableDefinitionParser(object):
r'(?: +USING +(?P<using_post>\S+))?'
r'(?: +KEY_BLOCK_SIZE *[ =]? *(?P<keyblock>\S+))?'
r'(?: +WITH PARSER +(?P<parser>\S+))?'
+ r'(?: +COMMENT +(?P<comment>(\x27\x27|\x27([^\x27])*?\x27)+))?'
r',?$'
% quotes
)
diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py
index 88f9235e1..b72507104 100644
--- a/test/dialect/mysql/test_compiler.py
+++ b/test/dialect/mysql/test_compiler.py
@@ -40,6 +40,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(schema.CreateIndex(idx),
'CREATE INDEX test_idx1 ON testtbl (data)')
+ def test_create_index_with_prefix(self):
+ m = MetaData()
+ tbl = Table('testtbl', m, Column('data', String(255)))
+ idx = Index('test_idx1', tbl.c.data, mysql_length=10, mysql_prefix='FULLTEXT')
+
+ self.assert_compile(schema.CreateIndex(idx),
+ 'CREATE FULLTEXT INDEX test_idx1 ON testtbl (data(10))')
+
def test_create_index_with_length(self):
m = MetaData()
tbl = Table('testtbl', m, Column('data', String(255)))
diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py
index ddf158167..2ccb299bc 100644
--- a/test/dialect/mysql/test_reflection.py
+++ b/test/dialect/mysql/test_reflection.py
@@ -552,6 +552,18 @@ class RawReflectionTest(fixtures.TestBase):
' PRIMARY KEY (`id`) USING BTREE KEY_BLOCK_SIZE = 16')
assert not regex.match(
' PRIMARY KEY (`id`) USING BTREE KEY_BLOCK_SIZE = = 16')
+ assert regex.match(
+ " KEY (`id`) USING BTREE COMMENT 'comment'")
+ # `SHOW CREATE TABLE` returns COMMENT '''comment'
+ # after creating table with COMMENT '\'comment'
+ assert regex.match(
+ " KEY (`id`) USING BTREE COMMENT '''comment'")
+ assert regex.match(
+ " KEY (`id`) USING BTREE COMMENT 'comment'''")
+ assert regex.match(
+ " KEY (`id`) USING BTREE COMMENT 'prefix''suffix'")
+ assert regex.match(
+ " KEY (`id`) USING BTREE COMMENT 'prefix''text''suffix'")
def test_fk_reflection(self):
regex = self.parser._re_constraint