Alter SQL column names to be distinct

This commit is contained in:
Cadence Ember 2023-10-05 12:32:05 +13:00
parent a49b46381c
commit 28abdac5b6
14 changed files with 40 additions and 25 deletions

View file

@ -15,7 +15,7 @@ const api = sync.require("../../matrix/api")
* @param {import("discord-api-types/v10").APIThreadChannel} thread
*/
async function announceThread(parentRoomID, threadRoomID, thread) {
const creatorMxid = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(thread.owner_id)
const creatorMxid = select("sim", "mxid", "WHERE user_id = ?").pluck().get(thread.owner_id)
const content = await threadToAnnouncement.threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thread, {api})

View file

@ -29,7 +29,7 @@ async function createSim(user) {
// Save chosen name in the database forever
// Making this database change right away so that in a concurrent registration, the 2nd registration will already have generated a different localpart because it can see this row when it generates
db.prepare("INSERT INTO sim (discord_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run(user.id, simName, localpart, mxid)
db.prepare("INSERT INTO sim (user_id, sim_name, localpart, mxid) VALUES (?, ?, ?, ?)").run(user.id, simName, localpart, mxid)
// Register matrix user with that name
try {
@ -37,7 +37,7 @@ async function createSim(user) {
} catch (e) {
// If user creation fails, manually undo the database change. Still isn't perfect, but should help.
// (A transaction would be preferable, but I don't think it's safe to leave transaction open across event loop ticks.)
db.prepare("DELETE FROM sim WHERE discord_id = ?").run(user.id)
db.prepare("DELETE FROM sim WHERE user_id = ?").run(user.id)
throw e
}
return mxid
@ -51,7 +51,7 @@ async function createSim(user) {
*/
async function ensureSim(user) {
let mxid = null
const existing = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(user.id)
const existing = select("sim", "mxid", "WHERE user_id = ?").pluck().get(user.id)
if (existing) {
mxid = existing
} else {
@ -164,7 +164,7 @@ async function syncAllUsersInRoom(roomID) {
assert.ok(typeof guildID === "string")
for (const mxid of mxids) {
const userID = select("sim", "discord_id", "WHERE mxid = ?").pluck().get(mxid)
const userID = select("sim", "user_id", "WHERE mxid = ?").pluck().get(mxid)
assert.ok(typeof userID === "string")
/** @ts-ignore @type {Required<import("discord-api-types/v10").APIGuildMember>} */

View file

@ -42,7 +42,7 @@ async function removeReaction(data) {
}
if (!lookingAtMatrixReaction && !wantToRemoveMatrixReaction) {
// We are removing a Discord user's reaction, so we just make the sim user remove it.
const mxid = select("sim", "mxid", "WHERE discord_id = ?").pluck().get(data.user_id)
const mxid = select("sim", "mxid", "WHERE user_id = ?").pluck().get(data.user_id)
if (mxid === event.sender) {
await api.redactEvent(roomID, event.event_id, mxid)
}