Skip to content

Commit bbb131b

Browse files
committed
Check user status type to be varchar(255) ACTIVE
1 parent 1cac82d commit bbb131b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\DB;
5+
6+
return new class extends Migration {
7+
/**
8+
* Run the migrations.
9+
*/
10+
public function up(): void
11+
{
12+
$isMysql = DB::getDriverName() === 'mysql';
13+
if (!$isMysql) {
14+
return;
15+
}
16+
// check if the column status is of type enum
17+
$column = DB::selectOne('SHOW COLUMNS FROM users WHERE Field = "status"');
18+
$isEnum = substr($column->Type, 0, 4) === 'enum';
19+
if (!$isEnum) {
20+
return;
21+
}
22+
// change the column status to varchar
23+
DB::statement('ALTER TABLE users MODIFY COLUMN status VARCHAR(255) NOT NULL DEFAULT "ACTIVE"');
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
}
32+
};

0 commit comments

Comments
 (0)