<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void {
		Schema::create('member_extends', function (Blueprint $table) {
			$table->id()->uniqid()->comment('主键id');
			$table->unsignedBigInteger('member_id')->comment('用户id');
			$table->tinyInteger('status')->default(1)->comment('状态');
			$table->timestamp('created_at')->nullable()->comment('创建时间');
			$table->timestamp('updated_at')->nullable()->comment('更新时间');

			$table->engine = 'InnoDB';
			$table->charset = 'utf8mb4';
			$table->collation = 'utf8mb4_unicode_ci';
			$table->comment('会员扩展表');
		});

		Schema::create('member_extends_fields', function (Blueprint $table) {
			$table->id()->uniqid()->comment('主键id');
			$table->string('title')->comment('字段名称');
			$table->string('name')->comment('字段标识');
			$table->string('type')->comment('字段类型');
			$table->string('length')->nullable()->comment('字段长度');
			$table->string('default_value')->nullable()->comment('默认值');
			$table->string('after')->nullable()->comment('在字段后');
			$table->string('remark')->nullable()->comment('字段备注');
			$table->tinyInteger('required')->default(0)->comment('是否必填');
			$table->string('sort')->default(0)->comment('排序');
			$table->tinyInteger('status')->default(1)->comment('状态 1正常 2禁用');
			$table->timestamp('created_at')->nullable()->comment('创建时间');
			$table->timestamp('updated_at')->nullable()->comment('更新时间');

			$table->engine = 'InnoDB';
			$table->charset = 'utf8mb4';
			$table->collation = 'utf8mb4_unicode_ci';
			$table->comment('会员扩展字段表');
		});

		Schema::create('member_extends_log', function (Blueprint $table) {
			$table->id()->uniqid()->comment('主键id');
			$table->unsignedBigInteger('member_id')->comment('用户id');
			$table->string('field')->comment('修改的字段');
			$table->string('old_value')->nullable()->comment('旧值');
			$table->string('new_value')->nullable()->comment('新值');
			$table->timestamp('created_at')->nullable()->comment('创建时间');
			$table->timestamp('updated_at')->nullable()->comment('更新时间');

			$table->engine = 'InnoDB';
			$table->charset = 'utf8mb4';
			$table->collation = 'utf8mb4_unicode_ci';
			$table->comment('会员扩展日志表');
		});
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void {
		Schema::dropIfExists('member_extends');
		Schema::dropIfExists('member_extends_fields');
		Schema::dropIfExists('member_extends_log');
    }
};
