更新
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?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('account_families', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->comment('家庭名称');
|
||||
$table->unsignedBigInteger('owner_id')->comment('家主用户ID');
|
||||
$table->foreign('owner_id')->references('uid')->on('member')->onDelete('cascade');
|
||||
$table->string('invite_code', 10)->unique()->comment('邀请码');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('owner_id');
|
||||
$table->index('invite_code');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('account_families');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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('account_bills', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->foreign('user_id')->references('uid')->on('member')->onDelete('cascade');
|
||||
$table->foreignId('family_id')->nullable()->constrained('account_families')->onDelete('set null')->comment('家庭ID');
|
||||
$table->enum('type', ['income', 'expense'])->default('expense')->comment('类型:income-收入,expense-支出');
|
||||
$table->decimal('amount', 10, 2)->comment('金额');
|
||||
$table->string('category', 50)->comment('分类');
|
||||
$table->string('remark')->nullable()->comment('备注');
|
||||
$table->date('bill_date')->comment('账单日期');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('user_id');
|
||||
$table->index('family_id');
|
||||
$table->index('type');
|
||||
$table->index('bill_date');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('account_bills');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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('account_family_members', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('family_id')->constrained('account_families')->onDelete('cascade')->comment('家庭ID');
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->foreign('user_id')->references('uid')->on('member')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index('family_id');
|
||||
$table->index('user_id');
|
||||
$table->unique(['family_id', 'user_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('account_family_members');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user