first commit
This commit is contained in:
63
app/Models/MigrationRun.php
Normal file
63
app/Models/MigrationRun.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class MigrationRun extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'schedule_id',
|
||||
'status',
|
||||
'total_tables',
|
||||
'processed_tables',
|
||||
'total_rows',
|
||||
'migrated_rows',
|
||||
'failed_rows',
|
||||
'error_message',
|
||||
'logs',
|
||||
'started_at',
|
||||
'completed_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'logs' => 'array',
|
||||
'total_tables' => 'integer',
|
||||
'processed_tables' => 'integer',
|
||||
'total_rows' => 'integer',
|
||||
'migrated_rows' => 'integer',
|
||||
'failed_rows' => 'integer',
|
||||
'started_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function schedule(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MigrationSchedule::class, 'schedule_id');
|
||||
}
|
||||
|
||||
public function getProgressAttribute(): float
|
||||
{
|
||||
if ($this->total_tables === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return round(($this->processed_tables / $this->total_tables) * 100, 2);
|
||||
}
|
||||
|
||||
public function getDurationAttribute(): ?string
|
||||
{
|
||||
if (!$this->started_at) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$end = $this->completed_at ?? now();
|
||||
$duration = $this->started_at->diff($end);
|
||||
|
||||
return $duration->format('%H:%I:%S');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user