Skip to content

FOUR-12885: Added migration to convert status column from enum to varchar #5872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
$isMysql = DB::getDriverName() === 'mysql';
if (!$isMysql) {
return;
}
// check if the column status is of type enum
$column = DB::selectOne('SHOW COLUMNS FROM users WHERE Field = "status"');
$isEnum = substr($column->Type, 0, 4) === 'enum';
if (!$isEnum) {
return;
}
// change the column status to varchar
DB::statement('ALTER TABLE users MODIFY COLUMN status VARCHAR(255) NOT NULL DEFAULT "ACTIVE"');
}

/**
* Reverse the migrations.
*/
public function down(): void
{
}
};