{"record":{"id":"1693cbed3a1139d0","repo":"coollabsio/coolify","slug":"database-not-found","errorCode":null,"errorMessage":"Database not found?!","messagePattern":"Database not found\\?!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/Jobs/DatabaseBackupJob.php","lineNumber":118,"sourceCode":"            if (! $this->team) {\n                $this->backup->delete();\n\n                return;\n            }\n            if (data_get($this->backup, 'database_type') === ServiceDatabase::class) {\n                $this->database = data_get($this->backup, 'database');\n                $this->server = $this->database->service->server;\n                $this->s3 = $this->backup->s3;\n            } else {\n                $this->database = data_get($this->backup, 'database');\n                $this->server = $this->database->destination->server;\n                $this->s3 = $this->backup->s3;\n            }\n            if (is_null($this->server)) {\n                throw new \\Exception('Server not found?!');\n            }\n            if (is_null($this->database)) {\n                throw new \\Exception('Database not found?!');\n            }\n\n            $this->markStaleExecutionsAsFailed();\n\n            BackupCreated::dispatch($this->team->id);\n\n            $status = str(data_get($this->database, 'status'));\n            if (! $status->startsWith('running') && $this->database->id !== 0) {\n                Log::info('DatabaseBackupJob skipped: database not running', [\n                    'backup_id' => $this->backup->id,\n                    'database_id' => $this->database->id,\n                    'status' => (string) $status,\n                ]);\n\n                return;\n            }\n            if (data_get($this->backup, 'database_type') === ServiceDatabase::class) {\n                $databaseType = $this->database->databaseType();","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/coollabsio/coolify/blob/70b9acc42467278373e00de77abb40684e25b395/app/Jobs/DatabaseBackupJob.php#L100-L136","documentation":"DatabaseBackupJob throws when data_get($this->backup, 'database') is null: the ScheduledDatabaseBackup row exists but its related database record (standalone or service database) is gone or its database_type no longer resolves. Note the job returns silently when the whole backup schedule is missing; a present schedule with a missing database is treated as a hard integrity error.","triggerScenarios":"The database resource was deleted while its ScheduledDatabaseBackup row remained; database_type on the schedule points at a model/class whose record was removed; scheduled task fires after an incomplete resource deletion.","commonSituations":"Deleting a database via UI/API without cascading to scheduled backups; database_type staleness after upgrades/renames; manual DB surgery that dropped database rows but left schedules.","solutions":["Delete the orphaned ScheduledDatabaseBackup row(s) for the removed database.","Restore the database record if it was removed by mistake.","Audit scheduled backups after bulk deletions: ScheduledDatabaseBackup::whereDoesntHave('database')->get()."],"exampleFix":"// before: orphaned schedules keep firing and failing\n$database->delete();\n\n// after: cascade the cleanup\n$database->scheduledBackups()->delete();\n$database->delete();","handlingStrategy":"validation","validationCode":"// Confirm the schedule still has its database before the job fires\nif (is_null($backup->database)) {\n    \\Illuminate\\Support\\Facades\\Log::warning('Deleting orphaned scheduled backup', ['id' => $backup->id]);\n    $backup->delete();\n\n    return;\n}\n\ndispatch(new DatabaseBackupJob($backup));","typeGuard":"function scheduleHasDatabase(\\App\\Models\\ScheduledDatabaseBackup $backup): bool\n{\n    return ! is_null($backup->database);\n}","tryCatchPattern":null,"preventionTips":["Delete ScheduledDatabaseBackup rows in the same unit of work as the database resource.","After upgrades or manual DB edits, sweep for schedules with dangling database_type/database ids.","Prefer model deletion events (observers) over relying on users to clean up schedules manually."],"tags":["backup","database","orphaned-record","queue-job","scheduler"],"backgroundTag":"orphaned-relation","analyzedSha":"70b9acc42467278373e00de77abb40684e25b395","analyzedAt":"2026-08-17T01:41:01.313Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}