Skip to content

A self-hosted media server and file management system

feat: basic demo seeder

aminnausin135d5486d12e
diff --git a/app/Console/Commands/ResetDemo.php b/app/Console/Commands/ResetDemo.php
new file mode 100644
index 00000000..0f06ed9a
--- /dev/null
+++ b/app/Console/Commands/ResetDemo.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Artisan;
+
+class ResetDemo extends Command {
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'demo:reset';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Reset the app to a preconfigured demo state';
+
+ /**
+ * Execute the console command.
+ */
+ public function handle() {
+ if (!str_contains(strtolower(config('database.connections.pgsql.database', 'mediaServer')), 'demo')) {
+ $this->error("Not using a demo database");
+ return;
+ }
+ $this->info('Resetting demo database...');
+
+ Artisan::call('migrate:fresh', ['--force' => true]);
+ Artisan::call('db:seed', [
+ '--class' => 'DemoSeeder',
+ '--force' => true
+ ]);
+
+ Artisan::call('mediaServer:scan', ['library_id' => 1]);
+
+ $this->info('✅ Demo DB reset complete.');
+ }
+}
diff --git a/database/factories/SubtaskFactory.php b/database/factories/SubtaskFactory.php
new file mode 100644
index 00000000..051735b4
--- /dev/null
+++ b/database/factories/SubtaskFactory.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/**
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Subtask>
+ */
+class SubtaskFactory extends Factory
+{
+ /**
+ * Define the model's default state.
+ *
+ * @return array<string, mixed>
+ */
+ public function definition(): array
+ {
+ return [
+ //
+ ];
+ }
+}
diff --git a/database/factories/TaskFactory.php b/database/factories/TaskFactory.php
new file mode 100644
index 00000000..e4632799
--- /dev/null
+++ b/database/factories/TaskFactory.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/**
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Task>
+ */
+class TaskFactory extends Factory
+{
+ /**
+ * Define the model's default state.
+ *
+ * @return array<string, mixed>
+ */
+ public function definition(): array
+ {
+ return [
+ //
+ ];
+ }
+}
diff --git a/database/seeders/DemoSeeder.php b/database/seeders/DemoSeeder.php
new file mode 100644
index 00000000..674f0e7a
--- /dev/null
+++ b/database/seeders/DemoSeeder.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\Metadata;
+use App\Models\Record;
+use App\Models\Tag;
+use App\Models\User;
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+use Illuminate\Support\Facades\Hash;
+
+class DemoSeeder extends Seeder {
+ /**
+ * Run the database seeds.
+ */
+ public function run(): void {
+ User::firstOrCreate(
+ ['email' => '[email protected]'],
+ [
+ 'name' => 'demo',
+ 'email_verified_at' => now(),
+ 'password' => Hash::make('mediaserver'),
+ ]
+ );
+ User::factory(5)->create();
+ Tag::factory(15)->create();
+ $metadata = Metadata::factory()->count(10)->create();
+
+ foreach ($metadata as $entry) {
+ Record::factory()->count(2)->create([
+ 'user_id' => 1,
+ 'metadata_id' => $entry->id,
+ ]);
+ }
+ }
+}