diff --git a/app/Console/Commands/DeleteOldData.php b/app/Console/Commands/DeleteOldData.php deleted file mode 100644 index bf2dcfe3..00000000 --- a/app/Console/Commands/DeleteOldData.php +++ /dev/null @@ -1,44 +0,0 @@ -where('created_at', '<', Carbon::now()->subMonths(self::MONTHS_TO_KEEP)) - ->forceDelete(); - - Event::withTrashed() - ->where('created_at', '<', Carbon::now()->subMonths(self::MONTHS_TO_KEEP)) - ->forceDelete(); - return 0; - } -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1bc8f7c6..84b2e04f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->command(SendDiscordNotifications::class)->everyMinute(); - $schedule->command(DeleteOldData::class)->daily(); $schedule->command(OptimiseTables::class)->daily(); } diff --git a/tests/Console/Commands/DeleteOldDataTest.php b/tests/Console/Commands/DeleteOldDataTest.php deleted file mode 100644 index 4dfbf6c2..00000000 --- a/tests/Console/Commands/DeleteOldDataTest.php +++ /dev/null @@ -1,115 +0,0 @@ -delete(); - DB::table('events')->delete(); - } - - public function testItDoesntDeleteValidMeasures() - { - $flowMeasure = FlowMeasure::factory()->create(); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('flow_measures', 1); - $this->assertDatabaseHas( - 'flow_measures', - [ - 'id' => $flowMeasure->id, - ] - ); - } - - public function testItDeletesExpiredMeasures() - { - FlowMeasure::factory() - ->afterCreating(function (FlowMeasure $measure) { - $measure->created_at = Carbon::now()->subMonths(2)->subDay(); - $measure->save(); - }) - ->create(); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('flow_measures', 0); - } - - public function testItDeletesExpiredSoftDeletedMeasures() - { - $flowMeasure = FlowMeasure::factory() - ->afterCreating(function (FlowMeasure $measure) { - $measure->created_at = Carbon::now()->subMonths(2)->subDay(); - $measure->save(); - }) - ->create(); - $flowMeasure->delete(); - $this->assertDatabaseCount('flow_measures', 1); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('flow_measures', 0); - } - - public function testItDoesntDeleteValidEvents() - { - $event = Event::factory()->create(); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('events', 1); - $this->assertDatabaseHas( - 'events', - [ - 'id' => $event->id, - ] - ); - } - - public function testItDeletesExpiredEvents() - { - Event::factory() - ->afterCreating(function (Event $event) { - $event->created_at = Carbon::now()->subMonths(2)->subDay(); - $event->save(); - }) - ->create(); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('events', 0); - } - - public function testItDeletesExpiredSoftDeletedEvents() - { - $event = Event::factory() - ->afterCreating(function (Event $event) { - $event->created_at = Carbon::now()->subMonths(2)->subDay(); - $event->save(); - }) - ->create(); - - $event->delete(); - $this->assertDatabaseCount('events', 1); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('events', 0); - } - - public function testItDeletesFlowMeasuresAssociatedWithExpiredEvents() - { - $flowMeasure = FlowMeasure::factory()->withEvent()->create(); - $flowMeasure->event->created_at = Carbon::now()->subMonths(2)->subDay(); - $flowMeasure->event->save(); - - $this->artisan('data:delete-old'); - $this->assertDatabaseCount('events', 0); - $this->assertDatabaseCount('flow_measures', 0); - } -}