Verified Commit df6006ff authored by Korko's avatar Korko
Browse files

Add constraints on foreign relations

parent 6be2b34a
...@@ -17,7 +17,7 @@ class CreateMailsTable extends Migration ...@@ -17,7 +17,7 @@ class CreateMailsTable extends Migration
Schema::create('mails', function (Blueprint $table) { Schema::create('mails', function (Blueprint $table) {
$table->id(); $table->id();
$table->enum('delivery_status', Mail::$deliveryStatuses); $table->enum('delivery_status', Mail::$deliveryStatuses);
$table->foreignId('draw_id')->constrained(); $table->foreignId('draw_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
$table->unsignedTinyInteger('version')->default(0); $table->unsignedTinyInteger('version')->default(0);
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -15,11 +15,11 @@ class CreateParticipantsTable extends Migration ...@@ -15,11 +15,11 @@ class CreateParticipantsTable extends Migration
{ {
Schema::create('participants', function (Blueprint $table) { Schema::create('participants', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('draw_id')->constrained(); $table->foreignId('draw_id')->constrained()->cascadeOnDelete();
$table->longText('name'); $table->longText('name');
$table->longText('email'); $table->longText('email');
$table->foreignId('target_id')->nullable()->constrained('participants'); $table->foreignId('target_id')->nullable()->constrained('participants')->cascadeOnDelete();
$table->foreignId('mail_id')->constrained(); $table->foreignId('mail_id')->constrained()->cascadeOnDelete();
$table->timestamps(); $table->timestamps();
}); });
} }
......
...@@ -15,9 +15,9 @@ class CreateDearSantasTable extends Migration ...@@ -15,9 +15,9 @@ class CreateDearSantasTable extends Migration
{ {
Schema::create('dear_santas', function (Blueprint $table) { Schema::create('dear_santas', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('sender_id')->constrained('participants'); $table->foreignId('sender_id')->constrained('participants')->cascadeOnDelete();
$table->longText('mail_body'); $table->longText('mail_body');
$table->foreignId('mail_id')->constrained(); $table->foreignId('mail_id')->constrained()->cascadeOnDelete();
}); });
} }
......
...@@ -14,8 +14,8 @@ class CreateExclusionsTable extends Migration ...@@ -14,8 +14,8 @@ class CreateExclusionsTable extends Migration
public function up() public function up()
{ {
Schema::create('exclusions', function (Blueprint $table) { Schema::create('exclusions', function (Blueprint $table) {
$table->foreignId('participant_id')->constrained(); $table->foreignId('participant_id')->constrained()->cascadeOnDelete();
$table->foreignId('exclusion_id')->constrained('participants'); $table->foreignId('exclusion_id')->constrained('participants')->cascadeOnDelete();
}); });
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment