mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Name tables back
This commit is contained in:
parent
1b00a16609
commit
0b1e114c13
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const blacklistSchema = `
|
const blacklistSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_blacklist (
|
CREATE TABLE IF NOT EXISTS federationsender_blacklist (
|
||||||
-- The blacklisted server name
|
-- The blacklisted server name
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
UNIQUE (server_name)
|
UNIQUE (server_name)
|
||||||
|
|
@ -31,17 +31,17 @@ CREATE TABLE IF NOT EXISTS federationapi_blacklist (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertBlacklistSQL = "" +
|
const insertBlacklistSQL = "" +
|
||||||
"INSERT INTO federationapi_blacklist (server_name) VALUES ($1)" +
|
"INSERT INTO federationsender_blacklist (server_name) VALUES ($1)" +
|
||||||
" ON CONFLICT DO NOTHING"
|
" ON CONFLICT DO NOTHING"
|
||||||
|
|
||||||
const selectBlacklistSQL = "" +
|
const selectBlacklistSQL = "" +
|
||||||
"SELECT server_name FROM federationapi_blacklist WHERE server_name = $1"
|
"SELECT server_name FROM federationsender_blacklist WHERE server_name = $1"
|
||||||
|
|
||||||
const deleteBlacklistSQL = "" +
|
const deleteBlacklistSQL = "" +
|
||||||
"DELETE FROM federationapi_blacklist WHERE server_name = $1"
|
"DELETE FROM federationsender_blacklist WHERE server_name = $1"
|
||||||
|
|
||||||
const deleteAllBlacklistSQL = "" +
|
const deleteAllBlacklistSQL = "" +
|
||||||
"TRUNCATE federationapi_blacklist"
|
"TRUNCATE federationsender_blacklist"
|
||||||
|
|
||||||
type blacklistStatements struct {
|
type blacklistStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func LoadRemoveRoomsTable(m *sqlutil.Migrations) {
|
||||||
|
|
||||||
func UpRemoveRoomsTable(tx *sql.Tx) error {
|
func UpRemoveRoomsTable(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec(`
|
_, err := tx.Exec(`
|
||||||
DROP TABLE IF EXISTS federationapi_rooms;
|
DROP TABLE IF EXISTS federationsender_rooms;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const inboundPeeksSchema = `
|
const inboundPeeksSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_inbound_peeks (
|
CREATE TABLE IF NOT EXISTS federationsender_inbound_peeks (
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
peek_id TEXT NOT NULL,
|
peek_id TEXT NOT NULL,
|
||||||
|
|
@ -38,22 +38,22 @@ CREATE TABLE IF NOT EXISTS federationapi_inbound_peeks (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertInboundPeekSQL = "" +
|
const insertInboundPeekSQL = "" +
|
||||||
"INSERT INTO federationapi_inbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
"INSERT INTO federationsender_inbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
||||||
|
|
||||||
const selectInboundPeekSQL = "" +
|
const selectInboundPeekSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_inbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_inbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
||||||
|
|
||||||
const selectInboundPeeksSQL = "" +
|
const selectInboundPeeksSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_inbound_peeks WHERE room_id = $1"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_inbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
const renewInboundPeekSQL = "" +
|
const renewInboundPeekSQL = "" +
|
||||||
"UPDATE federationapi_inbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
"UPDATE federationsender_inbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
||||||
|
|
||||||
const deleteInboundPeekSQL = "" +
|
const deleteInboundPeekSQL = "" +
|
||||||
"DELETE FROM federationapi_inbound_peeks WHERE room_id = $1 and server_name = $2"
|
"DELETE FROM federationsender_inbound_peeks WHERE room_id = $1 and server_name = $2"
|
||||||
|
|
||||||
const deleteInboundPeeksSQL = "" +
|
const deleteInboundPeeksSQL = "" +
|
||||||
"DELETE FROM federationapi_inbound_peeks WHERE room_id = $1"
|
"DELETE FROM federationsender_inbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
type inboundPeeksStatements struct {
|
type inboundPeeksStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ const joinedHostsSchema = `
|
||||||
-- The joined_hosts table stores a list of m.room.member event ids in the
|
-- The joined_hosts table stores a list of m.room.member event ids in the
|
||||||
-- current state for each room where the membership is "join".
|
-- current state for each room where the membership is "join".
|
||||||
-- There will be an entry for every user that is joined to the room.
|
-- There will be an entry for every user that is joined to the room.
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_joined_hosts (
|
CREATE TABLE IF NOT EXISTS federationsender_joined_hosts (
|
||||||
-- The string ID of the room.
|
-- The string ID of the room.
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
-- The event ID of the m.room.member join event.
|
-- The event ID of the m.room.member join event.
|
||||||
|
|
@ -40,31 +40,31 @@ CREATE TABLE IF NOT EXISTS federationapi_joined_hosts (
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federatonsender_joined_hosts_event_id_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federatonsender_joined_hosts_event_id_idx
|
||||||
ON federationapi_joined_hosts (event_id);
|
ON federationsender_joined_hosts (event_id);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS federatonsender_joined_hosts_room_id_idx
|
CREATE INDEX IF NOT EXISTS federatonsender_joined_hosts_room_id_idx
|
||||||
ON federationapi_joined_hosts (room_id)
|
ON federationsender_joined_hosts (room_id)
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertJoinedHostsSQL = "" +
|
const insertJoinedHostsSQL = "" +
|
||||||
"INSERT INTO federationapi_joined_hosts (room_id, event_id, server_name)" +
|
"INSERT INTO federationsender_joined_hosts (room_id, event_id, server_name)" +
|
||||||
" VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
" VALUES ($1, $2, $3) ON CONFLICT DO NOTHING"
|
||||||
|
|
||||||
const deleteJoinedHostsSQL = "" +
|
const deleteJoinedHostsSQL = "" +
|
||||||
"DELETE FROM federationapi_joined_hosts WHERE event_id = ANY($1)"
|
"DELETE FROM federationsender_joined_hosts WHERE event_id = ANY($1)"
|
||||||
|
|
||||||
const deleteJoinedHostsForRoomSQL = "" +
|
const deleteJoinedHostsForRoomSQL = "" +
|
||||||
"DELETE FROM federationapi_joined_hosts WHERE room_id = $1"
|
"DELETE FROM federationsender_joined_hosts WHERE room_id = $1"
|
||||||
|
|
||||||
const selectJoinedHostsSQL = "" +
|
const selectJoinedHostsSQL = "" +
|
||||||
"SELECT event_id, server_name FROM federationapi_joined_hosts" +
|
"SELECT event_id, server_name FROM federationsender_joined_hosts" +
|
||||||
" WHERE room_id = $1"
|
" WHERE room_id = $1"
|
||||||
|
|
||||||
const selectAllJoinedHostsSQL = "" +
|
const selectAllJoinedHostsSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_joined_hosts"
|
"SELECT DISTINCT server_name FROM federationsender_joined_hosts"
|
||||||
|
|
||||||
const selectJoinedHostsForRoomsSQL = "" +
|
const selectJoinedHostsForRoomsSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_joined_hosts WHERE room_id = ANY($1)"
|
"SELECT DISTINCT server_name FROM federationsender_joined_hosts WHERE room_id = ANY($1)"
|
||||||
|
|
||||||
type joinedHostsStatements struct {
|
type joinedHostsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const notaryServerKeysJSONSchema = `
|
const notaryServerKeysJSONSchema = `
|
||||||
CREATE SEQUENCE IF NOT EXISTS federationapi_notary_server_keys_json_pkey;
|
CREATE SEQUENCE IF NOT EXISTS federationsender_notary_server_keys_json_pkey;
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_json (
|
CREATE TABLE IF NOT EXISTS federationsender_notary_server_keys_json (
|
||||||
notary_id BIGINT PRIMARY KEY NOT NULL DEFAULT nextval('federationapi_notary_server_keys_json_pkey'),
|
notary_id BIGINT PRIMARY KEY NOT NULL DEFAULT nextval('federationsender_notary_server_keys_json_pkey'),
|
||||||
response_json TEXT NOT NULL,
|
response_json TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
valid_until BIGINT NOT NULL
|
valid_until BIGINT NOT NULL
|
||||||
|
|
@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_json (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertServerKeysJSONSQL = "" +
|
const insertServerKeysJSONSQL = "" +
|
||||||
"INSERT INTO federationapi_notary_server_keys_json (response_json, server_name, valid_until) VALUES ($1, $2, $3)" +
|
"INSERT INTO federationsender_notary_server_keys_json (response_json, server_name, valid_until) VALUES ($1, $2, $3)" +
|
||||||
" RETURNING notary_id"
|
" RETURNING notary_id"
|
||||||
|
|
||||||
type notaryServerKeysStatements struct {
|
type notaryServerKeysStatements struct {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const notaryServerKeysMetadataSchema = `
|
const notaryServerKeysMetadataSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_metadata (
|
CREATE TABLE IF NOT EXISTS federationsender_notary_server_keys_metadata (
|
||||||
notary_id BIGINT NOT NULL,
|
notary_id BIGINT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
key_id TEXT NOT NULL,
|
key_id TEXT NOT NULL,
|
||||||
|
|
@ -35,41 +35,41 @@ CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_metadata (
|
||||||
`
|
`
|
||||||
|
|
||||||
const upsertServerKeysSQL = "" +
|
const upsertServerKeysSQL = "" +
|
||||||
"INSERT INTO federationapi_notary_server_keys_metadata (notary_id, server_name, key_id) VALUES ($1, $2, $3)" +
|
"INSERT INTO federationsender_notary_server_keys_metadata (notary_id, server_name, key_id) VALUES ($1, $2, $3)" +
|
||||||
" ON CONFLICT (server_name, key_id) DO UPDATE SET notary_id = $1"
|
" ON CONFLICT (server_name, key_id) DO UPDATE SET notary_id = $1"
|
||||||
|
|
||||||
// for a given (server_name, key_id), find the existing notary ID and valid until. Used to check if we will replace it
|
// for a given (server_name, key_id), find the existing notary ID and valid until. Used to check if we will replace it
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyMetadataSQL = `
|
const selectNotaryKeyMetadataSQL = `
|
||||||
SELECT federationapi_notary_server_keys_metadata.notary_id, valid_until FROM federationapi_notary_server_keys_json
|
SELECT federationsender_notary_server_keys_metadata.notary_id, valid_until FROM federationsender_notary_server_keys_json
|
||||||
JOIN federationapi_notary_server_keys_metadata ON
|
JOIN federationsender_notary_server_keys_metadata ON
|
||||||
federationapi_notary_server_keys_metadata.notary_id = federationapi_notary_server_keys_json.notary_id
|
federationsender_notary_server_keys_metadata.notary_id = federationsender_notary_server_keys_json.notary_id
|
||||||
WHERE federationapi_notary_server_keys_metadata.server_name = $1 AND federationapi_notary_server_keys_metadata.key_id = $2
|
WHERE federationsender_notary_server_keys_metadata.server_name = $1 AND federationsender_notary_server_keys_metadata.key_id = $2
|
||||||
`
|
`
|
||||||
|
|
||||||
// select the response which has the highest valid_until value
|
// select the response which has the highest valid_until value
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyResponsesSQL = `
|
const selectNotaryKeyResponsesSQL = `
|
||||||
SELECT response_json FROM federationapi_notary_server_keys_json
|
SELECT response_json FROM federationsender_notary_server_keys_json
|
||||||
WHERE server_name = $1 AND valid_until = (
|
WHERE server_name = $1 AND valid_until = (
|
||||||
SELECT MAX(valid_until) FROM federationapi_notary_server_keys_json WHERE server_name = $1
|
SELECT MAX(valid_until) FROM federationsender_notary_server_keys_json WHERE server_name = $1
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
// select the responses which have the given key IDs
|
// select the responses which have the given key IDs
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyResponsesWithKeyIDsSQL = `
|
const selectNotaryKeyResponsesWithKeyIDsSQL = `
|
||||||
SELECT response_json FROM federationapi_notary_server_keys_json
|
SELECT response_json FROM federationsender_notary_server_keys_json
|
||||||
JOIN federationapi_notary_server_keys_metadata ON
|
JOIN federationsender_notary_server_keys_metadata ON
|
||||||
federationapi_notary_server_keys_metadata.notary_id = federationapi_notary_server_keys_json.notary_id
|
federationsender_notary_server_keys_metadata.notary_id = federationsender_notary_server_keys_json.notary_id
|
||||||
WHERE federationapi_notary_server_keys_json.server_name = $1 AND federationapi_notary_server_keys_metadata.key_id = ANY ($2)
|
WHERE federationsender_notary_server_keys_json.server_name = $1 AND federationsender_notary_server_keys_metadata.key_id = ANY ($2)
|
||||||
GROUP BY federationapi_notary_server_keys_json.notary_id
|
GROUP BY federationsender_notary_server_keys_json.notary_id
|
||||||
`
|
`
|
||||||
|
|
||||||
// JOINs with the metadata table
|
// JOINs with the metadata table
|
||||||
const deleteUnusedServerKeysJSONSQL = `
|
const deleteUnusedServerKeysJSONSQL = `
|
||||||
DELETE FROM federationapi_notary_server_keys_json WHERE federationapi_notary_server_keys_json.notary_id NOT IN (
|
DELETE FROM federationsender_notary_server_keys_json WHERE federationsender_notary_server_keys_json.notary_id NOT IN (
|
||||||
SELECT DISTINCT notary_id FROM federationapi_notary_server_keys_metadata
|
SELECT DISTINCT notary_id FROM federationsender_notary_server_keys_metadata
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const outboundPeeksSchema = `
|
const outboundPeeksSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_outbound_peeks (
|
CREATE TABLE IF NOT EXISTS federationsender_outbound_peeks (
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
peek_id TEXT NOT NULL,
|
peek_id TEXT NOT NULL,
|
||||||
|
|
@ -38,22 +38,22 @@ CREATE TABLE IF NOT EXISTS federationapi_outbound_peeks (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertOutboundPeekSQL = "" +
|
const insertOutboundPeekSQL = "" +
|
||||||
"INSERT INTO federationapi_outbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
"INSERT INTO federationsender_outbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
||||||
|
|
||||||
const selectOutboundPeekSQL = "" +
|
const selectOutboundPeekSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_outbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_outbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
||||||
|
|
||||||
const selectOutboundPeeksSQL = "" +
|
const selectOutboundPeeksSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_outbound_peeks WHERE room_id = $1"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_outbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
const renewOutboundPeekSQL = "" +
|
const renewOutboundPeekSQL = "" +
|
||||||
"UPDATE federationapi_outbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
"UPDATE federationsender_outbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
||||||
|
|
||||||
const deleteOutboundPeekSQL = "" +
|
const deleteOutboundPeekSQL = "" +
|
||||||
"DELETE FROM federationapi_outbound_peeks WHERE room_id = $1 and server_name = $2"
|
"DELETE FROM federationsender_outbound_peeks WHERE room_id = $1 and server_name = $2"
|
||||||
|
|
||||||
const deleteOutboundPeeksSQL = "" +
|
const deleteOutboundPeeksSQL = "" +
|
||||||
"DELETE FROM federationapi_outbound_peeks WHERE room_id = $1"
|
"DELETE FROM federationsender_outbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
type outboundPeeksStatements struct {
|
type outboundPeeksStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -25,41 +25,41 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const queueEDUsSchema = `
|
const queueEDUsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_edus (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_edus (
|
||||||
-- The type of the event (informational).
|
-- The type of the event (informational).
|
||||||
edu_type TEXT NOT NULL,
|
edu_type TEXT NOT NULL,
|
||||||
-- The domain part of the user ID the EDU event is for.
|
-- The domain part of the user ID the EDU event is for.
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
-- The JSON NID from the federationapi_queue_edus_json table.
|
-- The JSON NID from the federationsender_queue_edus_json table.
|
||||||
json_nid BIGINT NOT NULL
|
json_nid BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationapi_queue_edus_json_nid_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
||||||
ON federationapi_queue_edus (json_nid, server_name);
|
ON federationsender_queue_edus (json_nid, server_name);
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertQueueEDUSQL = "" +
|
const insertQueueEDUSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_edus (edu_type, server_name, json_nid)" +
|
"INSERT INTO federationsender_queue_edus (edu_type, server_name, json_nid)" +
|
||||||
" VALUES ($1, $2, $3)"
|
" VALUES ($1, $2, $3)"
|
||||||
|
|
||||||
const deleteQueueEDUSQL = "" +
|
const deleteQueueEDUSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_edus WHERE server_name = $1 AND json_nid = ANY($2)"
|
"DELETE FROM federationsender_queue_edus WHERE server_name = $1 AND json_nid = ANY($2)"
|
||||||
|
|
||||||
const selectQueueEDUSQL = "" +
|
const selectQueueEDUSQL = "" +
|
||||||
"SELECT json_nid FROM federationapi_queue_edus" +
|
"SELECT json_nid FROM federationsender_queue_edus" +
|
||||||
" WHERE server_name = $1" +
|
" WHERE server_name = $1" +
|
||||||
" LIMIT $2"
|
" LIMIT $2"
|
||||||
|
|
||||||
const selectQueueEDUReferenceJSONCountSQL = "" +
|
const selectQueueEDUReferenceJSONCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_edus" +
|
"SELECT COUNT(*) FROM federationsender_queue_edus" +
|
||||||
" WHERE json_nid = $1"
|
" WHERE json_nid = $1"
|
||||||
|
|
||||||
const selectQueueEDUCountSQL = "" +
|
const selectQueueEDUCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_edus" +
|
"SELECT COUNT(*) FROM federationsender_queue_edus" +
|
||||||
" WHERE server_name = $1"
|
" WHERE server_name = $1"
|
||||||
|
|
||||||
const selectQueueServerNamesSQL = "" +
|
const selectQueueServerNamesSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_queue_edus"
|
"SELECT DISTINCT server_name FROM federationsender_queue_edus"
|
||||||
|
|
||||||
type queueEDUsStatements struct {
|
type queueEDUsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const queueJSONSchema = `
|
const queueJSONSchema = `
|
||||||
-- The federationapi_queue_json table contains event contents that
|
-- The federationsender_queue_json table contains event contents that
|
||||||
-- we failed to send.
|
-- we failed to send.
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_json (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_json (
|
||||||
-- The JSON NID. This allows the federationapi_queue_retry table to
|
-- The JSON NID. This allows the federationsender_queue_retry table to
|
||||||
-- cross-reference to find the JSON blob.
|
-- cross-reference to find the JSON blob.
|
||||||
json_nid BIGSERIAL,
|
json_nid BIGSERIAL,
|
||||||
-- The JSON body. Text so that we preserve UTF-8.
|
-- The JSON body. Text so that we preserve UTF-8.
|
||||||
|
|
@ -36,15 +36,15 @@ CREATE TABLE IF NOT EXISTS federationapi_queue_json (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertJSONSQL = "" +
|
const insertJSONSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_json (json_body)" +
|
"INSERT INTO federationsender_queue_json (json_body)" +
|
||||||
" VALUES ($1)" +
|
" VALUES ($1)" +
|
||||||
" RETURNING json_nid"
|
" RETURNING json_nid"
|
||||||
|
|
||||||
const deleteJSONSQL = "" +
|
const deleteJSONSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_json WHERE json_nid = ANY($1)"
|
"DELETE FROM federationsender_queue_json WHERE json_nid = ANY($1)"
|
||||||
|
|
||||||
const selectJSONSQL = "" +
|
const selectJSONSQL = "" +
|
||||||
"SELECT json_nid, json_body FROM federationapi_queue_json" +
|
"SELECT json_nid, json_body FROM federationsender_queue_json" +
|
||||||
" WHERE json_nid = ANY($1)"
|
" WHERE json_nid = ANY($1)"
|
||||||
|
|
||||||
type queueJSONStatements struct {
|
type queueJSONStatements struct {
|
||||||
|
|
|
||||||
|
|
@ -25,41 +25,41 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const queuePDUsSchema = `
|
const queuePDUsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_pdus (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_pdus (
|
||||||
-- The transaction ID that was generated before persisting the event.
|
-- The transaction ID that was generated before persisting the event.
|
||||||
transaction_id TEXT NOT NULL,
|
transaction_id TEXT NOT NULL,
|
||||||
-- The destination server that we will send the event to.
|
-- The destination server that we will send the event to.
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
-- The JSON NID from the federationapi_queue_pdus_json table.
|
-- The JSON NID from the federationsender_queue_pdus_json table.
|
||||||
json_nid BIGINT NOT NULL
|
json_nid BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationapi_queue_pdus_pdus_json_nid_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_pdus_pdus_json_nid_idx
|
||||||
ON federationapi_queue_pdus (json_nid, server_name);
|
ON federationsender_queue_pdus (json_nid, server_name);
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertQueuePDUSQL = "" +
|
const insertQueuePDUSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_pdus (transaction_id, server_name, json_nid)" +
|
"INSERT INTO federationsender_queue_pdus (transaction_id, server_name, json_nid)" +
|
||||||
" VALUES ($1, $2, $3)"
|
" VALUES ($1, $2, $3)"
|
||||||
|
|
||||||
const deleteQueuePDUSQL = "" +
|
const deleteQueuePDUSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_pdus WHERE server_name = $1 AND json_nid = ANY($2)"
|
"DELETE FROM federationsender_queue_pdus WHERE server_name = $1 AND json_nid = ANY($2)"
|
||||||
|
|
||||||
const selectQueuePDUsSQL = "" +
|
const selectQueuePDUsSQL = "" +
|
||||||
"SELECT json_nid FROM federationapi_queue_pdus" +
|
"SELECT json_nid FROM federationsender_queue_pdus" +
|
||||||
" WHERE server_name = $1" +
|
" WHERE server_name = $1" +
|
||||||
" LIMIT $2"
|
" LIMIT $2"
|
||||||
|
|
||||||
const selectQueuePDUReferenceJSONCountSQL = "" +
|
const selectQueuePDUReferenceJSONCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_pdus" +
|
"SELECT COUNT(*) FROM federationsender_queue_pdus" +
|
||||||
" WHERE json_nid = $1"
|
" WHERE json_nid = $1"
|
||||||
|
|
||||||
const selectQueuePDUsCountSQL = "" +
|
const selectQueuePDUsCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_pdus" +
|
"SELECT COUNT(*) FROM federationsender_queue_pdus" +
|
||||||
" WHERE server_name = $1"
|
" WHERE server_name = $1"
|
||||||
|
|
||||||
const selectQueuePDUServerNamesSQL = "" +
|
const selectQueuePDUServerNamesSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_queue_pdus"
|
"SELECT DISTINCT server_name FROM federationsender_queue_pdus"
|
||||||
|
|
||||||
type queuePDUsStatements struct {
|
type queuePDUsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const blacklistSchema = `
|
const blacklistSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_blacklist (
|
CREATE TABLE IF NOT EXISTS federationsender_blacklist (
|
||||||
-- The blacklisted server name
|
-- The blacklisted server name
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
UNIQUE (server_name)
|
UNIQUE (server_name)
|
||||||
|
|
@ -31,17 +31,17 @@ CREATE TABLE IF NOT EXISTS federationapi_blacklist (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertBlacklistSQL = "" +
|
const insertBlacklistSQL = "" +
|
||||||
"INSERT INTO federationapi_blacklist (server_name) VALUES ($1)" +
|
"INSERT INTO federationsender_blacklist (server_name) VALUES ($1)" +
|
||||||
" ON CONFLICT DO NOTHING"
|
" ON CONFLICT DO NOTHING"
|
||||||
|
|
||||||
const selectBlacklistSQL = "" +
|
const selectBlacklistSQL = "" +
|
||||||
"SELECT server_name FROM federationapi_blacklist WHERE server_name = $1"
|
"SELECT server_name FROM federationsender_blacklist WHERE server_name = $1"
|
||||||
|
|
||||||
const deleteBlacklistSQL = "" +
|
const deleteBlacklistSQL = "" +
|
||||||
"DELETE FROM federationapi_blacklist WHERE server_name = $1"
|
"DELETE FROM federationsender_blacklist WHERE server_name = $1"
|
||||||
|
|
||||||
const deleteAllBlacklistSQL = "" +
|
const deleteAllBlacklistSQL = "" +
|
||||||
"DELETE FROM federationapi_blacklist"
|
"DELETE FROM federationsender_blacklist"
|
||||||
|
|
||||||
type blacklistStatements struct {
|
type blacklistStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func LoadRemoveRoomsTable(m *sqlutil.Migrations) {
|
||||||
|
|
||||||
func UpRemoveRoomsTable(tx *sql.Tx) error {
|
func UpRemoveRoomsTable(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec(`
|
_, err := tx.Exec(`
|
||||||
DROP TABLE IF EXISTS federationapi_rooms;
|
DROP TABLE IF EXISTS federationsender_rooms;
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const inboundPeeksSchema = `
|
const inboundPeeksSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_inbound_peeks (
|
CREATE TABLE IF NOT EXISTS federationsender_inbound_peeks (
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
peek_id TEXT NOT NULL,
|
peek_id TEXT NOT NULL,
|
||||||
|
|
@ -38,22 +38,22 @@ CREATE TABLE IF NOT EXISTS federationapi_inbound_peeks (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertInboundPeekSQL = "" +
|
const insertInboundPeekSQL = "" +
|
||||||
"INSERT INTO federationapi_inbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
"INSERT INTO federationsender_inbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
||||||
|
|
||||||
const selectInboundPeekSQL = "" +
|
const selectInboundPeekSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_inbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_inbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
||||||
|
|
||||||
const selectInboundPeeksSQL = "" +
|
const selectInboundPeeksSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_inbound_peeks WHERE room_id = $1"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_inbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
const renewInboundPeekSQL = "" +
|
const renewInboundPeekSQL = "" +
|
||||||
"UPDATE federationapi_inbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
"UPDATE federationsender_inbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
||||||
|
|
||||||
const deleteInboundPeekSQL = "" +
|
const deleteInboundPeekSQL = "" +
|
||||||
"DELETE FROM federationapi_inbound_peeks WHERE room_id = $1 and server_name = $2"
|
"DELETE FROM federationsender_inbound_peeks WHERE room_id = $1 and server_name = $2"
|
||||||
|
|
||||||
const deleteInboundPeeksSQL = "" +
|
const deleteInboundPeeksSQL = "" +
|
||||||
"DELETE FROM federationapi_inbound_peeks WHERE room_id = $1"
|
"DELETE FROM federationsender_inbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
type inboundPeeksStatements struct {
|
type inboundPeeksStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ const joinedHostsSchema = `
|
||||||
-- The joined_hosts table stores a list of m.room.member event ids in the
|
-- The joined_hosts table stores a list of m.room.member event ids in the
|
||||||
-- current state for each room where the membership is "join".
|
-- current state for each room where the membership is "join".
|
||||||
-- There will be an entry for every user that is joined to the room.
|
-- There will be an entry for every user that is joined to the room.
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_joined_hosts (
|
CREATE TABLE IF NOT EXISTS federationsender_joined_hosts (
|
||||||
-- The string ID of the room.
|
-- The string ID of the room.
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
-- The event ID of the m.room.member join event.
|
-- The event ID of the m.room.member join event.
|
||||||
|
|
@ -40,31 +40,31 @@ CREATE TABLE IF NOT EXISTS federationapi_joined_hosts (
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federatonsender_joined_hosts_event_id_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federatonsender_joined_hosts_event_id_idx
|
||||||
ON federationapi_joined_hosts (event_id);
|
ON federationsender_joined_hosts (event_id);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS federatonsender_joined_hosts_room_id_idx
|
CREATE INDEX IF NOT EXISTS federatonsender_joined_hosts_room_id_idx
|
||||||
ON federationapi_joined_hosts (room_id)
|
ON federationsender_joined_hosts (room_id)
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertJoinedHostsSQL = "" +
|
const insertJoinedHostsSQL = "" +
|
||||||
"INSERT OR IGNORE INTO federationapi_joined_hosts (room_id, event_id, server_name)" +
|
"INSERT OR IGNORE INTO federationsender_joined_hosts (room_id, event_id, server_name)" +
|
||||||
" VALUES ($1, $2, $3)"
|
" VALUES ($1, $2, $3)"
|
||||||
|
|
||||||
const deleteJoinedHostsSQL = "" +
|
const deleteJoinedHostsSQL = "" +
|
||||||
"DELETE FROM federationapi_joined_hosts WHERE event_id = $1"
|
"DELETE FROM federationsender_joined_hosts WHERE event_id = $1"
|
||||||
|
|
||||||
const deleteJoinedHostsForRoomSQL = "" +
|
const deleteJoinedHostsForRoomSQL = "" +
|
||||||
"DELETE FROM federationapi_joined_hosts WHERE room_id = $1"
|
"DELETE FROM federationsender_joined_hosts WHERE room_id = $1"
|
||||||
|
|
||||||
const selectJoinedHostsSQL = "" +
|
const selectJoinedHostsSQL = "" +
|
||||||
"SELECT event_id, server_name FROM federationapi_joined_hosts" +
|
"SELECT event_id, server_name FROM federationsender_joined_hosts" +
|
||||||
" WHERE room_id = $1"
|
" WHERE room_id = $1"
|
||||||
|
|
||||||
const selectAllJoinedHostsSQL = "" +
|
const selectAllJoinedHostsSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_joined_hosts"
|
"SELECT DISTINCT server_name FROM federationsender_joined_hosts"
|
||||||
|
|
||||||
const selectJoinedHostsForRoomsSQL = "" +
|
const selectJoinedHostsForRoomsSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_joined_hosts WHERE room_id IN ($1)"
|
"SELECT DISTINCT server_name FROM federationsender_joined_hosts WHERE room_id IN ($1)"
|
||||||
|
|
||||||
type joinedHostsStatements struct {
|
type joinedHostsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const notaryServerKeysJSONSchema = `
|
const notaryServerKeysJSONSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_json (
|
CREATE TABLE IF NOT EXISTS federationsender_notary_server_keys_json (
|
||||||
notary_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
notary_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
response_json TEXT NOT NULL,
|
response_json TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
|
|
@ -32,7 +32,7 @@ CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_json (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertServerKeysJSONSQL = "" +
|
const insertServerKeysJSONSQL = "" +
|
||||||
"INSERT INTO federationapi_notary_server_keys_json (response_json, server_name, valid_until) VALUES ($1, $2, $3)" +
|
"INSERT INTO federationsender_notary_server_keys_json (response_json, server_name, valid_until) VALUES ($1, $2, $3)" +
|
||||||
" RETURNING notary_id"
|
" RETURNING notary_id"
|
||||||
|
|
||||||
type notaryServerKeysStatements struct {
|
type notaryServerKeysStatements struct {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const notaryServerKeysMetadataSchema = `
|
const notaryServerKeysMetadataSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_metadata (
|
CREATE TABLE IF NOT EXISTS federationsender_notary_server_keys_metadata (
|
||||||
notary_id BIGINT NOT NULL,
|
notary_id BIGINT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
key_id TEXT NOT NULL,
|
key_id TEXT NOT NULL,
|
||||||
|
|
@ -37,41 +37,41 @@ CREATE TABLE IF NOT EXISTS federationapi_notary_server_keys_metadata (
|
||||||
`
|
`
|
||||||
|
|
||||||
const upsertServerKeysSQL = "" +
|
const upsertServerKeysSQL = "" +
|
||||||
"INSERT INTO federationapi_notary_server_keys_metadata (notary_id, server_name, key_id) VALUES ($1, $2, $3)" +
|
"INSERT INTO federationsender_notary_server_keys_metadata (notary_id, server_name, key_id) VALUES ($1, $2, $3)" +
|
||||||
" ON CONFLICT (server_name, key_id) DO UPDATE SET notary_id = $1"
|
" ON CONFLICT (server_name, key_id) DO UPDATE SET notary_id = $1"
|
||||||
|
|
||||||
// for a given (server_name, key_id), find the existing notary ID and valid until. Used to check if we will replace it
|
// for a given (server_name, key_id), find the existing notary ID and valid until. Used to check if we will replace it
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyMetadataSQL = `
|
const selectNotaryKeyMetadataSQL = `
|
||||||
SELECT federationapi_notary_server_keys_metadata.notary_id, valid_until FROM federationapi_notary_server_keys_json
|
SELECT federationsender_notary_server_keys_metadata.notary_id, valid_until FROM federationsender_notary_server_keys_json
|
||||||
JOIN federationapi_notary_server_keys_metadata ON
|
JOIN federationsender_notary_server_keys_metadata ON
|
||||||
federationapi_notary_server_keys_metadata.notary_id = federationapi_notary_server_keys_json.notary_id
|
federationsender_notary_server_keys_metadata.notary_id = federationsender_notary_server_keys_json.notary_id
|
||||||
WHERE federationapi_notary_server_keys_metadata.server_name = $1 AND federationapi_notary_server_keys_metadata.key_id = $2
|
WHERE federationsender_notary_server_keys_metadata.server_name = $1 AND federationsender_notary_server_keys_metadata.key_id = $2
|
||||||
`
|
`
|
||||||
|
|
||||||
// select the response which has the highest valid_until value
|
// select the response which has the highest valid_until value
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyResponsesSQL = `
|
const selectNotaryKeyResponsesSQL = `
|
||||||
SELECT response_json FROM federationapi_notary_server_keys_json
|
SELECT response_json FROM federationsender_notary_server_keys_json
|
||||||
WHERE server_name = $1 AND valid_until = (
|
WHERE server_name = $1 AND valid_until = (
|
||||||
SELECT MAX(valid_until) FROM federationapi_notary_server_keys_json WHERE server_name = $1
|
SELECT MAX(valid_until) FROM federationsender_notary_server_keys_json WHERE server_name = $1
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
// select the responses which have the given key IDs
|
// select the responses which have the given key IDs
|
||||||
// JOINs with the json table
|
// JOINs with the json table
|
||||||
const selectNotaryKeyResponsesWithKeyIDsSQL = `
|
const selectNotaryKeyResponsesWithKeyIDsSQL = `
|
||||||
SELECT response_json FROM federationapi_notary_server_keys_json
|
SELECT response_json FROM federationsender_notary_server_keys_json
|
||||||
JOIN federationapi_notary_server_keys_metadata ON
|
JOIN federationsender_notary_server_keys_metadata ON
|
||||||
federationapi_notary_server_keys_metadata.notary_id = federationapi_notary_server_keys_json.notary_id
|
federationsender_notary_server_keys_metadata.notary_id = federationsender_notary_server_keys_json.notary_id
|
||||||
WHERE federationapi_notary_server_keys_json.server_name = $1 AND federationapi_notary_server_keys_metadata.key_id IN ($2)
|
WHERE federationsender_notary_server_keys_json.server_name = $1 AND federationsender_notary_server_keys_metadata.key_id IN ($2)
|
||||||
GROUP BY federationapi_notary_server_keys_json.notary_id
|
GROUP BY federationsender_notary_server_keys_json.notary_id
|
||||||
`
|
`
|
||||||
|
|
||||||
// JOINs with the metadata table
|
// JOINs with the metadata table
|
||||||
const deleteUnusedServerKeysJSONSQL = `
|
const deleteUnusedServerKeysJSONSQL = `
|
||||||
DELETE FROM federationapi_notary_server_keys_json WHERE federationapi_notary_server_keys_json.notary_id NOT IN (
|
DELETE FROM federationsender_notary_server_keys_json WHERE federationsender_notary_server_keys_json.notary_id NOT IN (
|
||||||
SELECT DISTINCT notary_id FROM federationapi_notary_server_keys_metadata
|
SELECT DISTINCT notary_id FROM federationsender_notary_server_keys_metadata
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const outboundPeeksSchema = `
|
const outboundPeeksSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_outbound_peeks (
|
CREATE TABLE IF NOT EXISTS federationsender_outbound_peeks (
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
peek_id TEXT NOT NULL,
|
peek_id TEXT NOT NULL,
|
||||||
|
|
@ -38,22 +38,22 @@ CREATE TABLE IF NOT EXISTS federationapi_outbound_peeks (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertOutboundPeekSQL = "" +
|
const insertOutboundPeekSQL = "" +
|
||||||
"INSERT INTO federationapi_outbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
"INSERT INTO federationsender_outbound_peeks (room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval) VALUES ($1, $2, $3, $4, $5, $6)"
|
||||||
|
|
||||||
const selectOutboundPeekSQL = "" +
|
const selectOutboundPeekSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_outbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_outbound_peeks WHERE room_id = $1 and server_name = $2 and peek_id = $3"
|
||||||
|
|
||||||
const selectOutboundPeeksSQL = "" +
|
const selectOutboundPeeksSQL = "" +
|
||||||
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationapi_outbound_peeks WHERE room_id = $1"
|
"SELECT room_id, server_name, peek_id, creation_ts, renewed_ts, renewal_interval FROM federationsender_outbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
const renewOutboundPeekSQL = "" +
|
const renewOutboundPeekSQL = "" +
|
||||||
"UPDATE federationapi_outbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
"UPDATE federationsender_outbound_peeks SET renewed_ts=$1, renewal_interval=$2 WHERE room_id = $3 and server_name = $4 and peek_id = $5"
|
||||||
|
|
||||||
const deleteOutboundPeekSQL = "" +
|
const deleteOutboundPeekSQL = "" +
|
||||||
"DELETE FROM federationapi_outbound_peeks WHERE room_id = $1 and server_name = $2"
|
"DELETE FROM federationsender_outbound_peeks WHERE room_id = $1 and server_name = $2"
|
||||||
|
|
||||||
const deleteOutboundPeeksSQL = "" +
|
const deleteOutboundPeeksSQL = "" +
|
||||||
"DELETE FROM federationapi_outbound_peeks WHERE room_id = $1"
|
"DELETE FROM federationsender_outbound_peeks WHERE room_id = $1"
|
||||||
|
|
||||||
type outboundPeeksStatements struct {
|
type outboundPeeksStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -26,41 +26,41 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const queueEDUsSchema = `
|
const queueEDUsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_edus (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_edus (
|
||||||
-- The type of the event (informational).
|
-- The type of the event (informational).
|
||||||
edu_type TEXT NOT NULL,
|
edu_type TEXT NOT NULL,
|
||||||
-- The domain part of the user ID the EDU event is for.
|
-- The domain part of the user ID the EDU event is for.
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
-- The JSON NID from the federationapi_queue_edus_json table.
|
-- The JSON NID from the federationsender_queue_edus_json table.
|
||||||
json_nid BIGINT NOT NULL
|
json_nid BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationapi_queue_edus_json_nid_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_edus_json_nid_idx
|
||||||
ON federationapi_queue_edus (json_nid, server_name);
|
ON federationsender_queue_edus (json_nid, server_name);
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertQueueEDUSQL = "" +
|
const insertQueueEDUSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_edus (edu_type, server_name, json_nid)" +
|
"INSERT INTO federationsender_queue_edus (edu_type, server_name, json_nid)" +
|
||||||
" VALUES ($1, $2, $3)"
|
" VALUES ($1, $2, $3)"
|
||||||
|
|
||||||
const deleteQueueEDUsSQL = "" +
|
const deleteQueueEDUsSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_edus WHERE server_name = $1 AND json_nid IN ($2)"
|
"DELETE FROM federationsender_queue_edus WHERE server_name = $1 AND json_nid IN ($2)"
|
||||||
|
|
||||||
const selectQueueEDUSQL = "" +
|
const selectQueueEDUSQL = "" +
|
||||||
"SELECT json_nid FROM federationapi_queue_edus" +
|
"SELECT json_nid FROM federationsender_queue_edus" +
|
||||||
" WHERE server_name = $1" +
|
" WHERE server_name = $1" +
|
||||||
" LIMIT $2"
|
" LIMIT $2"
|
||||||
|
|
||||||
const selectQueueEDUReferenceJSONCountSQL = "" +
|
const selectQueueEDUReferenceJSONCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_edus" +
|
"SELECT COUNT(*) FROM federationsender_queue_edus" +
|
||||||
" WHERE json_nid = $1"
|
" WHERE json_nid = $1"
|
||||||
|
|
||||||
const selectQueueEDUCountSQL = "" +
|
const selectQueueEDUCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_edus" +
|
"SELECT COUNT(*) FROM federationsender_queue_edus" +
|
||||||
" WHERE server_name = $1"
|
" WHERE server_name = $1"
|
||||||
|
|
||||||
const selectQueueServerNamesSQL = "" +
|
const selectQueueServerNamesSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_queue_edus"
|
"SELECT DISTINCT server_name FROM federationsender_queue_edus"
|
||||||
|
|
||||||
type queueEDUsStatements struct {
|
type queueEDUsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
const queueJSONSchema = `
|
const queueJSONSchema = `
|
||||||
-- The queue_retry_json table contains event contents that
|
-- The queue_retry_json table contains event contents that
|
||||||
-- we failed to send.
|
-- we failed to send.
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_json (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_json (
|
||||||
-- The JSON NID. This allows the federationapi_queue_retry table to
|
-- The JSON NID. This allows the federationsender_queue_retry table to
|
||||||
-- cross-reference to find the JSON blob.
|
-- cross-reference to find the JSON blob.
|
||||||
json_nid INTEGER PRIMARY KEY AUTOINCREMENT,
|
json_nid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
-- The JSON body. Text so that we preserve UTF-8.
|
-- The JSON body. Text so that we preserve UTF-8.
|
||||||
|
|
@ -38,14 +38,14 @@ CREATE TABLE IF NOT EXISTS federationapi_queue_json (
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertJSONSQL = "" +
|
const insertJSONSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_json (json_body)" +
|
"INSERT INTO federationsender_queue_json (json_body)" +
|
||||||
" VALUES ($1)"
|
" VALUES ($1)"
|
||||||
|
|
||||||
const deleteJSONSQL = "" +
|
const deleteJSONSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_json WHERE json_nid IN ($1)"
|
"DELETE FROM federationsender_queue_json WHERE json_nid IN ($1)"
|
||||||
|
|
||||||
const selectJSONSQL = "" +
|
const selectJSONSQL = "" +
|
||||||
"SELECT json_nid, json_body FROM federationapi_queue_json" +
|
"SELECT json_nid, json_body FROM federationsender_queue_json" +
|
||||||
" WHERE json_nid IN ($1)"
|
" WHERE json_nid IN ($1)"
|
||||||
|
|
||||||
type queueJSONStatements struct {
|
type queueJSONStatements struct {
|
||||||
|
|
|
||||||
|
|
@ -27,47 +27,47 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const queuePDUsSchema = `
|
const queuePDUsSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS federationapi_queue_pdus (
|
CREATE TABLE IF NOT EXISTS federationsender_queue_pdus (
|
||||||
-- The transaction ID that was generated before persisting the event.
|
-- The transaction ID that was generated before persisting the event.
|
||||||
transaction_id TEXT NOT NULL,
|
transaction_id TEXT NOT NULL,
|
||||||
-- The domain part of the user ID the m.room.member event is for.
|
-- The domain part of the user ID the m.room.member event is for.
|
||||||
server_name TEXT NOT NULL,
|
server_name TEXT NOT NULL,
|
||||||
-- The JSON NID from the federationapi_queue_pdus_json table.
|
-- The JSON NID from the federationsender_queue_pdus_json table.
|
||||||
json_nid BIGINT NOT NULL
|
json_nid BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS federationapi_queue_pdus_pdus_json_nid_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS federationsender_queue_pdus_pdus_json_nid_idx
|
||||||
ON federationapi_queue_pdus (json_nid, server_name);
|
ON federationsender_queue_pdus (json_nid, server_name);
|
||||||
`
|
`
|
||||||
|
|
||||||
const insertQueuePDUSQL = "" +
|
const insertQueuePDUSQL = "" +
|
||||||
"INSERT INTO federationapi_queue_pdus (transaction_id, server_name, json_nid)" +
|
"INSERT INTO federationsender_queue_pdus (transaction_id, server_name, json_nid)" +
|
||||||
" VALUES ($1, $2, $3)"
|
" VALUES ($1, $2, $3)"
|
||||||
|
|
||||||
const deleteQueuePDUsSQL = "" +
|
const deleteQueuePDUsSQL = "" +
|
||||||
"DELETE FROM federationapi_queue_pdus WHERE server_name = $1 AND json_nid IN ($2)"
|
"DELETE FROM federationsender_queue_pdus WHERE server_name = $1 AND json_nid IN ($2)"
|
||||||
|
|
||||||
const selectQueueNextTransactionIDSQL = "" +
|
const selectQueueNextTransactionIDSQL = "" +
|
||||||
"SELECT transaction_id FROM federationapi_queue_pdus" +
|
"SELECT transaction_id FROM federationsender_queue_pdus" +
|
||||||
" WHERE server_name = $1" +
|
" WHERE server_name = $1" +
|
||||||
" ORDER BY transaction_id ASC" +
|
" ORDER BY transaction_id ASC" +
|
||||||
" LIMIT 1"
|
" LIMIT 1"
|
||||||
|
|
||||||
const selectQueuePDUsSQL = "" +
|
const selectQueuePDUsSQL = "" +
|
||||||
"SELECT json_nid FROM federationapi_queue_pdus" +
|
"SELECT json_nid FROM federationsender_queue_pdus" +
|
||||||
" WHERE server_name = $1" +
|
" WHERE server_name = $1" +
|
||||||
" LIMIT $2"
|
" LIMIT $2"
|
||||||
|
|
||||||
const selectQueuePDUsReferenceJSONCountSQL = "" +
|
const selectQueuePDUsReferenceJSONCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_pdus" +
|
"SELECT COUNT(*) FROM federationsender_queue_pdus" +
|
||||||
" WHERE json_nid = $1"
|
" WHERE json_nid = $1"
|
||||||
|
|
||||||
const selectQueuePDUsCountSQL = "" +
|
const selectQueuePDUsCountSQL = "" +
|
||||||
"SELECT COUNT(*) FROM federationapi_queue_pdus" +
|
"SELECT COUNT(*) FROM federationsender_queue_pdus" +
|
||||||
" WHERE server_name = $1"
|
" WHERE server_name = $1"
|
||||||
|
|
||||||
const selectQueuePDUsServerNamesSQL = "" +
|
const selectQueuePDUsServerNamesSQL = "" +
|
||||||
"SELECT DISTINCT server_name FROM federationapi_queue_pdus"
|
"SELECT DISTINCT server_name FROM federationsender_queue_pdus"
|
||||||
|
|
||||||
type queuePDUsStatements struct {
|
type queuePDUsStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue