Changeset View
Changeset View
Standalone View
Standalone View
src/database/migrations/2021_11_10_100000_add_group_name_column.php
- This file was added.
<?php | |||||
use Illuminate\Database\Migrations\Migration; | |||||
use Illuminate\Database\Schema\Blueprint; | |||||
use Illuminate\Support\Facades\Schema; | |||||
use Illuminate\Support\Facades\DB; | |||||
// phpcs:ignore | |||||
class AddGroupNameColumn extends Migration | |||||
{ | |||||
/** | |||||
* Run the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function up() | |||||
{ | |||||
Schema::table( | |||||
'groups', | |||||
function (Blueprint $table) { | |||||
$table->string('name')->nullable()->after('email'); | |||||
} | |||||
); | |||||
// Fill the name with the local part of the email address | |||||
DB::table('groups')->update([ | |||||
'name' => DB::raw("SUBSTRING_INDEX(`email`, '@', 1)") | |||||
]); | |||||
Schema::table( | |||||
mollekopf: Maybe add an index for the name field for the uniqueness checks?
Maybe add a uniqueness… | |||||
Done Inline ActionsName alone cannot be unique. An index on name + email does not really make sense to me. Maybe this table should have a domain or domain_id column, but it shouldn't be a stopper. machniak: Name alone cannot be unique. An index on name + email does not really make sense to me. Maybe… | |||||
Not Done Inline ActionsThe index on name would not be for uniqueness, but for lookup performance. The name + domain index would indeed be what we're after. I agree this is not a blocker. mollekopf: The index on name would not be for uniqueness, but for lookup performance.
The name + domain… | |||||
'groups', | |||||
function (Blueprint $table) { | |||||
$table->string('name')->nullable(false)->change(); | |||||
} | |||||
); | |||||
} | |||||
/** | |||||
* Reverse the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function down() | |||||
{ | |||||
Schema::table( | |||||
'groups', | |||||
function (Blueprint $table) { | |||||
$table->dropColumn('name'); | |||||
} | |||||
); | |||||
} | |||||
} |
Maybe add an index for the name field for the uniqueness checks?
Maybe add a uniqueness contraint for name + email (so the uniqueness check in the role only additionally checks that you don't reuse the same name for any of your domains)?