From d676a3471b4d94c567995448d0531354264c2176 Mon Sep 17 00:00:00 2001 From: Matthew Thornton <44626690+ThorntonMatthewD@users.noreply.github.com> Date: Thu, 7 Dec 2023 20:49:29 -0500 Subject: [PATCH 1/2] Add command to wipe events and orgs tables --- app/Console/Commands/ClearOrgsAndEvents.php | 60 +++++++++++++++++++++ tests/Feature/ClearOrgsAndEventsTest.php | 27 ++++++++++ 2 files changed, 87 insertions(+) create mode 100644 app/Console/Commands/ClearOrgsAndEvents.php create mode 100644 tests/Feature/ClearOrgsAndEventsTest.php diff --git a/app/Console/Commands/ClearOrgsAndEvents.php b/app/Console/Commands/ClearOrgsAndEvents.php new file mode 100644 index 00000000..3aac5f08 --- /dev/null +++ b/app/Console/Commands/ClearOrgsAndEvents.php @@ -0,0 +1,60 @@ +addMinutes(1); + } + + /** + * Execute the console command. + */ + public function handle() + { + $models_to_reset = [ + "Events" => "App\Models\Event", + "Orgs" => "App\Models\Org" + ]; + + ProgressBar::setFormatDefinition('simplified', '%current% of %max% tables wiped --- %message%'); + $progressIndicator = $this->output->createProgressBar(sizeof($models_to_reset)); + $progressIndicator->setFormat('simplified'); + + $progressIndicator->start(); + + foreach ($models_to_reset as $model_name => $model_namespace) { + $progressIndicator->setMessage("Resetting " . $model_name); + $model_namespace::truncate(); + $progressIndicator->advance(); + } + + $progressIndicator->setMessage("Events and Orgs have been successfully wiped."); + $progressIndicator->finish(); + } +} diff --git a/tests/Feature/ClearOrgsAndEventsTest.php b/tests/Feature/ClearOrgsAndEventsTest.php new file mode 100644 index 00000000..6cd4a6a7 --- /dev/null +++ b/tests/Feature/ClearOrgsAndEventsTest.php @@ -0,0 +1,27 @@ +count($expected_count)->create(); + + // Check pre-wipe count + expect(Event::count())->toEqual($expected_count); + expect(Org::count())->toEqual($expected_count); + + + Artisan::call(ClearOrgsAndEvents::class); + + // Ensure tables are squeaky clean + expect(Event::count())->toEqual(0); + expect(Org::count())->toEqual(0); +}); From 8e53252cdc5acc5640c31d7d661562dac63325b1 Mon Sep 17 00:00:00 2001 From: Matthew Thornton <44626690+ThorntonMatthewD@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:39:40 -0500 Subject: [PATCH 2/2] Update nomenclature related to database operations --- ...AndEvents.php => TruncateOrgsAndEvents.php} | 18 +++++++++--------- ...sTest.php => TruncateOrgsAndEventsTest.php} | 5 ++--- 2 files changed, 11 insertions(+), 12 deletions(-) rename app/Console/Commands/{ClearOrgsAndEvents.php => TruncateOrgsAndEvents.php} (70%) rename tests/Feature/{ClearOrgsAndEventsTest.php => TruncateOrgsAndEventsTest.php} (80%) diff --git a/app/Console/Commands/ClearOrgsAndEvents.php b/app/Console/Commands/TruncateOrgsAndEvents.php similarity index 70% rename from app/Console/Commands/ClearOrgsAndEvents.php rename to app/Console/Commands/TruncateOrgsAndEvents.php index 3aac5f08..c8cdbecc 100644 --- a/app/Console/Commands/ClearOrgsAndEvents.php +++ b/app/Console/Commands/TruncateOrgsAndEvents.php @@ -8,21 +8,21 @@ use Illuminate\Contracts\Console\Isolatable; use Symfony\Component\Console\Helper\ProgressBar; -class ClearOrgsAndEvents extends Command implements Isolatable +class TruncateOrgsAndEvents extends Command implements Isolatable { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'app:clear-orgs-and-events'; + protected $signature = 'app:truncate-orgs-and-events'; /** * The console command description. * * @var string */ - protected $description = 'Clears out the events and orgs tables for debugging purposes.'; + protected $description = 'Truncates the events and orgs tables for debugging purposes.'; /* * Lock timeout for the command. @@ -37,24 +37,24 @@ public function isolationLockExpiresAt(): DateTimeInterface|DateInterval */ public function handle() { - $models_to_reset = [ + $models_to_truncate = [ "Events" => "App\Models\Event", "Orgs" => "App\Models\Org" ]; - ProgressBar::setFormatDefinition('simplified', '%current% of %max% tables wiped --- %message%'); - $progressIndicator = $this->output->createProgressBar(sizeof($models_to_reset)); + ProgressBar::setFormatDefinition('simplified', '%current% of %max% tables truncated --- %message%'); + $progressIndicator = $this->output->createProgressBar(sizeof($models_to_truncate)); $progressIndicator->setFormat('simplified'); $progressIndicator->start(); - foreach ($models_to_reset as $model_name => $model_namespace) { - $progressIndicator->setMessage("Resetting " . $model_name); + foreach ($models_to_truncate as $model_name => $model_namespace) { + $progressIndicator->setMessage("Truncating " . $model_name); $model_namespace::truncate(); $progressIndicator->advance(); } - $progressIndicator->setMessage("Events and Orgs have been successfully wiped."); + $progressIndicator->setMessage("Events and Orgs have been successfully truncated."); $progressIndicator->finish(); } } diff --git a/tests/Feature/ClearOrgsAndEventsTest.php b/tests/Feature/TruncateOrgsAndEventsTest.php similarity index 80% rename from tests/Feature/ClearOrgsAndEventsTest.php rename to tests/Feature/TruncateOrgsAndEventsTest.php index 6cd4a6a7..8f4b5072 100644 --- a/tests/Feature/ClearOrgsAndEventsTest.php +++ b/tests/Feature/TruncateOrgsAndEventsTest.php @@ -1,6 +1,6 @@ count($expected_count)->create(); // Check pre-wipe count @@ -19,7 +18,7 @@ expect(Org::count())->toEqual($expected_count); - Artisan::call(ClearOrgsAndEvents::class); + Artisan::call(TruncateOrgsAndEvents::class); // Ensure tables are squeaky clean expect(Event::count())->toEqual(0);