Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ULID should be able to be stored as UUID #44135

Closed
@DarkGhostHunter

Description

@DarkGhostHunter
  • 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

  1. Offer 'ulid' and 'uuid' cast types for columns, and add ulid and uuid primary keys types, and apply them into the primary key.
  2. Have the Model/Builder change the ULID to UUID as opt-in when storing the values in the database.
  3. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions