40 lines
893 B
PHP
40 lines
893 B
PHP
|
<?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;
|
||
|
|
||
|
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']);
|
||
|
});
|
||
|
}
|
||
|
}
|