Skip to content

MySQL support for Mailman

username-removed-262 requested to merge maxking/mailman:mysql2 into master

This merge request adds MySQL database support to Mailman.

I have added a two new Column types for Unicode to handle the constraint in MySQL to specify the length of VARCHAR columns.

 @public
 class SAUnicode(TypeDecorator):
     """Unicode datatype to support fixed length VARCHAR in mysql
 
     This type compiles to VARCHAR(255) in case of mysql and in case of other
     dailects defaults to the Unicode type. This was just created so that I
     don't alter the output of the default Unicode data type and it can still be
     used if needed in the codebase.
     """
     impl = Unicode

The above type compiles to VARCHAR(255) when using Mysql and the default value in other database dailects due to the following two compile directives:

 @compiles(SAUnicode)
 def default_sa_unicode(element, compiler, **kw):
     return compiler.visit_Unicode(element, **kw)
 
 
 @compiles(SAUnicode, 'mysql')
 def compile_sa_unicode(element, compiler, **kw):
     return "VARCHAR(255)"

By default, I changed all the Unicode fields to this column. If any of the fields require length longer than this, I have specified another column type similar to the above which can be used if needed.

 @public
 class SAUnicodeLarge(TypeDecorator):
     """Similar to SAUnicode type, but compiles to VARCHAR(510), double size of
     SAUnicode defined above.
     """
     impl = Unicode

Which compiles to VARCHAR(510) (double length of the SAUnicode column).

Also, there is still a test that I am skipping for MySQL which deals for case-sensitivity of the arguments. The [case-sensityvity support for MySQL is inconsistent][2] and I am not sure how to guarantee that the test passes everytime. See test_create_list_case_folding in mailman/model/tests/test_listmanager.py below.

Another thing to note is the default collate on the MySQL databases required for the tests. I usually always set the collate to utf8_general_ci as latin1(default on most servers) causes some tests to fail with mixed collation error. I don't know very much about collations though. You can change the default collate on a database with:

mysql> ALTER DATABASE mailman DEFAULT COLLATE utf8_unicode_ci;

I have mentioned this in the docs and also the test infrastructure is adjusted to support this default collate on the databases created for the CI. I am using a slightly modified version of the mysql image, you can see it [on Dockerhub][1]. Just a slight modification in the configuration.

This request outdates !51 (closed) . [1]: https://hub.docker.com/r/maxking/mysql/~/dockerfile/ [2]: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#case-sensitivity-and-table-reflection

Merge request reports