From 4c203631db9566b3d26e0205813baabd1a9df1b6 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 13 Oct 2020 10:10:46 +0700 Subject: [PATCH] Making order_id (BTCPay invoice id) unique in the database. --- backend/src/api/donations.ts | 2 +- mariadb-structure.sql | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/api/donations.ts b/backend/src/api/donations.ts index 7d7b81b0d..c3ab24f33 100644 --- a/backend/src/api/donations.ts +++ b/backend/src/api/donations.ts @@ -105,7 +105,7 @@ class Donations { private async $addDonationToDatabase(btcPaid: number, handle: string, orderId: string, imageUrl: string): Promise { try { const connection = await DB.pool.getConnection(); - const query = `INSERT INTO donations(added, amount, handle, order_id, imageUrl) VALUES (NOW(), ?, ?, ?, ?)`; + const query = `INSERT IGNORE INTO donations(added, amount, handle, order_id, imageUrl) VALUES (NOW(), ?, ?, ?, ?)`; const params: (string | number)[] = [ btcPaid, handle, diff --git a/mariadb-structure.sql b/mariadb-structure.sql index 770f8029a..b7eed37c4 100644 --- a/mariadb-structure.sql +++ b/mariadb-structure.sql @@ -100,3 +100,5 @@ ALTER TABLE `donations` ALTER TABLE `donations` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; + +ALTER TABLE `donations` ADD UNIQUE(`order_id`);