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
This commit is contained in:
Neil Alexander 2020-03-16 16:05:29 +00:00 committed by GitHub
parent dfd8b93d93
commit 452f393dd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 121 additions and 95 deletions

View file

@ -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