Skip to content

Commit 135d548

Browse files
committed
feat: basic demo seeder
1 parent 9d84c92 commit 135d548

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

app/Console/Commands/ResetDemo.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Artisan;
7+
8+
class ResetDemo extends Command {
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'demo:reset';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Reset the app to a preconfigured demo state';
22+
23+
/**
24+
* Execute the console command.
25+
*/
26+
public function handle() {
27+
if (!str_contains(strtolower(config('database.connections.pgsql.database', 'mediaServer')), 'demo')) {
28+
$this->error("Not using a demo database");
29+
return;
30+
}
31+
$this->info('Resetting demo database...');
32+
33+
Artisan::call('migrate:fresh', ['--force' => true]);
34+
Artisan::call('db:seed', [
35+
'--class' => 'DemoSeeder',
36+
'--force' => true
37+
]);
38+
39+
Artisan::call('mediaServer:scan', ['library_id' => 1]);
40+
41+
$this->info('✅ Demo DB reset complete.');
42+
}
43+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Subtask>
9+
*/
10+
class SubtaskFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
//
21+
];
22+
}
23+
}

database/factories/TaskFactory.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Task>
9+
*/
10+
class TaskFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
//
21+
];
22+
}
23+
}

database/seeders/DemoSeeder.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use App\Models\Metadata;
6+
use App\Models\Record;
7+
use App\Models\Tag;
8+
use App\Models\User;
9+
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
10+
use Illuminate\Database\Seeder;
11+
use Illuminate\Support\Facades\Hash;
12+
13+
class DemoSeeder extends Seeder {
14+
/**
15+
* Run the database seeds.
16+
*/
17+
public function run(): void {
18+
User::firstOrCreate(
19+
['email' => 'demo@mediaserver.me'],
20+
[
21+
'name' => 'demo',
22+
'email_verified_at' => now(),
23+
'password' => Hash::make('mediaserver'),
24+
]
25+
);
26+
User::factory(5)->create();
27+
Tag::factory(15)->create();
28+
$metadata = Metadata::factory()->count(10)->create();
29+
30+
foreach ($metadata as $entry) {
31+
Record::factory()->count(2)->create([
32+
'user_id' => 1,
33+
'metadata_id' => $entry->id,
34+
]);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)