moved roles to a separate database and added code to make updates
This commit is contained in:
parent
985f339725
commit
836ef8f1f6
14 changed files with 317 additions and 21 deletions
24
database/factories/RoleFactory.php
Normal file
24
database/factories/RoleFactory.php
Normal 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',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
database/migrations/2026_03_01_035158_create_roles_table.php
Normal file
30
database/migrations/2026_03_01_035158_create_roles_table.php
Normal 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');
|
||||
}
|
||||
};
|
||||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue