Skip to content

Commit

Permalink
Merge pull request #157 from biigle/patch-1
Browse files Browse the repository at this point in the history
Drop constraints on proposal and candidate tables
  • Loading branch information
mzur authored Jan 31, 2024
2 parents 5497825 + 548fc00 commit c77e573
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public function up()
{
Schema::create('maia_training_proposal_feature_vectors', function (Blueprint $table) {
$table->unsignedBigInteger('id');
// This constraint turned out to be very problematic. When a MAIA job
// is deleted, the deletion will cascade to training proposals and then
// to their feature vectors (here). Since this column has no index, the
// deletion of feature vectors is *very* inefficient on a large table
// (which is expected with MAIA). The deletion takes hours to days!
//
// The foreign key constraint is dropped in a later migration because
// individual training proposals cannot be deleted. Deletion of feature
// vectors will then cascade from the deletion of the job, which is
// indexed below.
$table->foreign('id')
->references('id')
->on('maia_training_proposals')
Expand All @@ -31,6 +41,8 @@ public function up()

Schema::create('maia_annotation_candidate_feature_vectors', function (Blueprint $table) {
$table->unsignedBigInteger('id');
// See comment on the foreign key constraint above. The same is true
// here, too.
$table->foreign('id')
->references('id')
->on('maia_annotation_candidates')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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()
{
Schema::table('maia_training_proposal_feature_vectors', function (Blueprint $table) {
// Delete queries were terribly slow with this constraint. Also, individual
// proposals could not be deleted anyway. This is dropped to make the delete
// query (cascaded from deletion of the whole MAIA job) more efficient.
//
// See also comment in: 2023_12_12_150900_create_feature_vectors_tables.php
$table->dropForeign(['id']);
});

Schema::table('maia_annotation_candidate_feature_vectors', function (Blueprint $table) {
// See comment above. This is the same.
$table->dropForeign(['id']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('maia_training_proposal_feature_vectors', function (Blueprint $table) {
$table->foreign('id')
->references('id')
->on('maia_training_proposals')
->onDelete('cascade');
});

Schema::table('maia_annotation_candidate_feature_vectors', function (Blueprint $table) {
$table->foreign('id')
->references('id')
->on('maia_annotation_candidates')
->onDelete('cascade');
});
}
};
4 changes: 2 additions & 2 deletions tests/AnnotationCandidateFeatureVectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Biigle\Tests\Modules\Maia;

use Biigle\Modules\Maia\AnnotationCandidate;
use Biigle\Modules\Maia\AnnotationCandidateFeatureVector;
use Biigle\Modules\Maia\MaiaJob;
use Biigle\Shape;
use TestCase;

Expand All @@ -19,7 +19,7 @@ public function testAttributes()
public function testCascadeDelete()
{
$model = AnnotationCandidateFeatureVector::factory()->create();
AnnotationCandidate::find($model->id)->delete();
MaiaJob::find($model->job_id)->delete();
$this->assertNull($model->fresh());
}
}
4 changes: 2 additions & 2 deletions tests/TrainingProposalFeatureVectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Biigle\Tests\Modules\Maia;

use Biigle\Modules\Maia\TrainingProposal;
use Biigle\Modules\Maia\MaiaJob;
use Biigle\Modules\Maia\TrainingProposalFeatureVector;
use Biigle\Shape;
use TestCase;
Expand All @@ -19,7 +19,7 @@ public function testAttributes()
public function testCascadeDelete()
{
$model = TrainingProposalFeatureVector::factory()->create();
TrainingProposal::find($model->id)->delete();
MaiaJob::find($model->job_id)->delete();
$this->assertNull($model->fresh());
}
}

0 comments on commit c77e573

Please sign in to comment.