mirror of
https://github.com/koel/koel
synced 2024-12-19 17:13:09 +00:00
30 lines
743 B
PHP
30 lines
743 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Album;
|
|
use App\Models\Artist;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AlbumTableSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
Album::query()->firstOrCreate(['id' => Album::UNKNOWN_ID], [
|
|
'artist_id' => Artist::UNKNOWN_ID,
|
|
'name' => Album::UNKNOWN_NAME,
|
|
]);
|
|
|
|
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"
|
|
);
|
|
}
|
|
}
|
|
}
|