Fix account balances unique constraint

- Drop and recreate the broken unique index on account_balances table
- Ensure proper unique constraint on (account_id, balance_date)
This commit is contained in:
Víctor Falcón 2025-12-01 10:30:03 +01:00
parent 36c8c30f94
commit 42615e6ee0
1 changed files with 34 additions and 0 deletions

View File

@ -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::table('account_balances', function (Blueprint $table) {
// Drop the broken index
$table->dropUnique('account_balances_account_id_balance_date_unique');
// Recreate it properly
$table->unique(['account_id', 'balance_date'], 'account_balances_account_id_balance_date_unique');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('account_balances', function (Blueprint $table) {
$table->dropUnique('account_balances_account_id_balance_date_unique');
// Restoration might be tricky if we don't know the exact broken state, but let's assume valid state
$table->unique(['account_id', 'balance_date'], 'account_balances_account_id_balance_date_unique');
});
}
};