mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
fix: #1286 duplicate key value on Pgsql
This commit is contained in:
parent
6b7cb88e6d
commit
27b97fa317
2 changed files with 24 additions and 0 deletions
|
@ -5,6 +5,7 @@ namespace Database\Seeders;
|
||||||
use App\Models\Album;
|
use App\Models\Album;
|
||||||
use App\Models\Artist;
|
use App\Models\Artist;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class AlbumTableSeeder extends Seeder
|
class AlbumTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
@ -17,5 +18,16 @@ class AlbumTableSeeder extends Seeder
|
||||||
'name' => Album::UNKNOWN_NAME,
|
'name' => Album::UNKNOWN_NAME,
|
||||||
'cover' => Album::UNKNOWN_COVER,
|
'cover' => Album::UNKNOWN_COVER,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
self::maybeResetPgsqlSerialValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function maybeResetPgsqlSerialValue(): void
|
||||||
|
{
|
||||||
|
if (DB::getDriverName() === 'pgsql') {
|
||||||
|
DB::statement(
|
||||||
|
"SELECT setval(pg_get_serial_sequence('albums', 'id'), coalesce(max(id), 0) + 1, false) FROM albums"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\Artist;
|
use App\Models\Artist;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class ArtistTableSeeder extends Seeder
|
class ArtistTableSeeder extends Seeder
|
||||||
{
|
{
|
||||||
|
@ -14,5 +15,16 @@ class ArtistTableSeeder extends Seeder
|
||||||
], [
|
], [
|
||||||
'name' => Artist::UNKNOWN_NAME,
|
'name' => Artist::UNKNOWN_NAME,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
self::maybeResetPgsqlSerialValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function maybeResetPgsqlSerialValue(): void
|
||||||
|
{
|
||||||
|
if (DB::getDriverName() === 'pgsql') {
|
||||||
|
DB::statement(
|
||||||
|
"SELECT setval(pg_get_serial_sequence('artists', 'id'), coalesce(max(id), 0) + 1, false) FROM artists"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue