jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
567 stars 129 forks source link

UUIDs instead of ID #174

Closed rommeA closed 2 years ago

rommeA commented 2 years ago

Is it possible to create a constant in config, which will determine if database migrations and models should use UUIDs as ID, not integers? For instance, in migration:

if (config('mail-tracker.use_uuids')) {
    $table->uuid('id')->primary();
} else {
    $table->increments('id');
}
......
if (config('mail-tracker.use_uuids')) {
    DB::statement('ALTER TABLE sent_emails_url ALTER COLUMN id SET DEFAULT uuid_generate_v4();');
}

and in models:

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->keyType = (config('mail-tracker.use_uuids')) ? 'string' : 'int';
    }

I've changed migration files to use UUIDs, but all Models should be changed too... https://flareapp.io/share/17xj4eGm#F62

rommeA commented 2 years ago

Opened a PR.

jdavidbakr commented 2 years ago

I'm going to close this - you could easily add UUID's with a migration and a model observer. I'm personally not a fan of using UUIDs as primary key anyway, I think it's better to have it as a separately indexed column.