fix(models): replace forceCreate with forceFill+save pattern

Replaces Model::forceCreate([...]) calls with (new Model)->forceFill([...])->save()
across SettingsBackup, Server, and User models to avoid bypassing Eloquent
model event lifecycle during record creation.
This commit is contained in:
Andras Bacsai 2026-03-31 13:50:37 +02:00
parent 1a603a10ed
commit a77e1f47d1
3 changed files with 13 additions and 9 deletions

View file

@ -83,7 +83,8 @@ public function addCoolifyDatabase()
$postgres_password = $envs['POSTGRES_PASSWORD'];
$postgres_user = $envs['POSTGRES_USER'];
$postgres_db = $envs['POSTGRES_DB'];
$this->database = StandalonePostgresql::forceCreate([
$this->database = new StandalonePostgresql;
$this->database->forceFill([
'id' => 0,
'name' => 'coolify-db',
'description' => 'Coolify database',
@ -94,6 +95,7 @@ public function addCoolifyDatabase()
'destination_type' => StandaloneDocker::class,
'destination_id' => 0,
]);
$this->database->save();
$this->backup = ScheduledDatabaseBackup::create([
'id' => 0,
'enabled' => true,

View file

@ -143,28 +143,28 @@ protected static function booted()
}
});
static::created(function ($server) {
ServerSetting::forceCreate([
ServerSetting::create([
'server_id' => $server->id,
]);
if ($server->id === 0) {
if ($server->isSwarm()) {
SwarmDocker::forceCreate([
(new SwarmDocker)->forceFill([
'id' => 0,
'name' => 'coolify',
'network' => 'coolify-overlay',
'server_id' => $server->id,
]);
])->save();
} else {
StandaloneDocker::forceCreate([
(new StandaloneDocker)->forceFill([
'id' => 0,
'name' => 'coolify',
'network' => 'coolify',
'server_id' => $server->id,
]);
])->saveQuietly();
}
} else {
if ($server->isSwarm()) {
SwarmDocker::forceCreate([
SwarmDocker::create([
'name' => 'coolify-overlay',
'network' => 'coolify-overlay',
'server_id' => $server->id,

View file

@ -98,7 +98,8 @@ protected static function boot()
$team['id'] = 0;
$team['name'] = 'Root Team';
}
$new_team = Team::forceCreate($team);
$new_team = (new Team)->forceFill($team);
$new_team->save();
$user->teams()->attach($new_team, ['role' => 'owner']);
});
@ -201,7 +202,8 @@ public function recreate_personal_team()
$team['id'] = 0;
$team['name'] = 'Root Team';
}
$new_team = Team::forceCreate($team);
$new_team = (new Team)->forceFill($team);
$new_team->save();
$this->teams()->attach($new_team, ['role' => 'owner']);
return $new_team;