File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments