Fix state block schema a bit

This commit is contained in:
Neil Alexander 2020-01-13 14:53:03 +00:00
parent 8bb8642560
commit 7a7be4f0ac
3 changed files with 6 additions and 6 deletions

View file

@ -28,7 +28,7 @@ import (
const stateDataSchema = `
CREATE TABLE IF NOT EXISTS roomserver_state_block (
state_block_nid INTEGER NOT NULL,
state_block_nid INTEGER PRIMARY KEY AUTOINCREMENT,
event_type_nid INTEGER NOT NULL,
event_state_key_nid INTEGER NOT NULL,
event_nid INTEGER NOT NULL,
@ -41,7 +41,10 @@ const insertStateDataSQL = "" +
" VALUES ($1, $2, $3, $4)"
const selectNextStateBlockNIDSQL = `
SELECT seq+1 FROM sqlite_sequence WHERE name = 'roomserver_state_block'
SELECT COALESCE((
SELECT seq AS state_block_nid FROM sqlite_sequence
WHERE name = 'roomserver_state_block'), 0
) AS state_block_nid
`
// Bulk state lookup by numeric state block ID.

View file

@ -88,7 +88,7 @@ func (s *stateSnapshotStatements) bulkSelectStateBlockNIDs(
for i := range stateNIDs {
nids[i] = int64(stateNIDs[i])
}
rows, err := s.bulkSelectStateBlockNIDsStmt.QueryContext(ctx, pq.Int64Array(nids))
rows, err := s.bulkSelectStateBlockNIDsStmt.QueryContext(ctx, sqliteIn(pq.Int64Array(nids)))
if err != nil {
return nil, err
}

View file

@ -18,7 +18,6 @@ package sqlite3
import (
"context"
"database/sql"
"fmt"
"net/url"
"github.com/matrix-org/dendrite/roomserver/api"
@ -245,11 +244,9 @@ func (d *Database) AddState(
if len(state) > 0 {
stateBlockNID, err := d.statements.selectNextStateBlockNID(ctx)
if err != nil {
fmt.Println("d.statements.selectNextStateBlockNID", err)
return 0, err
}
if err = d.statements.bulkInsertStateData(ctx, stateBlockNID, state); err != nil {
fmt.Println("d.statements.bulkInsertStateData", err)
return 0, err
}
stateBlockNIDs = append(stateBlockNIDs[:len(stateBlockNIDs):len(stateBlockNIDs)], stateBlockNID)