Skip to content

Commit

Permalink
Add foreign-key constraint to configureerror table (#2574)
Browse files Browse the repository at this point in the history
This PR adds a foreign-key constraint to the `configureerror` table in
support of #2093.
  • Loading branch information
zackgalbreath authored Nov 18, 2024
1 parent 58535a5 commit a0061f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/cdash/include/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ function remove_build($buildid)
if (count($configureids) > 0) {
$configureids_prepare_array = $db->createPreparedArray(count($configureids));
DB::delete("DELETE FROM configure WHERE id IN $configureids_prepare_array", $configureids);
DB::delete("DELETE FROM configureerror WHERE configureid IN $configureids_prepare_array", $configureids);
}

// coverage files are kept unless they are shared
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
echo "Adding foreign key constraint configureerror(configureid)->configure(id)...";
$num_deleted = DB::delete("DELETE FROM configureerror WHERE configureid NOT IN (SELECT id FROM configure)");
echo $num_deleted . ' invalid rows deleted' . PHP_EOL;
Schema::table('configureerror', function (Blueprint $table) {
$table->foreign('configureid')->references('id')->on('configure')->cascadeOnDelete();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('configureerror', function (Blueprint $table) {
$table->dropForeign(['configureid']);
});
}
};

0 comments on commit a0061f0

Please sign in to comment.