Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add foreign-key constraint to configureerror table #2574

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
});
}
};