-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to generate multiple photos
- Loading branch information
1 parent
273c5ce
commit 841e02e
Showing
3 changed files
with
90 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
use function Laravel\Prompts\progress; | ||
|
||
class GenerateRandomPhotos extends Command | ||
{ | ||
protected $signature = 'app:generate-random-photos'; | ||
|
||
public function handle(): void | ||
{ | ||
$user = User::query() | ||
->where('email', '[email protected]') | ||
->first(); | ||
|
||
$bar = progress('Generating 1M photos with tags...', 1_000_000); | ||
|
||
$bar->start(); | ||
|
||
$now = now()->toDateTimeString(); | ||
|
||
for ($i = 0; $i < 200; $i++) { | ||
$photos = []; | ||
$items = []; | ||
$tags = []; | ||
|
||
for ($j = 0; $j < 5000; $j++) { | ||
$photos[] = [ | ||
'user_id' => $user->id, | ||
'path' => 'photos/default.jpg', | ||
'created_at' => $now, | ||
'updated_at' => $now, | ||
]; | ||
} | ||
|
||
DB::table('photos')->insert($photos); | ||
|
||
for ($j = 0; $j < 5000; $j++) { | ||
$items[] = [ | ||
'photo_id' => $i * 5000 + $j + 2, | ||
'item_id' => random_int(1, 300), | ||
'picked_up' => 0, | ||
'recycled' => 0, | ||
'quantity' => 1, | ||
'created_at' => $now, | ||
'updated_at' => $now, | ||
]; | ||
} | ||
|
||
DB::table('photo_items')->insert($items); | ||
|
||
for ($k = 0; $k < 5000; $k++) { | ||
$tags[] = [ | ||
'photo_item_id' => $i * 5000 + $k + 1, | ||
'tag_id' => random_int(1, 1500), | ||
'created_at' => $now, | ||
'updated_at' => $now, | ||
]; | ||
} | ||
|
||
DB::table('photo_item_tag')->insert($tags); | ||
|
||
$bar->advance(5000); | ||
} | ||
|
||
$bar->finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,14 @@ public function run(): void | |
'password' => Hash::make('password'), | ||
]); | ||
|
||
$team = Team::factory()->create([ | ||
'name' => 'Team A', | ||
'user_id' => $userA->id, | ||
'personal_team' => true, | ||
]); | ||
|
||
$userA->teams()->attach($team); | ||
|
||
tap(User::factory()->create([ | ||
'name' => 'Waste Wizard', | ||
'email' => '[email protected]', | ||
|
@@ -51,13 +59,5 @@ public function run(): void | |
'email' => '[email protected]', | ||
'password' => Hash::make('password'), | ||
]); | ||
|
||
$team = Team::factory()->create([ | ||
'name' => 'Team A', | ||
'user_id' => $userA->id, | ||
'personal_team' => true, | ||
]); | ||
|
||
$userA->teams()->attach($team); | ||
} | ||
} |