freescout-restricted-customers/Database/Migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php

41 lines
1,010 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;
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']);
});
}
}