From 2c64cee9f3a145e9d4ca62a3f5e6e7f9cc1495dd Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Wed, 28 Mar 2018 19:55:39 +0000 Subject: [PATCH] Use charset=utf8mb4 in pymysql DBURIs To make full use of the new 4-byte character set in columns for MySQL, connections to the database need to also specify charset=utf8mb4. The easiest way to do that is by tacking it on as a variable in the DBURI string. Do this both in the test migration script and in the documented sample and test configs. Change-Id: Icf5f74543f6d062cafe2166d384f37f46394e964 --- doc/source/install/development.rst | 2 +- etc/storyboard.conf.sample | 2 +- etc/storyboard.conf.test | 2 +- storyboard/tests/base.py | 9 ++++----- storyboard/tests/db/migration/test_migrations.conf | 4 ++-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/doc/source/install/development.rst b/doc/source/install/development.rst index 8ea1cdf2..e0978148 100644 --- a/doc/source/install/development.rst +++ b/doc/source/install/development.rst @@ -69,7 +69,7 @@ Installing and Upgrading the API server 5. Edit ``./etc/storyboard.conf`` and in the ``oauth`` section, add your IP Adress to the list of ``valid_oauth_clients``. Then in the ``database`` section, on the line which reads - ``# connection = mysql+pymysql://root:pass@127.0.0.1:3306/storyboard``, + ``# connection = mysql+pymysql://root:pass@127.0.0.1:3306/storyboard?charset=utf8mb4``, replace the ``pass`` with your password (the same as used in the above steps). On both of these lines you will need to remove the ``#``. diff --git a/etc/storyboard.conf.sample b/etc/storyboard.conf.sample index eb2c149b..f0f2453c 100644 --- a/etc/storyboard.conf.sample +++ b/etc/storyboard.conf.sample @@ -116,7 +116,7 @@ lock_path = $state_path/lock [database] # This line MUST be changed to actually run storyboard # Example: -# connection = mysql+pymysql://root:pass@127.0.0.1:3306/storyboard +# connection = mysql+pymysql://root:pass@127.0.0.1:3306/storyboard?charset=utf8mb4 # Replace 127.0.0.1 above with the IP address of the database used by the # main storyboard server. (Leave it as is if the database runs on this host.) # connection=sqlite:// diff --git a/etc/storyboard.conf.test b/etc/storyboard.conf.test index d424d64a..e2f43fe9 100644 --- a/etc/storyboard.conf.test +++ b/etc/storyboard.conf.test @@ -9,4 +9,4 @@ lock_path = $state_path/lock [database] -connection = mysql+pymysql://#DB_USER#:#DB_PASSWORD#@127.0.0.1:3306/#DB_TEST# +connection = mysql+pymysql://#DB_USER#:#DB_PASSWORD#@127.0.0.1:3306/#DB_TEST#?charset=utf8mb4 diff --git a/storyboard/tests/base.py b/storyboard/tests/base.py index 3c9860f3..661ce24c 100644 --- a/storyboard/tests/base.py +++ b/storyboard/tests/base.py @@ -146,11 +146,10 @@ class DbTestCase(WorkingDirTestCase): self.db_name = "storyboard_test_db_%s" % uuid.uuid4() self.db_name = self.db_name.replace("-", "_") - CONF.set_override( - "connection", - self.test_connection + "/%s" - % self.db_name, - group="database") + dburi = self.test_connection + "/%s" % self.db_name + if dburi.startswith('mysql+pymysql://'): + dburi += "?charset=utf8mb4" + CONF.set_override("connection", dburi, group="database") self._full_db_name = self.test_connection + '/' + self.db_name LOG.info('using database %s', CONF.database.connection) diff --git a/storyboard/tests/db/migration/test_migrations.conf b/storyboard/tests/db/migration/test_migrations.conf index 11e498c2..5861e772 100644 --- a/storyboard/tests/db/migration/test_migrations.conf +++ b/storyboard/tests/db/migration/test_migrations.conf @@ -6,7 +6,7 @@ #sqlite=sqlite:// #sqlitefile=sqlite:///test_migrations_utils.db -mysql=mysql+pymysql://storyboard:storyboard@localhost/test_migrations_utils +mysql=mysql+pymysql://storyboard:storyboard@localhost/test_migrations_utils?charset=utf8mb4 [migration_dbs] # Migration DB details are listed separately as they can't be connected to @@ -17,7 +17,7 @@ mysql=mysql+pymysql://storyboard:storyboard@localhost/test_migrations_utils #sqlite=sqlite:// #sqlitefile=sqlite:///test_migrations.db -#mysql=mysql+pymysql://user:pass@localhost/test_migrations +#mysql=mysql+pymysql://user:pass@localhost/test_migrations?charset=utf8mb4 [walk_style] snake_walk=yes