40 lines
1 KiB
PHP
40 lines
1 KiB
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 RelaxUnicityOfCustomerEmails extends Migration {
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up() {
|
|
Schema::table('emails', function (Blueprint $table) {
|
|
// Ensure a same e-mail can only be set once for a given Customer.
|
|
$table->unique(['email', 'customer_id']);
|
|
// Allow a same e-mail to be set to multiple Customers.
|
|
$table->dropUnique(['email']);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down() {
|
|
Schema::table('emails', function (Blueprint $table) {
|
|
// TODO: Remove all duplicated e-mails.
|
|
// Restore the unicity of e-mails.
|
|
$table->unique('email');
|
|
// Drop the redundant unicity constraint.
|
|
$table->dropUnique(['email', 'customer_id']);
|
|
});
|
|
}
|
|
}
|