Closed
Description
- Laravel Version: 9.31 (tentative)
- PHP Version: 8.1.x
- Database Driver & Version: MySQL (all), PostgreSQL (all), MariaDB (all), SQL Server (all).
Description:
This recent #44074 forces the model to store ULIDs a 26-character strings in the database, which compared to standard UUIDv7, are 63% bigger. [There is an interesting article that talks about both]https://blog.daveallie.com/ulid-primary-keys().
Since ULID and UUID are inter-operable, a developer may mistake the binary/uuid column for the model and get errors because the ULID is created as string.
Laravel should by now offer first-class compatibility for both, and allow ULID to be stored as UUID in databases, since the latter have no OotB ULID compatibility yet. It's 2022, btw.
Steps To Reproduce:
Schema::create('example', function (Blueprint $table) {
$table->uuid('id');
});
class Example extends Model
{
use HasUlidPrimaryKey;
}
Storing a model with ULID in a UUID column will lead to SQL errors.
Possible solution
These are my candidates
- Offer 'ulid' and 'uuid' cast types for columns, and add
ulid
anduuid
primary keys types, and apply them into the primary key. - Have the Model/Builder change the ULID to UUID as opt-in when storing the values in the database.
- Let the developer deal with it by overriding
newUniqueId()
, and use a Cast to retrieve it as Ulid instance, through the documentation.
Metadata
Metadata
Assignees
Labels
No labels