moved roles to a separate database and added code to make updates

This commit is contained in:
Edward Tirado Jr 2026-04-09 18:30:16 -05:00
parent 985f339725
commit 836ef8f1f6
14 changed files with 317 additions and 21 deletions

View file

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class RoleFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, string>
*/
public function definition(): array
{
return [
'name' => 'ADMIN',
'display_name' => 'Administrator',
];
}
}

View file

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('display_name');
$table->string('name')->unique();
$table->text('description')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('roles');
}
};

View file

@ -15,7 +15,7 @@ return new class extends Migration
$table->id();
$table->foreignId('movie_list_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->enum('role', ['viewer', 'editor', 'admin'])->default('viewer');
$table->foreignId('role_id')->constrained()->cascadeOnDelete();
$table->unique(['movie_list_id', 'user_id']);
$table->timestamps();
});

View file

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
@ -15,11 +16,27 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
// User::factory(10)->create();
if (config('app.env') === 'local') {
User::factory()->create([
'username' => 'testy_mctestface',
'email' => 'test@example.com',
]);
}
User::factory()->create([
'username' => 'testy_mctestface',
'email' => 'test@example.com',
Role::factory()->createMany([
[
'name' => 'ADMIN',
'display_name' => 'Administrator',
'description' => 'Can make any changes to the list including deleting it. Can also invite other users to collaborate on this list.'],
[
'name' => 'EDITOR',
'display_name' => 'Editor',
'description' => 'Can edit list details and can add/remove movies from the list.'],
[
'name' => 'VIEWER',
'display_name' => 'Viewer',
'description' => 'Can view the list, but cannot make any changes.',
],
]);
}
}