Ensure emails entries are dropped when the related customer entry is deleted.
This commit is contained in:
parent
6e212c1513
commit
ba82668b76
3 changed files with 45 additions and 0 deletions
|
@ -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']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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;
|
Loading…
Reference in a new issue