Skip to content

Commit

Permalink
Replaces surrogate key with a composite key
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Aug 3, 2015
1 parent ba8cded commit a568ae5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 12 additions & 6 deletions api/app/Models/SocialLogin.php
Expand Up @@ -3,16 +3,22 @@
class SocialLogin extends BaseModel
{
/**
* The primary key for the model.
* The attributes that are mass assignable.
*
* @var string
* @var array
*/
protected $primaryKey = 'social_login_id';
protected $fillable = ['provider', 'token'];

/**
* The attributes that are mass assignable.
* Overrides UuidTrait boot method.
*
* @var array
* We override it with an empty method as we simply just want to prevent the
* event registration to automatically create a UUID primary key, as we do
* not use that in this model.
*
* @return void
*/
protected $fillable = ['provider', 'token'];
protected static function bootUuidTrait()
{
}
}
Expand Up @@ -17,14 +17,12 @@ public function up()
{
$modelClass = static::MODEL;
Schema::create($modelClass::getTableName(), function (Blueprint $table) use ($modelClass) {
$table->uuid('social_login_id');

$table->uuid('user_id');
$table->string('provider', 16);
$table->string('token');
$table->timestamps();

$table->primary('social_login_id');
$table->primary(['user_id', 'provider']);
$table->foreign('user_id')
->references('user_id')->on(User::getTableName())
->onDelete('cascade');
Expand Down

0 comments on commit a568ae5

Please sign in to comment.