feat(trash): implementasi fitur Tong Sampah (Recycle Bin) soft deletes dan retensi otomatis 30/60/90 hari di Super Admin
This commit is contained in:
@@ -19,6 +19,7 @@ return new class extends Migration
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
|
||||
@@ -17,6 +17,7 @@ return new class extends Migration
|
||||
$table->string('name', 100);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ return new class extends Migration
|
||||
$table->date('simper_expired_at')->nullable();
|
||||
$table->string('photo_path')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ return new class extends Migration
|
||||
$table->string('kir_document', 150)->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ return new class extends Migration
|
||||
$table->string('name', 100);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ return new class extends Migration
|
||||
$table->text('rejection_note')->nullable();
|
||||
$table->timestamp('validated_at')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// Indexes untuk percepatan performa filter log & antrean gerbang
|
||||
$table->index(['gate_id', 'validation_status']);
|
||||
|
||||
@@ -20,6 +20,7 @@ return new class extends Migration
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
// 2. Tabel Butir Pertanyaan / Item Cek per Template
|
||||
@@ -31,6 +32,7 @@ return new class extends Migration
|
||||
$table->string('question_type', 50); // choice, datetime, number, text
|
||||
$table->integer('sequence')->default(0);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['template_id', 'sequence']);
|
||||
});
|
||||
@@ -61,6 +63,7 @@ return new class extends Migration
|
||||
$table->text('validation_notes')->nullable();
|
||||
$table->dateTime('inspected_at');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['vehicle_id', 'inspected_at']);
|
||||
$table->index(['employee_id', 'inspected_at']);
|
||||
@@ -79,6 +82,7 @@ return new class extends Migration
|
||||
$table->text('answer_value')->nullable();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['p2h_record_id', 'condition_status']);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
// Pastikan seluruh user dengan role employee memiliki profil data master Employee
|
||||
$users = User::where('role', 'employee')
|
||||
$users = User::withoutGlobalScopes()->where('role', 'employee')
|
||||
->orWhereHas('roles', fn ($q) => $q->where('name', 'employee'))
|
||||
->get();
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ return new class extends Migration
|
||||
$table->text('notes')->nullable();
|
||||
$table->foreignId('created_by_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// Index performa query & pelaporan
|
||||
$table->index(['date', 'shift']);
|
||||
|
||||
@@ -38,6 +38,7 @@ return new class extends Migration
|
||||
$table->string('status', 30)->default('completed');
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
// Index
|
||||
$table->index(['vehicle_id', 'transfer_date']);
|
||||
|
||||
+2
@@ -21,6 +21,7 @@ return new class extends Migration
|
||||
$table->text('description')->nullable();
|
||||
$table->boolean('is_active')->default(true)->index();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
// 2. Tabel Relasi Multi-SIMPER Personil (Karyawan & Sukon)
|
||||
@@ -33,6 +34,7 @@ return new class extends Migration
|
||||
$table->string('status', 20)->default('active')->index();
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique(['employee_id', 'simper_type_id']);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// 1. Buat tabel system_settings untuk menyimpan konfigurasi sistem (seperti retensi auto-delete sampah)
|
||||
if (!Schema::hasTable('system_settings')) {
|
||||
Schema::create('system_settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key')->unique();
|
||||
$table->text('value')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
// Nilai bawaan retensi otomatis tong sampah: 30 hari
|
||||
DB::table('system_settings')->insertOrIgnore([
|
||||
'key' => 'trash_retention_days',
|
||||
'value' => '30',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. Tambahkan kolom deleted_at (SoftDeletes) ke seluruh tabel operasional dan master
|
||||
$tables = [
|
||||
'users',
|
||||
'employees',
|
||||
'employee_simpers',
|
||||
'simper_types',
|
||||
'vehicles',
|
||||
'vehicle_activities',
|
||||
'unit_transfers',
|
||||
'unit_support_timesheets',
|
||||
'p2h_templates',
|
||||
'p2h_template_items',
|
||||
'p2h_records',
|
||||
'p2h_record_items',
|
||||
'gates',
|
||||
'security_guards',
|
||||
];
|
||||
|
||||
foreach ($tables as $tableName) {
|
||||
if (Schema::hasTable($tableName) && !Schema::hasColumn($tableName, 'deleted_at')) {
|
||||
Schema::table($tableName, function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$tables = [
|
||||
'users',
|
||||
'employees',
|
||||
'employee_simpers',
|
||||
'simper_types',
|
||||
'vehicles',
|
||||
'vehicle_activities',
|
||||
'unit_transfers',
|
||||
'unit_support_timesheets',
|
||||
'p2h_templates',
|
||||
'p2h_template_items',
|
||||
'p2h_records',
|
||||
'p2h_record_items',
|
||||
'gates',
|
||||
'security_guards',
|
||||
];
|
||||
|
||||
foreach ($tables as $tableName) {
|
||||
if (Schema::hasTable($tableName) && Schema::hasColumn($tableName, 'deleted_at')) {
|
||||
Schema::table($tableName, function (Blueprint $table) {
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Schema::dropIfExists('system_settings');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user