Skip to content

Commit

Permalink
Changes the unique constraint for contacts (#203)
Browse files Browse the repository at this point in the history
Changes the unique constraint for contacts from 'email' to ['account_id', 'email'] (#203)

I think the unique constraint is too eager for the contacts table. 

If a user wants to add a contact with an already existing email, they'll encounter an error. Since they aren't the one who added that email to their contacts, it will be confusing & frustrating. 

I think this is a bug and the constraint should be `['account_id', 'email']`.
  • Loading branch information
Yamamoto Kadir authored and djaiss committed Jun 12, 2017
1 parent 5000554 commit 071dc4e
Showing 1 changed file with 36 additions and 0 deletions.
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeUniqueConstraintForContacts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contacts', function (Blueprint $table) {
$table->dropUnique(['email']);

$table->unique(['account_id', 'email'], 'unique_for_each_account_email_pair');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contacts', function (Blueprint $table) {
$table->dropUnique('unique_for_each_account_email_pair');

$table->unique('email');
});
}
}

0 comments on commit 071dc4e

Please sign in to comment.