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 #!/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 createdb -U dendrite -O dendrite dendrite_$db
done done

View file

@ -126,6 +126,7 @@ func main() {
cfg.FederationSender.FederationMaxRetries = 6 cfg.FederationSender.FederationMaxRetries = 6
cfg.UserAPI.AccountDatabase.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-account.db", *instanceName)) 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.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.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.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)) cfg.RoomServer.Database.ConnectionString = config.DataSource(fmt.Sprintf("file:%s-roomserver.db", *instanceName))

View file

@ -28,6 +28,7 @@ const (
SyncAPI = "syncapi" SyncAPI = "syncapi"
UserAPIAccounts = "userapi_accounts" UserAPIAccounts = "userapi_accounts"
UserAPIDevices = "userapi_devices" UserAPIDevices = "userapi_devices"
UserAPIPushers = "userapi_pushers"
) )
var ( var (
@ -35,7 +36,7 @@ var (
flags = flag.NewFlagSet("goose", flag.ExitOnError) flags = flag.NewFlagSet("goose", flag.ExitOnError)
component = flags.String("component", "", "dendrite component name") component = flags.String("component", "", "dendrite component name")
knownDBs = []string{ 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: * If you want to run each Dendrite component with its own database:
```bash ```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 sudo -u postgres createdb -O dendrite dendrite_$i
done done
``` ```

View file

@ -30,7 +30,11 @@ const pushersSchema = `
CREATE TABLE IF NOT EXISTS pusher_pushers ( CREATE TABLE IF NOT EXISTS pusher_pushers (
-- The Matrix user ID localpart for this pusher -- The Matrix user ID localpart for this pusher
localpart TEXT NOT NULL PRIMARY KEY, 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, pushkey VARCHAR(512) NOT NULL,
-- The kind of pusher. "http" is a pusher that sends HTTP pokes. -- The kind of pusher. "http" is a pusher that sends HTTP pokes.
kind TEXT, 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. -- Required if kind is http. The URL to use to send notifications to.
url TEXT, url TEXT,
-- The format to use when sending notifications to the Push Gateway. -- 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); CREATE UNIQUE INDEX IF NOT EXISTS pusher_localpart_pushkey_idx ON pusher_pushers(localpart, pushkey);
` `
const selectPushersByLocalpartSQL = "" + 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 { type pushersStatements struct {
selectPushersByLocalpartStmt *sql.Stmt selectPushersByLocalpartStmt *sql.Stmt
@ -91,8 +95,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
for rows.Next() { for rows.Next() {
var pusher api.Pusher var pusher api.Pusher
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, language, url, format sql.NullString var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, lang, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &language, &url, &format) err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &lang, &url, &format)
if err != nil { if err != nil {
return pushers, err return pushers, err
} }
@ -114,8 +118,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
if profiletag.Valid { if profiletag.Valid {
pusher.ProfileTag = profiletag.String pusher.ProfileTag = profiletag.String
} }
if language.Valid { if lang.Valid {
pusher.Language = language.String pusher.Language = lang.String
} }
if url.Valid && format.Valid { if url.Valid && format.Valid {
pusher.Data = api.PusherData{ pusher.Data = api.PusherData{

View file

@ -20,24 +20,23 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/api"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
const pushersSchema = ` 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. -- Stores data about pushers.
CREATE TABLE IF NOT EXISTS pusher_pushers ( CREATE TABLE IF NOT EXISTS pusher_pushers (
pushkey VARCHAR(512) PRIMARY KEY, localpart TEXT PRIMARY KEY,
kind TEXT , pushkey VARCHAR(512),
app_id VARCHAR(64) , kind TEXT,
app_id VARCHAR(64),
app_display_name TEXT, app_display_name TEXT,
device_display_name TEXT, device_display_name TEXT,
profile_tag TEXT, profile_tag TEXT,
language TEXT, lang TEXT,
url TEXT, url TEXT,
format TEXT, format TEXT,
@ -45,7 +44,7 @@ CREATE TABLE IF NOT EXISTS pusher_pushers (
); );
` `
const selectPushersByLocalpartSQL = "" + 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 { type pushersStatements struct {
db *sql.DB db *sql.DB
@ -63,6 +62,8 @@ func (s *pushersStatements) prepare(db *sql.DB, writer sqlutil.Writer, server go
s.db = db s.db = db
s.writer = writer s.writer = writer
if s.selectPushersByLocalpartStmt, err = db.Prepare(selectPushersByLocalpartSQL); err != nil { if s.selectPushersByLocalpartStmt, err = db.Prepare(selectPushersByLocalpartSQL); err != nil {
logrus.WithError(err).Debug("💥💥💥 Preparing selectPushersByLocalpartStmt...")
return
return return
} }
s.serverName = server s.serverName = server
@ -81,8 +82,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
for rows.Next() { for rows.Next() {
var pusher api.Pusher var pusher api.Pusher
var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, language, url, format sql.NullString var pushkey, kind, appid, appdisplayname, devicedisplayname, profiletag, lang, url, format sql.NullString
err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &language, &url, &format) err = rows.Scan(&pushkey, &kind, &appid, &appdisplayname, &devicedisplayname, &profiletag, &lang, &url, &format)
if err != nil { if err != nil {
return pushers, err return pushers, err
} }
@ -104,8 +105,8 @@ func (s *pushersStatements) selectPushersByLocalpart(
if profiletag.Valid { if profiletag.Valid {
pusher.ProfileTag = profiletag.String pusher.ProfileTag = profiletag.String
} }
if language.Valid { if lang.Valid {
pusher.Language = language.String pusher.Language = lang.String
} }
if url.Valid && format.Valid { if url.Valid && format.Valid {
pusher.Data = api.PusherData{ pusher.Data = api.PusherData{

View file

@ -45,7 +45,7 @@ func NewInternalAPI(
pusherDB, err := pushers.NewDatabase(&cfg.PusherDatabase, cfg.Matrix.ServerName) pusherDB, err := pushers.NewDatabase(&cfg.PusherDatabase, cfg.Matrix.ServerName)
if err != nil { 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{ return &internal.UserInternalAPI{