From e68e46541f62e8ca2ab348eab8ab69ac37bca0e1 Mon Sep 17 00:00:00 2001 From: Daniel Weissengruber Date: Thu, 4 Mar 2021 11:13:51 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=94=EF=B8=8F=20=20DB-Schema:=20Add=20?= =?UTF-8?q?Foreign=20Keys=20for=20faster=20queries?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2021_03_04_095453_add_foreign_keys.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 database/migrations/2021_03_04_095453_add_foreign_keys.php diff --git a/database/migrations/2021_03_04_095453_add_foreign_keys.php b/database/migrations/2021_03_04_095453_add_foreign_keys.php new file mode 100644 index 0000000..f9a40f2 --- /dev/null +++ b/database/migrations/2021_03_04_095453_add_foreign_keys.php @@ -0,0 +1,104 @@ +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'); + }); + } +} From 65d45ea787decc1c329c72689669d5f11740161b Mon Sep 17 00:00:00 2001 From: Daniel Weissengruber Date: Thu, 4 Mar 2021 12:25:14 +0100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20=20Fix=20website=5Fid=20data?= =?UTF-8?q?type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2021_03_04_095453_add_foreign_keys.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/migrations/2021_03_04_095453_add_foreign_keys.php b/database/migrations/2021_03_04_095453_add_foreign_keys.php index f9a40f2..b8226e1 100644 --- a/database/migrations/2021_03_04_095453_add_foreign_keys.php +++ b/database/migrations/2021_03_04_095453_add_foreign_keys.php @@ -14,42 +14,42 @@ class AddForeignKeys extends Migration public function up() { Schema::table('open_graph_scans', function (Blueprint $table) { - $table->integer('website_id')->unsigned()->change(); + $table->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->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->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); } From d8fd59b7390e32f70dadebb7e00ea709434ab004 Mon Sep 17 00:00:00 2001 From: Daniel Weissengruber Date: Thu, 4 Mar 2021 14:43:31 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20=20Update=20migration,=20ensure?= =?UTF-8?q?=20increment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2021_03_04_095453_add_foreign_keys.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/migrations/2021_03_04_095453_add_foreign_keys.php b/database/migrations/2021_03_04_095453_add_foreign_keys.php index b8226e1..d0892cf 100644 --- a/database/migrations/2021_03_04_095453_add_foreign_keys.php +++ b/database/migrations/2021_03_04_095453_add_foreign_keys.php @@ -14,42 +14,42 @@ class AddForeignKeys extends Migration public function up() { Schema::table('open_graph_scans', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('robot_scans', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('dns_scans', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('visual_diffs', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('cron_pings', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('uptime_scans', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('certificate_scans', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('crawled_pages', function (Blueprint $table) { - $table->bigInteger('website_id')->unsigned()->index()->change(); + $table->bigIncrements('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); } From df859541abb8ffd7f657acf099ab05c956d4f1d3 Mon Sep 17 00:00:00 2001 From: Daniel Weissengruber Date: Thu, 4 Mar 2021 15:08:49 +0100 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"=E2=9C=A8=20=20Update=20migration?= =?UTF-8?q?,=20ensure=20increment"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d8fd59b7390e32f70dadebb7e00ea709434ab004. --- .../2021_03_04_095453_add_foreign_keys.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/database/migrations/2021_03_04_095453_add_foreign_keys.php b/database/migrations/2021_03_04_095453_add_foreign_keys.php index d0892cf..b8226e1 100644 --- a/database/migrations/2021_03_04_095453_add_foreign_keys.php +++ b/database/migrations/2021_03_04_095453_add_foreign_keys.php @@ -14,42 +14,42 @@ class AddForeignKeys extends Migration public function up() { Schema::table('open_graph_scans', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('robot_scans', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('dns_scans', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('visual_diffs', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('cron_pings', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('uptime_scans', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('certificate_scans', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); Schema::table('crawled_pages', function (Blueprint $table) { - $table->bigIncrements('website_id')->unsigned()->index()->change(); + $table->bigInteger('website_id')->unsigned()->index()->change(); $table->foreign('website_id')->references('id')->on('websites')->onDelete('cascade'); }); }