feat:增加数据库迁移文件

This commit is contained in:
2026-05-08 11:12:09 +08:00
parent d780a2e249
commit 3f0bdda4e1
11 changed files with 359 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
APP_NAME=Laravel
APP_NAME=Llottery
APP_ENV=local
APP_KEY=
APP_DEBUG=true
@@ -24,8 +24,8 @@ DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=llotterlaravel
DB_USERNAME=root
DB_PASSWORD=
DB_USERNAME=kang
DB_PASSWORD=123456
SESSION_DRIVER=database
SESSION_LIFETIME=120
@@ -35,8 +35,10 @@ SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
# 本地可用 database上线建议 redis与产品文档赔付池 Lua / 队列)
QUEUE_CONNECTION=database
# 本地可用 database实现赔付池与热点缓存后改为 redis
CACHE_STORE=database
# CACHE_PREFIX=
@@ -63,3 +65,24 @@ AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
# ---------------------------------------------------------------------------
# 彩票业务(按对接填写;勿把真实密钥提交到 Git只在本地 .env 写)
# ---------------------------------------------------------------------------
# 默认结算币种PRDNPR
LOTTERY_DEFAULT_CURRENCY=NPR
# 主站 SSO / 钱包(名称可按实际接口调整)
# MAIN_SITE_BASE_URL=
# MAIN_SITE_SSO_JWT_SECRET=
# MAIN_SITE_WALLET_API_URL=
# MAIN_SITE_WALLET_API_KEY=
# MAIN_SITE_WALLET_TIMEOUT=10
# SanctumH5 / Next 管理端与 API 不同端口时需配置可识别的前端域名
# SANCTUM_STATEFUL_DOMAINS=localhost,localhost:3000,127.0.0.1
# Redis 库划分(可选,与 CACHE / SESSION 分开时用)
# REDIS_DB=0
# REDIS_CACHE_DB=1

View File

@@ -0,0 +1,26 @@
<?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::create('currencies', function (Blueprint $table) {
$table->id();
$table->string('code', 16)->unique();
$table->string('name', 64);
$table->unsignedTinyInteger('decimal_places')->default(2);
$table->boolean('is_enabled')->default(true);
$table->boolean('is_bettable')->default(false);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('currencies');
}
};

View File

@@ -0,0 +1,31 @@
<?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::create('players', function (Blueprint $table) {
$table->id();
$table->string('site_code', 64);
$table->string('site_player_id', 128);
$table->string('username', 128)->nullable();
$table->string('nickname', 128)->nullable();
$table->string('default_currency', 16)->default('NPR');
$table->unsignedTinyInteger('status')->default(0)->comment('0=active,1=frozen,2=blocked');
$table->timestamp('last_login_at')->nullable();
$table->timestamps();
$table->unique(['site_code', 'site_player_id'], 'uk_players_site_player');
$table->index('status', 'idx_players_status');
});
}
public function down(): void
{
Schema::dropIfExists('players');
}
};

View File

@@ -0,0 +1,28 @@
<?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::create('admin_users', function (Blueprint $table) {
$table->id();
$table->string('name', 128);
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->unsignedTinyInteger('status')->default(0)->comment('0=active,1=disabled');
$table->timestamp('last_login_at')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('admin_users');
}
};

View File

@@ -0,0 +1,45 @@
<?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::create('admin_roles', function (Blueprint $table) {
$table->id();
$table->string('slug', 64)->unique();
$table->string('name', 128);
$table->timestamps();
});
Schema::create('admin_permissions', function (Blueprint $table) {
$table->id();
$table->string('slug', 128)->unique();
$table->string('name', 128);
$table->timestamps();
});
Schema::create('admin_role_permissions', function (Blueprint $table) {
$table->foreignId('role_id')->constrained('admin_roles')->cascadeOnDelete();
$table->foreignId('permission_id')->constrained('admin_permissions')->cascadeOnDelete();
$table->primary(['role_id', 'permission_id']);
});
Schema::create('admin_user_roles', function (Blueprint $table) {
$table->foreignId('admin_user_id')->constrained('admin_users')->cascadeOnDelete();
$table->foreignId('role_id')->constrained('admin_roles')->cascadeOnDelete();
$table->primary(['admin_user_id', 'role_id']);
});
}
public function down(): void
{
Schema::dropIfExists('admin_user_roles');
Schema::dropIfExists('admin_role_permissions');
Schema::dropIfExists('admin_permissions');
Schema::dropIfExists('admin_roles');
}
};

View File

@@ -0,0 +1,30 @@
<?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::create('player_wallets', function (Blueprint $table) {
$table->id();
$table->foreignId('player_id')->constrained('players')->cascadeOnDelete();
$table->string('wallet_type', 32)->default('lottery');
$table->string('currency_code', 16);
$table->bigInteger('balance')->default(0);
$table->bigInteger('frozen_balance')->default(0);
$table->unsignedTinyInteger('status')->default(0)->comment('0=active,1=frozen');
$table->unsignedBigInteger('version')->default(0);
$table->timestamps();
$table->unique(['player_id', 'wallet_type', 'currency_code'], 'uk_player_wallets_player_type_currency');
});
}
public function down(): void
{
Schema::dropIfExists('player_wallets');
}
};

