Support uuid
type for MariaDB 10.7.0+
#49842
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #49752.
MariaDB since version 10.7 natively supports
uuid
data type. Also, since 10.5 supportsINSERT ... RETURNING
.This PR adds support for
uuid
type for MariaDB only.MySQL, unfortunately, as usual does not support anything. There are some hacks on how people manually implement "uuid" data type. For example, using a
BINARY(16)
column with aUUID_TO_BIN(UUID())
as a default or aVARCHAR(36)
withUUID()
as a default. See https://blogs.oracle.com/mysql/post/mysql-uuids or https://dev.mysql.com/blog-archive/mysql-8-0-uuid-support/ for detailed examples. But since MySQL does not supportRETURNING
, there is no way we can retrieve these values during theINSERT
without therecord.reload
. Or, differently, we must manually set the uuid before creating a record.So, the question is: Should we add also support for MySQL, expecting that people will manually set the default?
Something like:
The added test cases are basically adopted tests for PostgreSQL uuid (https://github.com/rails/rails/blob/main/activerecord/test/cases/adapters/postgresql/uuid_test.rb).
Before merging this PR, #49840 should be merged, because these have overlapping code regarding(done)RETURNING
for MariaDB.