laravel-vuexy-admin-old/database/migrations/2024_12_14_030215_modify_users_table.php
2025-03-05 20:28:54 -06:00

45 lines
1.7 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Schema\Blueprint;
use Koneko\VuexyAdmin\Models\User;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
DB::statement('ALTER TABLE `users` MODIFY `id` BIGINT UNSIGNED NOT NULL;');
DB::statement('ALTER TABLE `users` DROP PRIMARY KEY;');
DB::statement('ALTER TABLE `users` MODIFY `id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (`id`);');
Schema::table('users', function (Blueprint $table) {
$table->string('last_name', 100)->nullable()->comment('Apellidos')->index()->after('name');
$table->string('profile_photo_path', 2048)->nullable()->after('remember_token');
$table->unsignedTinyInteger('status')->default(User::STATUS_DISABLED)->after('profile_photo_path');
$table->unsignedMediumInteger('created_by')->nullable()->index()->after('status');
// Definir la relación con created_by
$table->foreign('created_by')->references('id')->on('users')->onUpdate('restrict')->onDelete('restrict');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
DB::statement('ALTER TABLE `users` MODIFY `id` MEDIUMINT UNSIGNED NOT NULL;');
DB::statement('ALTER TABLE `users` DROP PRIMARY KEY;');
DB::statement('ALTER TABLE `users` MODIFY `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (`id`);');
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['last_name', 'profile_photo_path', 'status', 'created_by']);
});
}
};