deleted problematic migration
This commit is contained in:
parent
12de0186cf
commit
06da0d8711
|
|
@ -1,41 +0,0 @@
|
|||
<?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::table('payments', function (Blueprint $table): void {
|
||||
if (! $this->hasUniqueIndex('payments', 'payments_account_id_reference_unique')) {
|
||||
$table->unique(['account_id', 'reference'], 'payments_account_id_reference_unique');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('payments', function (Blueprint $table): void {
|
||||
if ($this->hasUniqueIndex('payments', 'payments_account_id_reference_unique')) {
|
||||
$table->dropUnique('payments_account_id_reference_unique');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function hasUniqueIndex(string $table, string $indexName): bool
|
||||
{
|
||||
// Works for both SQLite and others by checking existing indexes from connection schema manager when available.
|
||||
try {
|
||||
$connection = Schema::getConnection();
|
||||
$schemaManager = $connection->getDoctrineSchemaManager();
|
||||
$indexes = $schemaManager->listTableIndexes($table);
|
||||
|
||||
return array_key_exists($indexName, $indexes);
|
||||
} catch (\Throwable $e) {
|
||||
// Fallback: attempt dropping/creating blindly in migration operations
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user