Prevent the creation of duplicated e-mails for a given Customer

This commit is contained in:
Antoine Le Gonidec 2024-07-11 12:38:06 +02:00
parent a61e14da47
commit 7a37ad5298
Signed by: vv221
GPG key ID: 636B78F91CEB80D8

View file

@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropUnicityFromCustomerEmails extends Migration {
class RelaxUnicityOfCustomerEmails extends Migration {
/**
* Run the migrations.
*
@ -16,6 +16,9 @@ class DropUnicityFromCustomerEmails extends Migration {
*/
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']);
});
}
@ -28,7 +31,10 @@ class DropUnicityFromCustomerEmails extends Migration {
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']);
});
}
}