Files
xin-school/database/migrations/2026_05_30_000001_extend_user_table.php
T
2026-05-30 18:02:41 +08:00

57 lines
2.5 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('user', function (Blueprint $table) {
$table->string('avatar', 255)->default('')->comment('头像')->after('email');
$table->string('mobile', 20)->default('')->comment('手机号')->after('avatar');
$table->tinyInteger('gender')->default(0)->comment('性别:0=未知,1=男,2=女')->after('mobile');
$table->date('birthday')->nullable()->comment('生日')->after('gender');
$table->decimal('balance', 10, 2)->default(0)->comment('余额')->after('birthday');
$table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=正常')->after('balance');
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间')->after('status');
$table->string('openid', 64)->default('')->comment('微信OpenID')->after('last_login_at');
$table->string('unionid', 64)->default('')->comment('微信UnionID')->after('openid');
$table->index('mobile');
$table->index('openid');
});
if (! Schema::hasTable('user_addresses')) {
Schema::create('user_addresses', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('user_id')->comment('用户ID');
$table->string('name', 30)->comment('收货人');
$table->string('mobile', 20)->comment('联系电话');
$table->string('province', 30)->comment('省');
$table->string('city', 30)->comment('市');
$table->string('district', 30)->comment('区');
$table->string('detail', 255)->comment('详细地址');
$table->tinyInteger('is_default')->default(0)->comment('是否默认:0=否,1=是');
$table->timestamps();
$table->index('user_id');
$table->comment('用户收货地址');
});
}
}
public function down(): void
{
Schema::table('user', function (Blueprint $table) {
$table->dropIndex(['mobile']);
$table->dropIndex(['openid']);
$table->dropColumn([
'avatar', 'mobile', 'gender', 'birthday',
'balance', 'status', 'last_login_at', 'openid', 'unionid',
]);
});
Schema::dropIfExists('user_addresses');
}
};