From a1d1f2b02cf0d44c110d814f24b226e9e394b6c1 Mon Sep 17 00:00:00 2001 From: Dan Peleg Date: Sat, 24 Apr 2021 16:12:06 +0300 Subject: [PATCH] =?UTF-8?q?Error:=20"=F0=9F=92=A5=20Preparing=20selectPush?= =?UTF-8?q?ersByLocalpartStmt..."=20func=3D"prepare"=20file=3D"=20[/src/us?= =?UTF-8?q?erapi/storage/pushers/sqlite3/pushers=5Ftable.go:69]"=20error?= =?UTF-8?q?=3D"no=20such=20column:=20pushkey"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/docker/postgres/create_db.sh | 2 +- cmd/dendrite-demo-libp2p/main.go | 1 + cmd/goose/main.go | 3 +- docs/INSTALL.md | 2 +- .../storage/pushers/postgres/pushers_table.go | 20 ++++++---- .../storage/pushers/sqlite3/pushers_table.go | 37 ++++++++++--------- userapi/userapi.go | 2 +- 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/build/docker/postgres/create_db.sh b/build/docker/postgres/create_db.sh index eb77bb26..17b2cfcc 100755 --- a/build/docker/postgres/create_db.sh +++ b/build/docker/postgres/create_db.sh @@ -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 diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index 0610ec77..16afea69 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -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)) diff --git a/cmd/goose/main.go b/cmd/goose/main.go index 83c97a72..7c3ecdae 100644 --- a/cmd/goose/main.go +++ b/cmd/goose/main.go @@ -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, } ) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index 1099bc83..9f96d4be 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -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 ``` diff --git a/userapi/storage/pushers/postgres/pushers_table.go b/userapi/storage/pushers/postgres/pushers_table.go index 8d5d01e1..d0843fbb 100644 --- a/userapi/storage/pushers/postgres/pushers_table.go +++ b/userapi/storage/pushers/postgres/pushers_table.go @@ -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{ diff --git a/userapi/storage/pushers/sqlite3/pushers_table.go b/userapi/storage/pushers/sqlite3/pushers_table.go index b4b19d58..8eda4c5a 100644 --- a/userapi/storage/pushers/sqlite3/pushers_table.go +++ b/userapi/storage/pushers/sqlite3/pushers_table.go @@ -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{ diff --git a/userapi/userapi.go b/userapi/userapi.go index 47574208..ebe4449b 100644 --- a/userapi/userapi.go +++ b/userapi/userapi.go @@ -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{