fix(database): 修复缺失表结构并完善索引检查逻辑

- 新增 fix-missing-tables.php 脚本用于补建 settlement_batches 和 system_jobs 表
- 为 settlement_batches 表添加 draw_id 和 settle_version 联合索引
- 在迁移文件中添加表存在性检查避免索引操作失败
- 补录相关迁移记录到 migrations 表中确保迁移状态一致
- 完善 schema 检查逻辑防止对不存在的表进行索引操作
This commit is contained in:
2026-06-10 14:42:23 +08:00
parent c887c4e146
commit 1d13d19b65
2 changed files with 95 additions and 4 deletions

View File

@@ -8,13 +8,13 @@ return new class extends Migration
{
public function up(): void
{
if (! $this->hasIndex('ticket_items', 'idx_ticket_items_order_id')) {
if (Schema::hasTable('ticket_items') && ! $this->hasIndex('ticket_items', 'idx_ticket_items_order_id')) {
Schema::table('ticket_items', function (Blueprint $table): void {
$table->index('order_id', 'idx_ticket_items_order_id');
});
}
if (! $this->hasIndex('settlement_batches', 'idx_settlement_batches_result_batch_id')) {
if (Schema::hasTable('settlement_batches') && ! $this->hasIndex('settlement_batches', 'idx_settlement_batches_result_batch_id')) {
Schema::table('settlement_batches', function (Blueprint $table): void {
$table->index('result_batch_id', 'idx_settlement_batches_result_batch_id');
});
@@ -23,13 +23,13 @@ return new class extends Migration
public function down(): void
{
if ($this->hasIndex('settlement_batches', 'idx_settlement_batches_result_batch_id')) {
if (Schema::hasTable('settlement_batches') && $this->hasIndex('settlement_batches', 'idx_settlement_batches_result_batch_id')) {
Schema::table('settlement_batches', function (Blueprint $table): void {
$table->dropIndex('idx_settlement_batches_result_batch_id');
});
}
if ($this->hasIndex('ticket_items', 'idx_ticket_items_order_id')) {
if (Schema::hasTable('ticket_items') && $this->hasIndex('ticket_items', 'idx_ticket_items_order_id')) {
Schema::table('ticket_items', function (Blueprint $table): void {
$table->dropIndex('idx_ticket_items_order_id');
});