aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/postgres/rooms_table.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-03-16 16:05:29 +0000
committerGitHub <noreply@github.com>2020-03-16 16:05:29 +0000
commit452f393dd7de5203c5cd3ebe5697af6ea0f4b009 (patch)
treebe995775e8e8b424ff6fa6ff6a06025504d95870 /roomserver/storage/postgres/rooms_table.go
parentdfd8b93d93a586f0c4400b3a317c978a1c0e04d9 (diff)
Update room version descriptors, add error handling (#906)
* Update room version descriptors, add error handling * Fix database queries * Drop Get from version package * Fix database wrapping, add comments for version descriptions * Don't set default room_version value in SQL
Diffstat (limited to 'roomserver/storage/postgres/rooms_table.go')
-rw-r--r--roomserver/storage/postgres/rooms_table.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/roomserver/storage/postgres/rooms_table.go b/roomserver/storage/postgres/rooms_table.go
index edd15a33..ef8b8ece 100644
--- a/roomserver/storage/postgres/rooms_table.go
+++ b/roomserver/storage/postgres/rooms_table.go
@@ -22,6 +22,7 @@ import (
"github.com/lib/pq"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/types"
+ "github.com/matrix-org/gomatrixserverlib"
)
const roomsSchema = `
@@ -42,13 +43,13 @@ CREATE TABLE IF NOT EXISTS roomserver_rooms (
state_snapshot_nid BIGINT NOT NULL DEFAULT 0,
-- The version of the room, which will assist in determining the state resolution
-- algorithm, event ID format, etc.
- room_version BIGINT NOT NULL DEFAULT 1
+ room_version TEXT NOT NULL
);
`
// Same as insertEventTypeNIDSQL
const insertRoomNIDSQL = "" +
- "INSERT INTO roomserver_rooms (room_id) VALUES ($1)" +
+ "INSERT INTO roomserver_rooms (room_id, room_version) VALUES ($1, $2)" +
" ON CONFLICT ON CONSTRAINT roomserver_room_id_unique" +
" DO NOTHING RETURNING (room_nid)"
@@ -92,11 +93,12 @@ func (s *roomStatements) prepare(db *sql.DB) (err error) {
}
func (s *roomStatements) insertRoomNID(
- ctx context.Context, txn *sql.Tx, roomID string,
+ ctx context.Context, txn *sql.Tx,
+ roomID string, roomVersion gomatrixserverlib.RoomVersion,
) (types.RoomNID, error) {
var roomNID int64
stmt := common.TxStmt(txn, s.insertRoomNIDStmt)
- err := stmt.QueryRowContext(ctx, roomID).Scan(&roomNID)
+ err := stmt.QueryRowContext(ctx, roomID, roomVersion).Scan(&roomNID)
return types.RoomNID(roomNID), err
}
@@ -165,8 +167,8 @@ func (s *roomStatements) updateLatestEventNIDs(
func (s *roomStatements) selectRoomVersionForRoomNID(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
-) (int64, error) {
- var roomVersion int64
+) (gomatrixserverlib.RoomVersion, error) {
+ var roomVersion gomatrixserverlib.RoomVersion
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
return roomVersion, err