hyperf-chat/migrations/2020_11_04_153553_create_us...

43 lines
1.4 KiB
PHP

<?php
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;
use Hyperf\DbConnection\Db;
class CreateUsersFriendsTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users_friends', function (Blueprint $table) {
$table->unsignedInteger('id', true)->comment('关系ID');
$table->unsignedInteger('user_id')->default(0)->comment('用户ID');
$table->unsignedInteger('friend_id')->default(0)->comment('好友ID');
$table->string('remark', 30)->default('')->comment('好友备注');
$table->unsignedTinyInteger('status')->default(0)->comment('好友状态[0:否;1:是;]');
$table->dateTime('created_at')->nullable(true)->comment('创建时间');
$table->dateTime('updated_at')->nullable(true)->comment('更新时间');
$table->charset = 'utf8';
$table->collation = 'utf8_general_ci';
$table->engine = 'InnoDB';
$table->index(['user_id', 'friend_id'], 'idx_user_id_friend_id');
});
$prefix = config('databases.default.prefix');
DB::statement("ALTER TABLE `{$prefix}users_friends` comment '用户好友关系表'");
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users_friends');
}
}