fix: issues with DISTINCT on pgsql (#1789)

This commit is contained in:
Phan An 2024-07-14 20:49:40 +02:00 committed by GitHub
parent 702913a76c
commit 3b34819706
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 4 deletions

View file

@ -61,7 +61,6 @@ class SongBuilder extends Builder
)
->leftJoin('albums', 'songs.album_id', 'albums.id')
->leftJoin('artists', 'songs.artist_id', 'artists.id')
->distinct()
->select(
'songs.*',
'albums.name',

View file

@ -44,11 +44,11 @@ class AlbumRepository extends Repository
->join('interactions', static function (JoinClause $join) use ($user): void {
$join->on('songs.id', 'interactions.song_id')->where('interactions.user_id', $user->id);
})
->groupBy('albums.id')
->groupBy('albums.id', 'play_count')
->distinct()
->orderByDesc('play_count')
->limit($count)
->get('albums.*');
->get(['albums.*', 'play_count']);
}
/** @return Collection|array<array-key, Album> */

View file

@ -40,7 +40,7 @@ class ArtistRepository extends Repository
->distinct()
->orderByDesc('play_count')
->limit($count)
->get('artists.*');
->get(['artists.*', 'play_count']);
}
/** @return Collection|array<array-key, Artist> */

View file

@ -60,6 +60,7 @@ class SongRepository extends Repository
return Song::query(user: $scopedUser ?? $this->auth->user())
->accessible()
->withMeta(requiresInteractions: true)
->addSelect('interactions.last_played_at')
->orderByDesc('interactions.last_played_at')
->limit($count)
->get();

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('podcasts', static function (Blueprint $table): void {
$table->text('categories')->change();
$table->text('metadata')->change();
});
Schema::table('queue_states', static function (Blueprint $table): void {
$table->text('song_ids')->change();
});
Schema::table('licenses', static function (Blueprint $table): void {
$table->text('instance')->nullable()->change();
$table->text('meta')->nullable()->change();
});
Schema::table('songs', static function (Blueprint $table): void {
$table->text('episode_metadata')->nullable()->change();
});
Schema::table('podcast_user', static function (Blueprint $table): void {
$table->text('state')->nullable()->change();
});
}
};