fix(audit): stop duplicate and empty audit rows

- Set env var version and compose parsing version while creating, so a create writes one row
- Record no rows for the auto-created preview copy of an env var
- Record env and application API updates only with the fields that really changed
- Store no change data for new env vars, and null for empty change data
- Store metadata team_id as an integer
- Drop the unused level and resource indexes of audit_events

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-11-05 23:49:17 +01:00
co-authored by Claude Opus 5.5
parent 13298591d8
commit b7d0e6be2a
10 changed files with 111 additions and 39 deletions
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* No query filters audit events by level or by resource, so these indexes only cost disk space and write time.
*/
public function up(): void
{
Schema::table('audit_events', function (Blueprint $table) {
if (Schema::hasIndex('audit_events', 'audit_events_level_index')) {
$table->dropIndex('audit_events_level_index');
}
if (Schema::hasIndex('audit_events', ['team_id', 'resource_type', 'resource_uuid', 'created_at'])) {
$table->dropIndex(['team_id', 'resource_type', 'resource_uuid', 'created_at']);
}
});
}
public function down(): void
{
Schema::table('audit_events', function (Blueprint $table) {
$table->index('level');
$table->index(['team_id', 'resource_type', 'resource_uuid', 'created_at']);
});
}
};