[Enhancement]: Enable backup restore/import for ServiceDatabase (Docker Compose databases)
Request Type
New Feature
Description
Description
Databases created via Docker Compose deployments (ServiceDatabase) can create backups but cannot restore/import them through the UI. The import functionality only supports Standalone database types.
Current Behavior
| Database Type | Backup | Restore/Import |
|---|---|---|
| StandalonePostgresql | ✅ | ✅ |
| StandaloneMysql | ✅ | ✅ |
| StandaloneMariadb | ✅ | ✅ |
| StandaloneMongodb | ✅ | ✅ |
| ServiceDatabase (from Docker Compose) | ✅ | ❌ |
Expected Behavior
ServiceDatabase should support restore/import functionality, similar to Standalone databases.
Technical Details
File: app/Livewire/Project/Database/Import.php
The buildRestoreCommand() method (line 576-614) only handles Standalone database classes:
switch ($this->resource->getMorphClass()) {
case \App\Models\StandaloneMariadb::class:
// ...
case \App\Models\StandaloneMysql::class:
// ...
case \App\Models\StandalonePostgresql::class:
// ...
case \App\Models\StandaloneMongodb::class:
// ...
default:
$restoreCommand = ''; // ServiceDatabase falls here
}
Proposed Solution
Add support for ServiceDatabase in Import.php:
- In
buildRestoreCommand(), add a case forServiceDatabase:
case \App\Models\ServiceDatabase::class:
$dbType = $this->resource->databaseType(); // Returns 'standalone-postgresql', etc.
// Build restore command based on $dbType
break;
-
The
ServiceDatabase->databaseType()method already returns the database type (e.g.,standalone-postgresql,standalone-mysql), which can be used to determine the correct restore command. -
Update
getContainers()to properly handle ServiceDatabase container naming:
// ServiceDatabase container name format: {service-name}-{service-uuid}
$this->container = $this->resource->name . '-' . $this->resource->service->uuid;
Related Code
-
app/Livewire/Project/Database/Import.php- Import/restore component -
app/Models/ServiceDatabase.php- HasdatabaseType()method -
app/Jobs/DatabaseBackupJob.php- Already supports ServiceDatabase for backups
Use Case
Users deploying databases via Docker Compose (e.g., postgres:17-alpine in a compose file) need the ability to restore backups through the Coolify UI, just like Standalone database deployments.
💎 $25 bounty • Ilias Ism
Steps to solve:
-
Start working: Comment
/attempt #7529with your implementation plan -
Submit work: Create a pull request including
/claim #7529in the PR body to claim the bounty - Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
❗ Important guidelines:
- To claim a bounty, you need to provide a short demo video of your changes in your pull request
- If anything is unclear, ask for clarification before starting as this will help avoid potential rework
- Low quality AI PRs will not receive review and will be closed
- Do not ask to be assigned unless you've contributed before
Thank you for contributing to coollabsio/coolify!
/attempt #7529
Implementation Plan
I will add ServiceDatabase support to the backup restore/import functionality by:
-
Modify app/Livewire/Project/Database/Import.php:
- Update getContainers() method to handle ServiceDatabase container naming (
name-service.uuid) - Add ServiceDatabase case in buildRestoreCommand() method
- Update getContainers() method to handle ServiceDatabase container naming (
-
Support all database types:
- PostgreSQL (including PostGIS variants)
- MySQL
- MariaDB
- MongoDB
-
Implementation approach:
- Use existing
ServiceDatabase::databaseType()method to detect database type - Build restore commands consistent with DatabaseBackupJob.php backup logic
- Support both regular and "dump all" restore modes
- Use existing
Timeline: Implementation complete and ready for review
I believe one of the main reasons why this hasn't been implemented yet, is the problem that deployments that could trigger at the same time as a running backup / import. This can interrupt the backup / import, and worst case corrupt your database. So it requires some logic to put a redeployment on queue, whenever a import or backup is running.
/attempt #7529
Implementation Plan
Adding ServiceDatabase support to the backup restore/import functionality:
-
Modified
getContainers(): Handle ServiceDatabase container naming (name-service.uuidformat) -
Modified
buildRestoreCommand(): Added ServiceDatabase case usingdatabaseType()to detect PostgreSQL, MySQL, MariaDB, MongoDB -
Modified
updatedDumpAll(): Support dump-all mode for ServiceDatabase
PR: #7540