diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js --- a/keyserver/src/creators/thread-creator.js +++ b/keyserver/src/creators/thread-creator.js @@ -323,12 +323,26 @@ } } else { const query = SQL` + START TRANSACTION; + INSERT INTO threads(id, type, name, description, creator, creation_time, color, parent_thread_id, containing_thread_id, community, depth, source_message) - VALUES ${[row]} + VALUES ${[row]}; `; - await dbQuery(query); + + if (threadTypeIsCommunityRoot(threadType)) { + query.append(SQL` + INSERT INTO communities (id) + VALUES (${id}); + `); + } + + query.append(SQL` + COMMIT; + `); + + await dbQuery(query, { multipleStatements: true }); } const initialMemberPromise: Promise = initialMemberIDs diff --git a/keyserver/src/deleters/thread-deleters.js b/keyserver/src/deleters/thread-deleters.js --- a/keyserver/src/deleters/thread-deleters.js +++ b/keyserver/src/deleters/thread-deleters.js @@ -95,6 +95,7 @@ const deletionQuery = SQL` START TRANSACTION; DELETE FROM threads WHERE id IN (${threadIDs}); + DELETE FROM communities WHERE id IN (${threadIDs}); DELETE FROM ids WHERE id IN (${threadIDs}); DELETE d, id, e, ie, r, ir FROM days d