mirror of
https://github.com/coollabsio/coolify.git
synced 2026-08-28 10:05:25 -05:00
Split V5 dashboard behavior into domain controllers and policies, add agent token rotation/revocation, status reconciliation jobs, ingress firewall syncing, and canvas connection APIs. Add migrations for V5 status tracking, server capabilities, resource connection aliases, and revoked agent tokens.
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models\V5;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
abstract class V5Model extends Model
|
|
{
|
|
/**
|
|
* Whether the model's table has a `uuid` column. Models without one (set
|
|
* this to false there) skip public-id generation and route on the primary
|
|
* key instead.
|
|
*/
|
|
protected bool $hasUuidColumn = true;
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return $this->hasUuidColumn ? 'uuid' : $this->getKeyName();
|
|
}
|
|
|
|
protected static function boot(): void
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function (self $model): void {
|
|
if ($model->hasUuidColumn && ! $model->getAttribute('uuid')) {
|
|
$model->setAttribute('uuid', $model->newUniquePublicId());
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Generate a public id, regenerating (up to three candidates) when one is
|
|
* already taken. A concurrent insert between this exists() check and our
|
|
* own insert can still collide; the unique index then rejects the insert,
|
|
* which is an acceptable residual race for these cheap, retryable writes.
|
|
*/
|
|
protected function newUniquePublicId(): string
|
|
{
|
|
$attempts = 0;
|
|
|
|
do {
|
|
$candidate = $this->newPublicIdCandidate();
|
|
$attempts++;
|
|
} while (
|
|
$attempts < 3
|
|
&& $this->newModelQuery()->where('uuid', $candidate)->exists()
|
|
);
|
|
|
|
return $candidate;
|
|
}
|
|
|
|
protected function newPublicIdCandidate(): string
|
|
{
|
|
return new_public_id();
|
|
}
|
|
}
|