Change table name (source) to uppercase on MySQL/MariaDB

Is it possible to change the table name (source) of an Ecto schema based on the Repo or the Adapter?

I need to connect to two databases, a PostgreSQL and a MySQL.

Tables on the MySQL server were created with uppercase names, so for example when querying all users, the generated SQL (SELECT ... FROM `users`) works on PostgreSQL but gives an error on MySQL as the table doesn’t exist, it exists as USERS.

Both are beyond my control, I don’t have permission to change either config. If I had access to the database I could change the config allowing case insensivity (https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html).

You can from u in {"users", User} and from u in {"USERS", User} where the first item is the table name and the second is the schema to cast to.

1 Like

Although that’s a perfectly valid answer, I would have to change queries and insert/updates in a lot of places, something I will ultimately have to do if there’s not an easier path. :smiley:

In the end that’s what I’m using to solve the problem. I wish there was some kind of “table name mapper” or callback to resolve table names.

Thank you anyway. :slight_smile: