Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add column type for native UUID #50192

Closed
wants to merge 7 commits into from

Conversation

staudenmeir
Copy link
Contributor

With the new dedicated driver, MariaDB users can now benefit from the native column type for UUIDs (Laravel uses char(36) at the moment).

This would be a breaking change for existing applications, but since the driver is new, users have to consciously switch to it and will be made aware of this change. They should convert their existing UUID columns to the native type. I'll document it in the upgrade guide.

@taylorotwell
Copy link
Member

Not totally sure I want the breaking change if people opt-in to this. 😬 I wonder if a nativeUuid method would be better? Or even uuid()->native() which I think I like even more.

@taylorotwell taylorotwell marked this pull request as draft February 21, 2024 20:01
@hafezdivandari
Copy link
Contributor

hafezdivandari commented Feb 22, 2024

But user expects uuid type when declaring uuid column? We already use uuid type on pgsql and uniqueidentifier type on sqlsrv, and it fallbacks to char(36) on MySQL. Isn't it totally expected to have uuid type on mariadb when it's actually supported?

image

@taylorotwell
Copy link
Member

It's more about the breaking changes involved. If you already have an app in production using uuid() where it creates a char(36), then you upgrade to Laravel 11 and setup a new dev machine, your column locally is now a native UUID but production is a char(36).

@hafezdivandari
Copy link
Contributor

I understand, but I think it's easier to explain this on the L11 upgrade guide (user may explicitly use ->char('uuid', 36) if they want), than explain this on the migrations docs that it's sometimes a UUID and sometimes not.

But if we are going to use a modifier, I suggest ->strict(). We can use this on some other types on SQLite too, to be able to enable strict mode: https://www.sqlite.org/stricttables.html

@staudenmeir
Copy link
Contributor Author

I wonder if a nativeUuid method would be better? Or even uuid()->native() which I think I like even more.

@taylorotwell Would you make this a MariaDB-only method/modifier or should it work with all DBMS that have a native column type for UUIDs (MariaDB, PostgreSQL, SQL Server) and throw an exception for all other DBMS?

@taylorotwell
Copy link
Member

I think it would work on all databases that support it and throw an exception on other DBs.

@johanrosenson
Copy link
Contributor

We are using MariaDB and UUID's and I would prefer the breaking change over a native() method. The breaking change is a one time effort required when upgrading, the native() is something everyone have to keep doing forever.

The breaking change better aligns with what we expect: a native type if possible, or a generic fallback.
We have always assumed that whenever a native type becomes available, the type methods would be updated to reflect the current best available options.

The upgrade guide would have to mention this of course and maybe the upgrade guide could give a small code example of how to convert existing char(36) to proper uuid type in a migration.

@staudenmeir
Copy link
Contributor Author

@johanrosenson I personally also prefer the breaking change. If there is ever a good time for this, it would be now.

@taylorotwell I reverted the changes and added the nativeUuid() type. I looked into uuid()->native(), but since modifiers can only add SQL after to the column type, we can't use them to replace char(36) with uuid without changing quite a bit of code.

There are three helper methods for UUIDs: foreignUuid(), uuidMorphs(), and nullableUuidMorphs()
Do you want to have equivalents for native UUIDs?

@staudenmeir staudenmeir marked this pull request as ready for review February 23, 2024 15:16
@staudenmeir staudenmeir changed the title [11.x] Use native UUID column type on MariaDB [11.x] Add column type for native UUID Feb 23, 2024
@taylorotwell
Copy link
Member

Decided to just go with your original commit of using native UUID on uuid method. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants