fix: add constraint actions to db structure
This commit adds several missing "cascade delete" actions to relationships on database tables. This effectively fixes errors while trying to delete user accounts because of pending child records. Additionally, the observers for applications and vacancies were removed, since they are now obsolete. The account deletion system was also refactored.
This commit is contained in:
@@ -46,7 +46,8 @@ class CreateProfilesTable extends Migration
|
||||
|
||||
$table->foreign('userID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,8 @@ class CreateApplicationsTable extends Migration
|
||||
|
||||
$table->foreign('applicantUserID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,8 @@ class CreateVotesTable extends Migration
|
||||
|
||||
$table->foreign('userID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,8 @@ class CreateAppointmentsTable extends Migration
|
||||
|
||||
$table->foreign('applicationID')
|
||||
->references('id')
|
||||
->on('applications');
|
||||
->on('applications')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -41,7 +41,8 @@ class CreateResponsesTable extends Migration
|
||||
// A better way would be to link responses directly to vacancies, that subsquently have a form
|
||||
$table->foreign('responseFormID')
|
||||
->references('id')
|
||||
->on('forms');
|
||||
->on('forms')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -38,8 +38,8 @@ class VotesHasApplication extends Migration
|
||||
$table->bigInteger('application_id')->unsigned();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('vote_id')->references('id')->on('votes');
|
||||
$table->foreign('application_id')->references('id')->on('applications');
|
||||
$table->foreign('vote_id')->references('id')->on('votes')->cascadeOnDelete();
|
||||
$table->foreign('application_id')->references('id')->on('applications')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,8 @@ class CreateBansTable extends Migration
|
||||
|
||||
$table->foreign('userID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -41,11 +41,13 @@ class CreateCommentsTable extends Migration
|
||||
|
||||
$table->foreign('authorID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->foreign('applicationID')
|
||||
->references('id')
|
||||
->on('applications');
|
||||
->on('applications')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -27,11 +27,13 @@ class CreateAbsencesTable extends Migration
|
||||
|
||||
$table->foreign('requesterID')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreign('reviewer')
|
||||
->references('id')
|
||||
->on('users');
|
||||
->on('users')
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->dropColumn('account_tokens');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('account_tokens')->after('password')->nullable();
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user