]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes MySQL dialect partitioning
authorMarcus McCurdy <mmccurdy@50onred.com>
Fri, 14 Feb 2014 18:23:51 +0000 (13:23 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 19 Feb 2014 20:27:24 +0000 (15:27 -0500)
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_compiler.py

index 14b8c99a88d0eb06baf45e09284b27797c6cf795..654ffbd8574c7c853329f65ec17d0b07f3e6a7ef 100644 (file)
@@ -1588,12 +1588,12 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
             if opt in ('DATA_DIRECTORY', 'INDEX_DIRECTORY',
                        'DEFAULT_CHARACTER_SET', 'CHARACTER_SET',
                        'DEFAULT_CHARSET',
-                       'DEFAULT_COLLATE'):
+                       'DEFAULT_COLLATE', 'PARTITION_BY'):
                 opt = opt.replace('_', ' ')
 
             joiner = '='
             if opt in ('TABLESPACE', 'DEFAULT CHARACTER SET',
-                       'CHARACTER SET', 'COLLATE'):
+                       'CHARACTER SET', 'COLLATE', 'PARTITION BY', 'PARTITIONS'):
                 joiner = ' '
 
             table_opts.append(joiner.join((opt, arg)))
index 8a242df824c5f18033a9c7d45c7dc28b29867e79..d479e21486ddf4beeb764722eff98d37397cf76d 100644 (file)
@@ -493,3 +493,33 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
             'KEY idx_autoinc_order (`order`)'
             ')ENGINE=InnoDB')
 
+    def test_create_table_with_partition(self):
+        t1 = Table(
+            'testtable', MetaData(),
+            Column('id', Integer(), primary_key=True, autoincrement=True),
+            Column('other_id', Integer(), primary_key=True, autoincrement=False),
+            mysql_partitions='2', mysql_partition_by='KEY(other_id)')
+        self.assert_compile(
+            schema.CreateTable(t1),
+            'CREATE TABLE testtable ('
+            'id INTEGER NOT NULL AUTO_INCREMENT, '
+            'other_id INTEGER NOT NULL, '
+            'PRIMARY KEY (id, other_id)'
+            ')PARTITION BY KEY(other_id) PARTITIONS 2'
+        )
+
+    def test_create_table_with_partition_hash(self):
+        t1 = Table(
+            'testtable', MetaData(),
+            Column('id', Integer(), primary_key=True, autoincrement=True),
+            Column('other_id', Integer(), primary_key=True, autoincrement=False),
+            mysql_partitions='2', mysql_partition_by='HASH(other_id)')
+        self.assert_compile(
+            schema.CreateTable(t1),
+            'CREATE TABLE testtable ('
+            'id INTEGER NOT NULL AUTO_INCREMENT, '
+            'other_id INTEGER NOT NULL, '
+            'PRIMARY KEY (id, other_id)'
+            ')PARTITION BY HASH(other_id) PARTITIONS 2'
+        )
+