-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1512 from younginnovations/1491-email-addresses-f…
…or-sign-in-are-case-sensitive Review: 1491-email-addresses-for-sign-in-are-case-sensitive
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
/node_modules | ||
/public/hot | ||
/public/storage | ||
/public/css | ||
/public/js | ||
/storage/*.key | ||
/vendor | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
database/migrations/2024_07_22_091222_update_email_collation_in_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Constants\DBTables; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
/* | ||
* Change source: https://github.com/younginnovations/iatipublisher/issues/1491 | ||
*/ | ||
return new class extends Migration { | ||
/** | ||
* Making email field case-insensitive by: | ||
* 1. Creating citext extension. Citext datatype makes string values case-insensitive on db level. | ||
* 2. Change email field type to citext. | ||
* 3. Refresh unique constraint in email field. | ||
* | ||
* @return void | ||
*/ | ||
public function up(): void | ||
{ | ||
DB::statement('CREATE EXTENSION IF NOT EXISTS citext;'); | ||
|
||
DB::statement('ALTER TABLE ' . DBTables::USERS . ' ALTER COLUMN email TYPE citext USING email::citext;'); | ||
|
||
$uniqueConstraintExists = DB::select( | ||
" | ||
SELECT constraint_name | ||
FROM information_schema.table_constraints | ||
WHERE table_name = '" . DBTables::USERS . "' | ||
AND constraint_type = 'UNIQUE' | ||
AND constraint_name = 'users_email_unique'" | ||
); | ||
|
||
if (empty($uniqueConstraintExists)) { | ||
Schema::table(DBTables::USERS, function (Blueprint $table) { | ||
$table->unique('email'); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
* Basically | ||
* 1. Drop unique constraint. | ||
* 2. Change email field type to varchar. | ||
* 3. Add unique constraint again. | ||
* | ||
* @return void | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table(DBTables::USERS, function (Blueprint $table) { | ||
$table->dropUnique('users_email_unique'); | ||
}); | ||
|
||
DB::statement('ALTER TABLE ' . DBTables::USERS . ' ALTER COLUMN email TYPE varchar USING email::varchar;'); | ||
|
||
Schema::table(DBTables::USERS, function (Blueprint $table) { | ||
$table->unique('email'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters