mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-08 05:43:18 +01:00
- Rename the audit actor columns user_type/user_id to actor_type/actor_id - Add owner_organization_id and owner_user_id to the audits table as foreign keys with cascade on delete, so that the audits of an organization or user are deleted together with it. The indexes and foreign keys are created without blocking writes on the large table. - Fill the owner columns for new audits via CustomAuditable. Organizations and users no longer record their own deletion audit, since it would reference the already deleted owner.
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\AuditFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Carbon;
|
|
use OwenIt\Auditing\Models\Audit as PackageAuditModel;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string|null $actor_type
|
|
* @property string|null $actor_id
|
|
* @property string $event
|
|
* @property string $auditable_type
|
|
* @property string $auditable_id
|
|
* @property array<string, mixed>|null $old_values
|
|
* @property array<string, mixed>|null $new_values
|
|
* @property string|null $url
|
|
* @property string|null $ip_address
|
|
* @property string|null $user_agent
|
|
* @property string|null $tags
|
|
* @property string|null $owner_user_id
|
|
* @property string|null $owner_organization_id
|
|
* @property Carbon|null $created_at
|
|
* @property Carbon|null $updated_at
|
|
* @property-read User|null $ownerUser
|
|
* @property-read Organization|null $ownerOrganization
|
|
*
|
|
* @method static AuditFactory factory()
|
|
*/
|
|
class Audit extends PackageAuditModel
|
|
{
|
|
/** @use HasFactory<AuditFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function ownerUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_user_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Organization, $this>
|
|
*/
|
|
public function ownerOrganization(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organization::class, 'owner_organization_id');
|
|
}
|
|
}
|