Skip to content

Commit

Permalink
add foreign key constraint on client session table
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed May 14, 2024
1 parent c0aade2 commit 834d1e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/account/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package account

import (
"database/sql"
"errors"
"fmt"

"github.com/pagefaultgames/rogueserver/db"
Expand All @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 834d1e6

Please sign in to comment.