From 4e0c1924a6f441de1d9f361d934bb5a8e836c7a1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 24 May 2017 16:47:23 +0100 Subject: [PATCH] Self-review --- .../auth/storage/devices/devices_table.go | 20 +++++++++---------- .../clientapi/auth/storage/devices/storage.go | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/devices_table.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/devices_table.go index 0aeb3cf81..f68576e0a 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/devices_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/devices_table.go @@ -26,15 +26,15 @@ import ( const devicesSchema = ` -- Stores data about devices. CREATE TABLE IF NOT EXISTS devices ( - -- The access token granted to this device. This has to be the primary key - -- so we can distinguish which device is making a given request. - access_token TEXT NOT NULL PRIMARY KEY, - -- The device identifier. This only needs to uniquely identify a device for a given user, not globally. - -- access_tokens will be clobbered based on the device ID for a user. - id TEXT NOT NULL, - -- The Matrix user ID localpart for this device. This is preferable to storing the full user_id - -- as it is smaller, makes it clearer that we only manage devices for our own users, and may make - -- migration to different domain names easier. + -- The access token granted to this device. This has to be the primary key + -- so we can distinguish which device is making a given request. + access_token TEXT NOT NULL PRIMARY KEY, + -- The device identifier. This only needs to uniquely identify a device for a given user, not globally. + -- access_tokens will be clobbered based on the device ID for a user. + id TEXT NOT NULL, + -- The Matrix user ID localpart for this device. This is preferable to storing the full user_id + -- as it is smaller, makes it clearer that we only manage devices for our own users, and may make + -- migration to different domain names easier. localpart TEXT NOT NULL, -- When this devices was first recognised on the network, as a unix timestamp (ms resolution). created_ts BIGINT NOT NULL @@ -54,7 +54,7 @@ const selectDeviceByTokenSQL = "" + const deleteDeviceSQL = "" + "DELETE FROM devices WHERE id = $1 AND localpart = $2" -// TODO: List devices, delete device API +// TODO: List devices? type devicesStatements struct { insertDeviceStmt *sql.Stmt diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go index cdb1f60c7..49c4a90c0 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/devices/storage.go @@ -75,6 +75,7 @@ func (d *Database) CreateDevice(localpart, deviceID string) (dev *authtypes.Devi return } +// TODO: factor out to common func runTransaction(db *sql.DB, fn func(txn *sql.Tx) error) (err error) { txn, err := db.Begin() if err != nil {