UUIDs instead of ID
rommeA opened this issue · 2 comments
rommeA commented
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
jdavidbakr commented
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.