From 834d1e62a003ff8382a304438a7396977605ae37 Mon Sep 17 00:00:00 2001 From: Up Date: Tue, 14 May 2024 14:33:53 +0200 Subject: [PATCH] add foreign key constraint on client session table --- api/account/logout.go | 3 ++- db/db.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/account/logout.go b/api/account/logout.go index 7bfdb94..774d884 100644 --- a/api/account/logout.go +++ b/api/account/logout.go @@ -19,6 +19,7 @@ package account import ( "database/sql" + "errors" "fmt" "github.com/pagefaultgames/rogueserver/db" @@ -28,7 +29,7 @@ import ( func Logout(token []byte) error { err := db.RemoveSessionFromToken(token) if err != nil { - if err == sql.ErrNoRows { + if errors.Is(err, sql.ErrNoRows) { return fmt.Errorf("token not found") } diff --git a/db/db.go b/db/db.go index 7aa881c..4ee1a71 100644 --- a/db/db.go +++ b/db/db.go @@ -175,7 +175,7 @@ func setupDb(tx *sql.Tx) error { // MIGRATION 001 `ALTER TABLE sessions DROP COLUMN IF EXISTS active`, - `CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL)`, + `CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`, } for _, q := range queries {