-
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 constraints for all userids (#1656)
This PR makes progress towards #1442 by adding foreign key constraints to every column which references user IDs.
- Loading branch information
1 parent
e9272a7
commit 9f71c66
Showing
2 changed files
with
147 additions
and
0 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
144 changes: 144 additions & 0 deletions
144
database/migrations/2023_08_14_200318_user_foreign_keys.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,144 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
echo 'Adding userid foreign key to authtoken table...' . PHP_EOL; | ||
Schema::table('authtoken', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to buildemail table...' . PHP_EOL; | ||
Schema::table('buildemail', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to buildnote table...' . PHP_EOL; | ||
Schema::table('buildnote', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to coveragefile2user table...' . PHP_EOL; | ||
Schema::table('coveragefile2user', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to labelemail table...' . PHP_EOL; | ||
Schema::table('labelemail', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to lockout table...' . PHP_EOL; | ||
Schema::table('lockout', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to password table...' . PHP_EOL; | ||
Schema::table('password', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to site2user table...' . PHP_EOL; | ||
Schema::table('site2user', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to user2project table...' . PHP_EOL; | ||
Schema::table('user2project', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to user2repository table...' . PHP_EOL; | ||
Schema::table('user2repository', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
|
||
echo 'Adding userid foreign key to userstatistics table...' . PHP_EOL; | ||
Schema::table('userstatistics', function (Blueprint $table) { | ||
$table->integer('userid')->nullable(false)->change(); | ||
$table->foreign('userid')->references('id')->on('user')->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('authtoken', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('buildemail', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('buildnote', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('coveragefile2user', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('labelemail', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('lockout', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('password', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('site2user', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('user2project', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('user2repository', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
|
||
Schema::table('userstatistics', function (Blueprint $table) { | ||
$table->integer('userid')->change(); | ||
$table->dropForeign(['userid']); | ||
}); | ||
} | ||
}; |