-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move "Cleanup Database" functionality to new artisan command (#2580)
- Loading branch information
1 parent
74ee534
commit 62feae3
Showing
7 changed files
with
324 additions
and
324 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,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Utils\DatabaseCleanupUtils; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class CleanDatabase extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
*/ | ||
protected $signature = 'db:clean'; | ||
|
||
/** | ||
* The console command description. | ||
*/ | ||
protected $description = 'Prune unused records from the CDash database'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): void | ||
{ | ||
// Reconfigure laravel to log to stderr for the rest of this command. | ||
config(['logging.default' => 'stderr']); | ||
|
||
Log::info("Deleting unused rows from `banner`"); | ||
$num_deleted = DB::delete("DELETE FROM banner WHERE projectid != 0 AND | ||
NOT EXISTS (SELECT 1 FROM project WHERE project.id = banner.projectid)"); | ||
Log::info("{$num_deleted} rows deleted from `banner`"); | ||
|
||
DatabaseCleanupUtils::deleteUnusedRows('dailyupdate', 'projectid', 'project'); | ||
|
||
DatabaseCleanupUtils::deleteUnusedRows('buildfailuredetails', 'id', 'buildfailure', 'detailsid'); | ||
DatabaseCleanupUtils::deleteUnusedRows('configure', 'id', 'build2configure', 'configureid'); | ||
DatabaseCleanupUtils::deleteUnusedRows('coveragefile', 'id', 'coverage', 'fileid'); | ||
DatabaseCleanupUtils::deleteUnusedRows('dailyupdatefile', 'dailyupdateid', 'dailyupdate'); | ||
DatabaseCleanupUtils::deleteUnusedRows('note', 'id', 'build2note', 'noteid'); | ||
DatabaseCleanupUtils::deleteUnusedRows('testoutput', 'id', 'build2test', 'outputid'); | ||
DatabaseCleanupUtils::deleteUnusedRows('uploadfile', 'id', 'build2uploadfile', 'fileid'); | ||
|
||
Log::info("Deleting unused rows from `image`"); | ||
$num_deleted = DB::delete("DELETE FROM image WHERE | ||
NOT EXISTS (SELECT 1 FROM project WHERE project.imageid = image.id) AND | ||
NOT EXISTS (SELECT 1 FROM test2image WHERE test2image.imgid = image.id)"); | ||
Log::info("{$num_deleted} rows deleted from `image`"); | ||
} | ||
} |
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
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
Oops, something went wrong.