Self-review

This commit is contained in:
Kegan Dougal 2017-05-24 16:47:23 +01:00
parent b29725ab13
commit 4e0c1924a6
2 changed files with 11 additions and 10 deletions

View file

@ -26,15 +26,15 @@ import (
const devicesSchema = ` const devicesSchema = `
-- Stores data about devices. -- Stores data about devices.
CREATE TABLE IF NOT EXISTS devices ( CREATE TABLE IF NOT EXISTS devices (
-- The access token granted to this device. This has to be the primary key -- 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. -- so we can distinguish which device is making a given request.
access_token TEXT NOT NULL PRIMARY KEY, access_token TEXT NOT NULL PRIMARY KEY,
-- The device identifier. This only needs to uniquely identify a device for a given user, not globally. -- 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. -- access_tokens will be clobbered based on the device ID for a user.
id TEXT NOT NULL, id TEXT NOT NULL,
-- The Matrix user ID localpart for this device. This is preferable to storing the full user_id -- 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 -- 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. -- migration to different domain names easier.
localpart TEXT NOT NULL, localpart TEXT NOT NULL,
-- When this devices was first recognised on the network, as a unix timestamp (ms resolution). -- When this devices was first recognised on the network, as a unix timestamp (ms resolution).
created_ts BIGINT NOT NULL created_ts BIGINT NOT NULL
@ -54,7 +54,7 @@ const selectDeviceByTokenSQL = "" +
const deleteDeviceSQL = "" + const deleteDeviceSQL = "" +
"DELETE FROM devices WHERE id = $1 AND localpart = $2" "DELETE FROM devices WHERE id = $1 AND localpart = $2"
// TODO: List devices, delete device API // TODO: List devices?
type devicesStatements struct { type devicesStatements struct {
insertDeviceStmt *sql.Stmt insertDeviceStmt *sql.Stmt

View file

@ -75,6 +75,7 @@ func (d *Database) CreateDevice(localpart, deviceID string) (dev *authtypes.Devi
return return
} }
// TODO: factor out to common
func runTransaction(db *sql.DB, fn func(txn *sql.Tx) error) (err error) { func runTransaction(db *sql.DB, fn func(txn *sql.Tx) error) (err error) {
txn, err := db.Begin() txn, err := db.Begin()
if err != nil { if err != nil {