How do I alter the position of a column in a PostgreSQL database table?

administrator

Administrator
Nhân viên
9 Tháng tám 2021
63
0
6
UserSeeder.php
Mã:
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

class ThumbnailS3Seeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //inser column mail after column name
        Schema::table('users',function(Blueprint $table){
            Schema::rename('users', 'users_old');
            Schema::create('users', function (Blueprint $table) {
                $table->id();
                $table->text('name')->nullable();
                $table->text('mail')->nullable();
                $table->timestamps();
            });
            DB::statement("insert into users (name, created_at, updated_at) select name, created_at, updated_at from users_old;");
            //delete users_old
            Schema::dropIfExists('users_old');
        });
    }
}