Force MySQL to use correct name and collation#6694
Force MySQL to use correct name and collation#6694BlackDex wants to merge 1 commit intodani-garcia:mainfrom
Conversation
This should force all MySQL/MariaDB connections to use the correct names and collation to be `utf8mb4` and `utf8mb4_unicode_ci`. It will not fix current tables which have the wrong charset or collation, but it should prevent new databases and future additions to use the wrong set. Also made sure that the init statements are also applied during migrations, which currently did not happen. Should prevent / resolve dani-garcia#6611 like issues in the future. Signed-off-by: BlackDex <black.dex@gmail.com>
|
Would this not introduce the issue to everyone who does not use As far as I've looked into it MariaDB by default uses I mean, I am not using MariaDB for Vaultwarden so I'm not sure how much of that is caused by upgrading without running scripts like |
|
In think it sets the connection preferred option. And shouldn't override the tables. Though conversion could happen, and maybe that possibly could cause an issue? |
|
New users probably won't be affect but I think this would break for everyone who does have existing tables with a different collation (as soon as we add any new tables or for users that upgrade from an older version without this change). Because if I understand it correctly, this would ignore the existing default collation for the database and change the charset and collation of newly added tables to |
|
Hmm conversion should happen, but not sure what that could cause. We could adjust all migrations which create tables to have the correct settings. |
But who decides what the correct settings are? I mean that's what I think the default collation is for, is it not? And if I want to have support for a newer unicode standard I'd set it to a new collation (which we can't do ourselves because MariaDB and MySQL have diverged long enough that the newest common To me this is not something that we can or should attempt to solve via code but that would have to be addressed by anyone who decides to use MariaDB or MySQL as their preferred database. We can probably just clarify the issue and improve our documentation so that people running into this have a better understanding of what to do. (Like migrating to Postgres or SQLite or fixing the collation issue when it comes up.) |
|
We could create a check in diagnostics which report non recommended settings as a different option. |
|
Yeah however I think that the diagnostics page will not be available if Vaultwarden refuses to start due to migration errors. Maybe we can do a check on startup if the charset + collation of existing tables are the same as the default collation? |
|
Maybe during startup we can do a simple table check? |
|
leaving this approved in case we decide to go this way but not merging yet, lmk if we decide to add the startup checks only and we can just close this then |
There was a problem hiding this comment.
Just tested it with using mariadb:10, mariadb:11 and mariadb:12 upgrading v1.28.0 to your PR (1.35.1-9a320171) and also checking what happens if you update from 1.28.0 with mariadb 10 to 1.35.1 with mariadb 11 and all seem to work without any issue, so I think this should actually be fine. (I mean I did not manage to reproduce the error that others have been facing without your PR either but at least setting the connection collation like this should not really hurt.)
|
if vaultwarden does not enforce, then migrations should also not fail. i dont think its valid for collate to be user defined as its a implementation detail. simplest example: case sensitive vs non case sensitive. at a minimum supported/recommended settings should be documented. that being said, SET NAMES at a minimum has been fairly standard practice, supporting a dynamic range is not really trivial and id be surprised if there was any greater value in that. |
The problem is that if a database product, Linux Distro, Docker Packager thinks a different default is better, and changes it, that will effect new tables or columns even. So, a user doesn't have to know or did anything for this to be changed. From my PHP day's i can remember i needed to set the specifics i wanted, else it would use the defaults from the server, which might or might not be in your control. |
|
Ill do some more testing btw, so keep this open for now. |
This should force all MySQL/MariaDB connections to use the correct names and collation to be
utf8mb4andutf8mb4_unicode_ci. It will not fix current tables which have the wrong charset or collation, but it should prevent new databases and future additions to use the wrong set.Also made sure that the init statements are also applied during migrations, which currently did not happen.
Should prevent / resolve #6611 like issues in the future.