Skip to content

Commit

Permalink
fix: RootUserSeeder
Browse files Browse the repository at this point in the history
- ensure that the existing root user is not overwritten
- ensure that the seeder can only be run once - creating the initial root user
  • Loading branch information
peaklabs-dev committed Jan 16, 2025
1 parent 3927e48 commit 4b6690e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions database/seeders/RootUserSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ class RootUserSeeder extends Seeder
{
public function run(): void
{
if (User::where('id', 0)->exists()) {
echo " Root user already exists. Skipping creation.\n";

return;
}

if (env('ROOT_USER_EMAIL') && env('ROOT_USER_PASSWORD')) {
User::updateOrCreate(
['id' => 0],
[
'name' => env('ROOT_USER_NAME', 'Root User'),
'email' => env('ROOT_USER_EMAIL'),
'password' => Hash::make(env('ROOT_USER_PASSWORD')),
]
);
User::create([
'id' => 0,
'name' => env('ROOT_USERNAME', 'Root User'),
'email' => env('ROOT_USER_EMAIL'),
'password' => Hash::make(env('ROOT_USER_PASSWORD')),
]);

InstanceSettings::updateOrCreate(
['id' => 0],
['is_registration_enabled' => false]
);

echo " Root user created/updated successfully.\n";
echo " Root user created successfully.\n";
echo " Registration has been disabled.\n";
} else {
echo " Warning: ROOT_USER_EMAIL and ROOT_USER_PASSWORD environment variables are required for root user creation.\n";
Expand Down

0 comments on commit 4b6690e

Please sign in to comment.