coolify/app/Livewire/Project/Service
Andras Bacsai ce12c94709 fix: prevent duplicate services on image change and enable real-time UI refresh
This commit addresses two critical issues with Docker Compose service management:

## Issue 1: Duplicate Services Created on Image Change
When changing the image in a docker-compose file, the parser was creating new
ServiceApplication/ServiceDatabase records instead of updating existing ones.

**Root Cause**: The parsers used `firstOrCreate()` with `['name', 'image', 'service_id']`,
meaning any image change would create a new record.

**Fix**: Remove `image` from `firstOrCreate()` queries and update it separately after
finding or creating the service record.

**Changes**:
- `bootstrap/helpers/parsers.php` (serviceParser v3): Fixed in presave loop (lines 1188-1203)
  and main parsing loop (lines 1519-1539)
- `bootstrap/helpers/shared.php` (parseDockerComposeFile v2): Fixed null check logic
  (lines 1308-1348)

## Issue 2: UI Not Refreshing After Changes
When compose file or domain was modified, the Configuration component wasn't receiving
events to refresh its data, requiring manual page refresh to see updates.

**Root Cause**: The Configuration component wasn't listening for refresh events dispatched
by child components (StackForm, EditDomain).

**Fix**: Add event listeners and dispatchers to enable real-time UI updates.

**Changes**:
- `app/Livewire/Project/Service/Configuration.php`: Added listeners for `refreshServices`
  and `refresh` events (lines 36-37)
- `app/Livewire/Project/Service/EditDomain.php`: Added `refreshServices` dispatch (line 76)
- Note: `app/Livewire/Project/Service/StackForm.php` already had the dispatch

## Tests Added
- `tests/Unit/ServiceParserImageUpdateTest.php`: 4 tests verifying no duplicates created
- `tests/Unit/ServiceConfigurationRefreshTest.php`: 4 tests verifying event dispatching

All 8 new tests pass, and all existing unit tests continue to pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 10:12:36 +02:00
..
Configuration.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
Database.php feat(acl): Change views/backend code to able to use proper ACL's later on. Currently it is not enabled. 2025-08-26 10:27:38 +02:00
EditCompose.php fix(ui): Restrict service retrieval to current team 2025-02-27 12:17:23 +01:00
EditDomain.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
FileStorage.php feat(storage): add read-only volume handling and UI notifications 2025-10-03 20:05:43 +02:00
Heading.php fix(service): ensure configuration changes are properly tracked and dispatched 2025-07-03 15:08:13 +02:00
Index.php feat(acl): Change views/backend code to able to use proper ACL's later on. Currently it is not enabled. 2025-08-26 10:27:38 +02:00
ServiceApplicationView.php move domain trimming before URL validation 2025-08-29 09:09:03 -04:00
StackForm.php refactor(validation): implement centralized validation patterns across components 2025-08-19 14:15:31 +02:00
Storage.php feat(storage): consolidate storage management into a single component with enhanced UI 2025-10-01 18:46:21 +02:00