Error: "💥 Preparing selectPushersByLocalpartStmt..." func="prepare" file=" [/src/userapi/storage/pushers/sqlite3/pushers_table.go:69]" error="no such column: pushkey"

This commit is contained in:
Dan Peleg 2021-04-24 16:12:06 +03:00
parent ae0c118238
commit a1d1f2b02c
7 changed files with 37 additions and 30 deletions

View file

@ -1,5 +1,5 @@
#!/bin/sh
for db in userapi_accounts userapi_devices mediaapi syncapi roomserver signingkeyserver keyserver federationsender appservice naffka; do
for db in userapi_accounts userapi_devices userapi_pushers mediaapi syncapi roomserver signingkeyserver keyserver federationsender appservice naffka; do
createdb -U dendrite -O dendrite dendrite_$db
done

View file

@ -126,6 +126,7 @@ func main() {
cfg.FederationSender.FederationMaxRetries = 6
cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName))
cfg.UserAPI.DeviceDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-device.db", *instanceName))
cfg.UserAPI.PusherDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-pusher.db", *instanceName))
cfg.MediaAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-mediaapi.db", *instanceName))
cfg.SyncAPI.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-syncapi.db", *instanceName))
cfg.RoomServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-roomserver.db", *instanceName))

View file

@ -28,6 +28,7 @@ const (
SyncAPI = "syncapi"
UserAPIAccounts = "userapi_accounts"
UserAPIDevices = "userapi_devices"
UserAPIPushers = "userapi_pushers"
)
var (
@ -35,7 +36,7 @@ var (
flags = flag.NewFlagSet("goose", flag.ExitOnError)
component = flags.String("component", "", "dendrite component name")
knownDBs = []string{
AppService, FederationSender, KeyServer, MediaAPI, RoomServer, SigningKeyServer, SyncAPI, UserAPIAccounts, UserAPIDevices,
AppService, FederationSender, KeyServer, MediaAPI, RoomServer, SigningKeyServer, SyncAPI, UserAPIAccounts, UserAPIDevices, UserAPIPushers,
}
)

View file

@ -109,7 +109,7 @@ On macOS, omit `sudo -u postgres` from the below commands.
* If you want to run each Dendrite component with its own database:
```bash
for i in mediaapi syncapi roomserver signingkeyserver federationsender appservice keyserver userapi_accounts userapi_devices naffka; do
for i in mediaapi syncapi roomserver signingkeyserver federationsender appservice keyserver userapi_accounts userapi_devices userapi_pushers naffka; do
sudo -u postgres createdb -O dendrite dendrite_$i
done
```

View file

@ -30,7 +30,11 @@ const pushersSchema = `
CREATE TABLE IF NOT EXISTS pusher_pushers (
-- The Matrix user ID localpart for this pusher
localpart TEXT NOT NULL PRIMARY KEY,
-- This is a unique identifier for this pusher. See /set for more detail. Max length, 512 bytes.
-- This is a unique identifier for this pusher.
-- The value you should use for this is the routing or destination address information for the notification, for example,
-- the APNS token for APNS or the Registration ID for GCM. If your notification client has no such concept, use any unique identifier.
-- If the kind is "email", this is the email address to send notifications to.
-- Max length, 512 bytes.
pushkey VARCHAR(512) NOT NULL,
-- The kind of pusher. "http" is a pusher that sends HTTP pokes.
kind TEXT,
@ -47,15 +51,15 @@ CREATE TABLE IF NOT EXISTS pusher_pushers (
-- Required if kind is http. The URL to use to send notifications to.
url TEXT,
-- The format to use when sending notifications to the Push Gateway.
format TEXT,
format TEXT
);
-- Pusher IDs must be unique for a given user.
-- Pushkey must be unique for a given user.
CREATE UNIQUE INDEX IF NOT EXISTS pusher_localpart_pushkey_idx ON pusher_pushers(localpart, pushkey);
`
const selectPushersByLocalpartSQL = "" +
"SELECT pushkey, kind, app_id, app_display_name, device_display_name, profile_tag, language, url, format FROM pusher_pushers WHERE localpart = $1"
"SELECT pushkey, kind, app_id, app_display_name, device_display_name, profile_tag, lang, url, format FROM pusher_pushers WHERE localpart = $1"
type pushersStatements struct {
selectPushersByLocalpartStmt *sql.Stmt
@ -91,8 +95,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
for rows.Next() {
var pusher api.Pusher
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, language, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &language, &url, &format)
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, lang, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &lang, &url, &format)
if err != nil {
return pushers, err
}
@ -114,8 +118,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
if profiletag.Valid {
pusher.ProfileTag = profiletag.String
}
if language.Valid {
pusher.Language = language.String
if lang.Valid {
pusher.Language = lang.String
}
if url.Valid && format.Valid {
pusher.Data = api.PusherData{

View file

@ -20,32 +20,31 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/gomatrixserverlib"
)
const pushersSchema = `
-- This sequence is used for automatic allocation of session_id.
-- CREATE SEQUENCE IF NOT EXISTS pusher_session_id_seq START 1;
-- Stores data about pushers.
CREATE TABLE IF NOT EXISTS pusher_pushers (
pushkey VARCHAR(512) PRIMARY KEY,
kind TEXT ,
app_id VARCHAR(64) ,
app_display_name TEXT,
device_display_name TEXT,
profile_tag TEXT,
language TEXT,
url TEXT,
format TEXT,
localpart TEXT PRIMARY KEY,
pushkey VARCHAR(512),
kind TEXT,
app_id VARCHAR(64),
app_display_name TEXT,
device_display_name TEXT,
profile_tag TEXT,
lang TEXT,
url TEXT,
format TEXT,
UNIQUE (localpart, pushkey)
UNIQUE (localpart, pushkey)
);
`
const selectPushersByLocalpartSQL = "" +
"SELECT pushkey, kind, app_id, app_display_name, device_display_name, profile_tag, language, url, format FROM pusher_pushers WHERE localpart = $1"
"SELECT pushkey, kind, app_id, app_display_name, device_display_name, profile_tag, lang, url, format FROM pusher_pushers WHERE localpart = $1"
type pushersStatements struct {
db *sql.DB
@ -63,6 +62,8 @@ func (s *pushersStatements) prepare(db *sql.DB, writer sqlutil.Writer, server go
s.db = db
s.writer = writer
if s.selectPushersByLocalpartStmt, err = db.Prepare(selectPushersByLocalpartSQL); err != nil {
logrus.WithError(err).Debug("💥💥💥 Preparing selectPushersByLocalpartStmt...")
return
return
}
s.serverName = server
@ -81,8 +82,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
for rows.Next() {
var pusher api.Pusher
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, language, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &language, &url, &format)
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, lang, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &lang, &url, &format)
if err != nil {
return pushers, err
}
@ -104,8 +105,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
if profiletag.Valid {
pusher.ProfileTag = profiletag.String
}
if language.Valid {
pusher.Language = language.String
if lang.Valid {
pusher.Language = lang.String
}
if url.Valid && format.Valid {
pusher.Data = api.PusherData{

View file

@ -45,7 +45,7 @@ func NewInternalAPI(
pusherDB, err := pushers.NewDatabase(&cfg.PusherDatabase, cfg.Matrix.ServerName)
if err != nil {
logrus.WithError(err).Panicf("failed to connect to device db")
logrus.WithError(err).Panicf("failed to connect to pusher db")
}
return &internal.UserInternalAPI{