This commit is contained in:
Mark Haines 2017-07-24 17:47:10 +01:00
parent 3df7ba8c0c
commit b9d4b10fe9
2 changed files with 10 additions and 10 deletions

View file

@ -21,7 +21,7 @@ import (
) )
const inviteSchema = ` const inviteSchema = `
CREATE TABLE invites ( CREATE TABLE IF NOT EXISTS invites (
-- The string ID of the invite event itself. -- The string ID of the invite event itself.
-- We can't use a numeric event ID here because we don't always have -- We can't use a numeric event ID here because we don't always have
-- enough information to store an invite in the event table. -- enough information to store an invite in the event table.
@ -47,17 +47,17 @@ CREATE TABLE invites (
invite_event_json TEXT NOT NULL invite_event_json TEXT NOT NULL
); );
CREATE INDEX invites_active_idx ON invites (target_state_key_nid, room_nid) CREATE INDEX IF NOT EXISTS invites_active_idx ON invites (target_nid, room_nid)
WHERE NOT retired; WHERE NOT retired;
` `
const insertInviteEventSQL = "" + const insertInviteEventSQL = "" +
"INSERT INTO invites (invite_event_id, room_nid, target_state_key_nid," + "INSERT INTO invites (invite_event_id, room_nid, target_nid," +
" sender_state_key_nid, invite_event_json) VALUES ($1, $2, $3, $4, $5)" + " sender_nid, invite_event_json) VALUES ($1, $2, $3, $4, $5)" +
" ON CONFLICT DO NOTHING" " ON CONFLICT DO NOTHING"
const selectInviteActiveForUserInRoomSQL = "" + const selectInviteActiveForUserInRoomSQL = "" +
"SELECT invite_event_id, sender_state_key_nid FROM invites" + "SELECT invite_event_id, sender_nid FROM invites" +
" WHERE target_state_key_id = $1 AND room_nid = $2" + " WHERE target_nid = $1 AND room_nid = $2" +
" AND NOT retired" " AND NOT retired"
// Retire every active invite. // Retire every active invite.
@ -67,7 +67,7 @@ const selectInviteActiveForUserInRoomSQL = "" +
// invites that were retired, so we are forced to retire all of them. // invites that were retired, so we are forced to retire all of them.
const updateInviteRetiredSQL = "" + const updateInviteRetiredSQL = "" +
"UPDATE invites SET retired = TRUE" + "UPDATE invites SET retired = TRUE" +
" WHERE room_nid = $1 AND target_state_key_nid = $2 AND NOT retired" + " WHERE room_nid = $1 AND target_nid = $2 AND NOT retired" +
" RETURNING invite_event_id" " RETURNING invite_event_id"
type inviteStatements struct { type inviteStatements struct {

View file

@ -35,7 +35,7 @@ const membershipSchema = `
-- 1) The membership of a user changes within the current state of the room. -- 1) The membership of a user changes within the current state of the room.
-- 2) An invite is received outside of a room over federation. -- 2) An invite is received outside of a room over federation.
-- 3) An invite is rejected outside of a room over federation. -- 3) An invite is rejected outside of a room over federation.
CREATE TABLE membership IF NOT EXISTS ( CREATE TABLE IF NOT EXISTS membership (
room_nid BIGINT NOT NULL, room_nid BIGINT NOT NULL,
-- Numeric state key ID for the user ID this state is for. -- Numeric state key ID for the user ID this state is for.
target_nid BIGINT NOT NULL, target_nid BIGINT NOT NULL,
@ -54,11 +54,11 @@ const insertMembershipSQL = "" +
const selectMembershipForUpdateSQL = "" + const selectMembershipForUpdateSQL = "" +
"SELECT membership_nid FROM membership" + "SELECT membership_nid FROM membership" +
" WHERE room_nid = $1, target_nid = $2 FOR UPDATE" " WHERE room_nid = $1 AND target_nid = $2 FOR UPDATE"
const updateMembershipSQL = "" + const updateMembershipSQL = "" +
"UPDATE membership SET membership_nid = $3, sender_nid = $4" + "UPDATE membership SET membership_nid = $3, sender_nid = $4" +
" WHERE room_nid = $1, target_nid = $2" " WHERE room_nid = $1 AND target_nid = $2"
type membershipStatements struct { type membershipStatements struct {
insertMembershipStmt *sql.Stmt insertMembershipStmt *sql.Stmt