2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2015-12-13 04:42:28 +00:00
|
|
|
use App\Models\Artist;
|
2015-12-14 13:22:39 +00:00
|
|
|
use Illuminate\Database\Seeder;
|
2021-05-21 12:24:20 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
class ArtistTableSeeder extends Seeder
|
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
public function run(): void
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
2022-08-09 18:45:11 +00:00
|
|
|
Artist::query()->firstOrCreate(['id' => Artist::UNKNOWN_ID], ['name' => Artist::UNKNOWN_NAME]);
|
2021-05-21 12:24:20 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|
|
|
|
}
|