-
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.
Add foreign-key constraint to configureerror table (#2574)
This PR adds a foreign-key constraint to the `configureerror` table in support of #2093.
- Loading branch information
1 parent
58535a5
commit a0061f0
Showing
2 changed files
with
31 additions
and
1 deletion.
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
31 changes: 31 additions & 0 deletions
31
database/migrations/2024_11_18_113619_configure_error_foreign_key.php
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,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']); | ||
}); | ||
} | ||
}; |