瀏覽代碼

feat(unit-payment-account): coluna de hash da chave para detectar conta compartilhada

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ebagabee 4 周之前
父節點
當前提交
a28f5fbc4e

+ 30 - 0
database/migrations/2026_07_01_000003_add_api_key_hash_to_unit_payment_accounts_table.php

@@ -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
+{
+    /**
+     * Hash determinístico da api_key para detectar unidades que compartilham a
+     * MESMA conta Asaas (mesmo dono). Como a api_key é cifrada (IV aleatório),
+     * não dá para comparar por SQL — o hash resolve isso e permite reaproveitar
+     * um único webhook por conta.
+     */
+    public function up(): void
+    {
+        Schema::table('unit_payment_accounts', function (Blueprint $table) {
+            $table->string('asaas_api_key_hash')->nullable()->after('asaas_webhook_id');
+            $table->index('asaas_api_key_hash');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('unit_payment_accounts', function (Blueprint $table) {
+            $table->dropIndex(['asaas_api_key_hash']);
+            $table->dropColumn('asaas_api_key_hash');
+        });
+    }
+};