-
Notifications
You must be signed in to change notification settings - Fork 163
Description
I have a database in MySQL on Linux (for production) and macOS (for development). In that database some table names use mixed-case (e.g. articleGalleryImage). I was trying to write a database migration that is portable from development to production.
On macOS in development (mysql_fdw version 2.5.3, mysql server version 5.7.29 Homebrew, PostgreSQL server 12.3 also from Homebrew):
import foreign schema app_development limit to ("articleGalleryImage")
from server mysql_server into mysql
completes successfully, but creates no foreign table, while
import foreign schema app_development limit to (articlegalleryimage)
from server mysql_server into mysql
works, and creates a foreign table called articlegalleryimage
.
On Linux (mysql_fdw version 2.5.3, mysql server version 5.7.31-0ubuntu0.18.04.1-log, PostgreSQL server 12.3 (Ubuntu 12.3-1.pgdg18.04+1)) the reverse is true and the foreign table is called articleGalleryImage
. This makes it tricky to write a single statement that will work on both platforms. It also means that resulting schemas objects have different names.
I think the cause could be mysql's lower_case_table_names
setting. On macOS the default for this is 2
, while on Linux it is 0
. I've pared down the query that is run to get the table details from MySQL's information schema to the following:
select t.table_name
from information_schema.tables as t
where t.table_name in ('articleGalleryImage');
Running this on macOS I get this:
+---------------------+
| table_name |
+---------------------+
| articlegalleryimage |
+---------------------+
Note that the table_name
value has been lower-cased: the actual table name is mixed case in the database schema, but this seems to be a quirk of MySQL. On Linux I get this:
+---------------------+
| table_name |
+---------------------+
| articleGalleryImage |
+---------------------+
Reading https://dev.mysql.com/doc/refman/5.7/en/charset-collation-information-schema.html suggests a possible solution might be to force the collation - again on macOS:
select t.table_name from information_schema.tables as t where t.table_name collate utf8_general_ci in ('articleGalleryImage');
+---------------------+
| table_name |
+---------------------+
| articleGalleryImage |
+---------------------+
I'll see if I can make that modification and report back.