Ensure emails entries are dropped when the related customer entry is deleted.

This commit is contained in:
Antoine Le Gonidec 2024-07-10 16:30:09 +02:00
parent 6e212c1513
commit ba82668b76
Signed by: vv221
GPG key ID: 636B78F91CEB80D8
3 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,41 @@
<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Symfony\Component\Console\Output\ConsoleOutput;
use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer;
class DropEmailsOnCustomersDeletion extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::table('emails', function (Blueprint $table) {
// Ensure emails entries are dropped when the related customer entry is deleted.
$table
->foreign('customer_id')
->references('id')
->on('customers')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::table('emails', function (Blueprint $table) {
// Drop the foreign key constraint.
$table->dropForeign(['customer_id']);
});
}
}

View file

@ -1,4 +1,8 @@
<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;