Browse Source

fixed duplicate channel bug

subDesTagesMitExtraKaese 3 years ago
parent
commit
1ab2f5536c
2 changed files with 5 additions and 4 deletions
  1. 2 2
      channel-statistics.js
  2. 3 2
      createTables.sql

+ 2 - 2
channel-statistics.js

@@ -133,8 +133,8 @@ registerPlugin({
       if (!err) {
         if(res.length > 0) {
           const id = res[0].id;
-          dbc.exec("UPDATE channel SET name = ?, parentId = ?, position = ?, description = ? WHERE id = ?", 
-            remove_non_utf8(channel.name()), parentId, channel.position(), remove_non_utf8(channel.description()), id);
+          dbc.exec("UPDATE channel SET name = ?, parentId = ?, position = ?, description = ? WHERE channelId = ? AND serverId = ?",
+            remove_non_utf8(channel.name()), parentId, channel.position(), remove_non_utf8(channel.description()), channel.id(), serverId);
           cb(id);
         } else {
           dbc.exec("INSERT INTO channel (channelId, name, serverId, parentId, position, description) VALUES (?, ?, ?, ?, ?, ?)", 

+ 3 - 2
createTables.sql

@@ -3,7 +3,7 @@
 -- https://www.phpmyadmin.net/
 --
 -- Host: localhost:3306
--- Erstellungszeit: 17. Okt 2021 um 00:27
+-- Erstellungszeit: 17. Okt 2021 um 13:12
 -- Server-Version: 10.3.29-MariaDB-0+deb10u1
 -- PHP-Version: 7.3.29-1~deb10u1
 
@@ -63,7 +63,8 @@ CREATE TABLE `server` (
 -- Indizes für die Tabelle `channel`
 --
 ALTER TABLE `channel`
-  ADD PRIMARY KEY (`id`);
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `channelId` (`channelId`,`serverId`);
 
 --
 -- Indizes für die Tabelle `channelEvent`