Skip to content

Commit f3157b5

Browse files
committed
execute as raw query
1 parent 81ab406 commit f3157b5

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

database/migrations/2025_05_17_194147_fix_livemetrics_album_id.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,7 @@
1414
*/
1515
public function up(): void
1616
{
17-
if (DB::getConfig('driver') === 'pgsql') {
18-
DB::table('live_metrics')->join('photos', 'photos.id', '=', 'live_metrics.photo_id')
19-
->addSelect([
20-
'live_metrics.photo_id',
21-
'photos.album_id',
22-
])
23-
->updateFrom(['album_id' => DB::raw('photos.album_id')]);
24-
} else {
25-
DB::table('live_metrics')->join('photos', 'photos.id', '=', 'live_metrics.photo_id')
26-
->addSelect([
27-
'live_metrics.photo_id',
28-
'photos.album_id',
29-
])
30-
->update(['live_metrics.album_id' => DB::raw('photos.album_id')]);
31-
}
17+
DB::statement('UPDATE live_metrics SET album_id = (SELECT album_id FROM photos WHERE photos.id = live_metrics.photo_id) WHERE photo_id IS NOT NULL');
3218
}
3319

3420
/**

0 commit comments

Comments
 (0)