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:
parent
36c8c30f94
commit
42615e6ee0
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue