You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
|
|
class dag extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'user_id',
|
|
|
|
|
'airflow_id',
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'file_path',
|
|
|
|
|
'status',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Связь с Airflow кластером.
|
|
|
|
|
*/
|
|
|
|
|
public function airflow()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Airflow::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Связь с моделью User.
|
|
|
|
|
*/
|
|
|
|
|
public function user()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Связь с моделью DAGRun.
|
|
|
|
|
*/
|
|
|
|
|
public function runs()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(dag_run::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::updated(function ($dag) {
|
|
|
|
|
$changes = $dag->getChanges();
|
|
|
|
|
|
|
|
|
|
// Исключаем системные поля
|
|
|
|
|
unset($changes['updated_at']);
|
|
|
|
|
|
|
|
|
|
if (!empty($changes)) {
|
|
|
|
|
$original = $dag->getOriginal();
|
|
|
|
|
|
|
|
|
|
$changedData = [];
|
|
|
|
|
foreach ($changes as $key => $value) {
|
|
|
|
|
$changedData[$key] = [
|
|
|
|
|
'old' => $original[$key] ?? null,
|
|
|
|
|
'new' => $value,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dag_historie::create([
|
|
|
|
|
'dag_id' => $dag->id,
|
|
|
|
|
'user_id' => Auth::id() ?? $dag->user_id, // Учитываем случаи, когда нет аутентифицированного пользователя
|
|
|
|
|
'change_description' => 'Обновление DAG',
|
|
|
|
|
'changed_data' => $changedData,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Связь с историей изменений DAG.
|
|
|
|
|
*/
|
|
|
|
|
public function histories()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(dag_historie::class);
|
|
|
|
|
}
|
|
|
|
|
}
|