View File

@@ -0,0 +1,38 @@
<?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::create('wallet_txns', function (Blueprint $table) {
$table->id();
$table->string('txn_no', 64)->unique();
$table->foreignId('player_id')->constrained('players')->cascadeOnDelete();
$table->foreignId('wallet_id')->constrained('player_wallets')->cascadeOnDelete();
$table->string('biz_type', 32);
$table->string('biz_no', 64)->nullable();
$table->unsignedTinyInteger('direction')->comment('1=in,2=out');
$table->bigInteger('amount');
$table->bigInteger('balance_before');
$table->bigInteger('balance_after');
$table->string('status', 32);
$table->string('external_ref_no', 64)->nullable();
$table->string('idempotent_key', 64)->nullable();
$table->string('remark', 255)->nullable();
$table->timestamps();
$table->index(['player_id', 'created_at'], 'idx_wallet_txns_player_time');
$table->index(['biz_type', 'biz_no'], 'idx_wallet_txns_biz');
$table->unique(['idempotent_key', 'biz_type'], 'uk_wallet_txns_idempotent_biz');
});
}
public function down(): void
{
Schema::dropIfExists('wallet_txns');
}
};

View File

@@ -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
{
public function up(): void
{
Schema::create('transfer_orders', function (Blueprint $table) {
$table->id();
$table->string('transfer_no', 64)->unique();
$table->foreignId('player_id')->constrained('players')->cascadeOnDelete();
$table->string('direction', 16);
$table->string('currency_code', 16);
$table->bigInteger('amount');
$table->string('idempotent_key', 64)->unique();
$table->string('status', 32);
$table->json('external_request_payload')->nullable();
$table->json('external_response_payload')->nullable();
$table->string('external_ref_no', 64)->nullable();
$table->string('fail_reason', 255)->nullable();
$table->timestamp('finished_at')->nullable();
$table->timestamps();
$table->index(['player_id', 'created_at']);
});
}
public function down(): void
{
Schema::dropIfExists('transfer_orders');
}
};

View File

@@ -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
{
public function up(): void
{
Schema::create('draws', function (Blueprint $table) {
$table->id();
$table->string('draw_no', 32)->unique();
$table->date('business_date');
$table->unsignedInteger('sequence_no');
$table->string('status', 32);
$table->timestamp('start_time')->nullable();
$table->timestamp('close_time')->nullable();
$table->timestamp('draw_time')->nullable();
$table->timestamp('cooling_end_time')->nullable();
$table->string('result_source', 16)->nullable()->comment('rng|manual');
$table->unsignedInteger('current_result_version')->default(0);
$table->unsignedInteger('settle_version')->default(0);
$table->boolean('is_reopened')->default(false);
$table->timestamps();
$table->index(['status', 'draw_time'], 'idx_draws_status_draw_time');
});
}
public function down(): void
{
Schema::dropIfExists('draws');
}
};

View File

@@ -0,0 +1,32 @@
<?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::create('draw_result_batches', function (Blueprint $table) {
$table->id();
$table->foreignId('draw_id')->constrained('draws')->cascadeOnDelete();
$table->unsignedInteger('result_version');
$table->string('source_type', 16)->comment('rng|manual');
$table->string('rng_seed_hash', 128)->nullable();
$table->text('raw_seed_encrypted')->nullable();
$table->string('status', 32);
$table->foreignId('created_by')->nullable()->constrained('admin_users')->nullOnDelete();
$table->foreignId('confirmed_by')->nullable()->constrained('admin_users')->nullOnDelete();
$table->timestamp('confirmed_at')->nullable();
$table->timestamps();
$table->unique(['draw_id', 'result_version'], 'uk_draw_result_batches_draw_version');
});
}
public function down(): void
{
Schema::dropIfExists('draw_result_batches');
}
};

View File

@@ -0,0 +1,33 @@
<?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::create('draw_result_items', function (Blueprint $table) {
$table->id();
$table->foreignId('draw_id')->constrained('draws')->cascadeOnDelete();
$table->foreignId('result_batch_id')->constrained('draw_result_batches')->cascadeOnDelete();
$table->string('prize_type', 32);
$table->unsignedInteger('prize_index')->default(0);
$table->char('number_4d', 4);
$table->char('suffix_3d', 3)->nullable();
$table->char('suffix_2d', 2)->nullable();
$table->unsignedTinyInteger('head_digit')->nullable();
$table->unsignedTinyInteger('tail_digit')->nullable();
$table->timestamp('created_at')->useCurrent();
$table->index(['draw_id', 'prize_type', 'prize_index'], 'idx_draw_result_items_draw_prize');
$table->index(['draw_id', 'number_4d'], 'idx_draw_result_items_draw_number');
});
}
public function down(): void
{
Schema::dropIfExists('draw_result_items');
}
};