Skip to content

Commit

Permalink
Fix migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagmat84 committed May 26, 2022
1 parent f3ccd59 commit 59f621a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions database/migrations/2020_12_12_203153_migrate_admin_user.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
<?php

use App\Exceptions\ModelDBException;
use App\Models\Configs;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class MigrateAdminUser extends Migration
{
/**
* Run the migrations.
*
* @return void
*
* @throws ModelDBException
*/
public function up()
public function up(): void
{
$user = new User();
$user->username = Configs::get_value('username', '');
$user->password = Configs::get_value('password', '');
$user->save();

// user will have a id which is NOT 0.
// we want this user to have an ID of 0 as it is the ADMIN ID.
// User will have an ID which is NOT 0.
// We want this user to have an ID of 0 as it is the ADMIN ID.
$user->id = 0;
$user->save();
}
Expand All @@ -28,14 +33,15 @@ public function up()
* Reverse the migrations.
*
* @return void
*
* @throws InvalidArgumentException
*/
public function down()
public function down(): void
{
if (Schema::hasTable('users')) {
$user = User::find(0);
if ($user != null) {
$user->delete();
}
DB::table('users')
->where('id', '=', 0)
->delete();
}
}
}

0 comments on commit 59f621a

Please sign in to comment.