doctor-appointment-system/app/Database/Migrations/2026-04-13-120000_DropNameFromUsers.php
2026-04-13 19:04:12 +05:30

40 lines
998 B
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class DropNameFromUsers extends Migration
{
public function up(): void
{
if ($this->db->fieldExists('name', 'users')) {
$this->forge->dropColumn('users', 'name');
}
}
public function down(): void
{
if ($this->db->fieldExists('name', 'users')) {
return;
}
$this->forge->addColumn('users', [
'name' => [
'type' => 'VARCHAR',
'constraint' => 100,
'null' => true,
'after' => 'id',
],
]);
if ($this->db->fieldExists('first_name', 'users') && $this->db->fieldExists('last_name', 'users')) {
$this->db->query("
UPDATE users
SET name = TRIM(CONCAT(COALESCE(first_name, ''), ' ', COALESCE(last_name, '')))
WHERE name IS NULL
");
}
}
}