From ba82668b76c038a166c09db1e0703959a8d33506 Mon Sep 17 00:00:00 2001 From: Antoine Le Gonidec Date: Wed, 10 Jul 2024 16:30:09 +0200 Subject: [PATCH] Ensure emails entries are dropped when the related customer entry is deleted. --- ...2710_drop_emails_on_customers_deletion.php | 41 +++++++++++++++++++ ...728_drop_unicity_from_customer_emails.php} | 4 ++ ..._mailbox_id_column_to_customers_table.php} | 0 3 files changed, 45 insertions(+) create mode 100644 database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php rename database/migrations/{2024_07_09_141535_drop_unicity_from_customer_emails.php => 2024_07_10_162728_drop_unicity_from_customer_emails.php} (82%) rename database/migrations/{2024_07_10_161855_add_user_id_column_to_customers_table.php => 2024_07_10_162735_add_mailbox_id_column_to_customers_table.php} (100%) diff --git a/database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php b/database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php new file mode 100644 index 0000000..7e15675 --- /dev/null +++ b/database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php @@ -0,0 +1,41 @@ + + */ + +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']); + }); + } +} diff --git a/database/migrations/2024_07_09_141535_drop_unicity_from_customer_emails.php b/database/migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php similarity index 82% rename from database/migrations/2024_07_09_141535_drop_unicity_from_customer_emails.php rename to database/migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php index 71b2fe1..329fa11 100644 --- a/database/migrations/2024_07_09_141535_drop_unicity_from_customer_emails.php +++ b/database/migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php @@ -1,4 +1,8 @@ + */ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; diff --git a/database/migrations/2024_07_10_161855_add_user_id_column_to_customers_table.php b/database/migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php similarity index 100% rename from database/migrations/2024_07_10_161855_add_user_id_column_to_customers_table.php rename to database/migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php