Delete duplicate wallets (#2163)
* Delete duplicate wallets * Add unique Wallet index to prevent duplicate user wallets
This commit is contained in:
parent
d2c71ca08f
commit
d7ddfffbf0
@ -0,0 +1,16 @@
|
|||||||
|
-- delete duplicate wallets per user
|
||||||
|
WITH duplicates AS (
|
||||||
|
SELECT
|
||||||
|
"userId",
|
||||||
|
"type",
|
||||||
|
(array_agg(id ORDER BY updated_at DESC))[2:] AS id
|
||||||
|
FROM "Wallet"
|
||||||
|
GROUP BY "userId", "type"
|
||||||
|
HAVING COUNT(id) > 1
|
||||||
|
ORDER BY COUNT(id) DESC, "userId" ASC
|
||||||
|
)
|
||||||
|
DELETE FROM "Wallet"
|
||||||
|
WHERE id in (SELECT unnest(id) FROM duplicates);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "Wallet_userId_type_key" ON "Wallet"("userId", "type");
|
@ -246,6 +246,7 @@ model Wallet {
|
|||||||
InvoiceForward InvoiceForward[]
|
InvoiceForward InvoiceForward[]
|
||||||
DirectPayment DirectPayment[]
|
DirectPayment DirectPayment[]
|
||||||
|
|
||||||
|
@@unique([userId, type])
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
@@index([priority])
|
@@index([priority])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user