-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✔️ DB-Schema: Add Foreign Keys for faster queries
- Loading branch information
1 parent
0175d87
commit e68e465
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
database/migrations/2021_03_04_095453_add_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,104 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class AddForeignKeys extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('open_graph_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('robot_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('dns_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('visual_diffs', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('cron_pings', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('uptime_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('certificate_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
|
||
Schema::table('crawled_pages', function (Blueprint $table) { | ||
$table->integer('website_id')->unsigned()->change(); | ||
$table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('open_graph_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('robot_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('dns_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('visual_diffs', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('cron_pings', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('uptime_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('certificate_scans', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
|
||
Schema::table('crawled_pages', function (Blueprint $table) { | ||
$table->integer('website_id')->change(); | ||
$table->dropForeign('website_id'); | ||
}); | ||
} | ||
} |