add foreign key constraint on client session table

pull/14/head
Up 6 months ago
parent c0aade2e65
commit 834d1e62a0
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388

@ -19,6 +19,7 @@ package account
import ( import (
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"github.com/pagefaultgames/rogueserver/db" "github.com/pagefaultgames/rogueserver/db"
@ -28,7 +29,7 @@ import (
func Logout(token []byte) error { func Logout(token []byte) error {
err := db.RemoveSessionFromToken(token) err := db.RemoveSessionFromToken(token)
if err != nil { if err != nil {
if err == sql.ErrNoRows { if errors.Is(err, sql.ErrNoRows) {
return fmt.Errorf("token not found") return fmt.Errorf("token not found")
} }

@ -175,7 +175,7 @@ func setupDb(tx *sql.Tx) error {
// MIGRATION 001 // MIGRATION 001
`ALTER TABLE sessions DROP COLUMN IF EXISTS active`, `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 { for _, q := range queries {

Loading…
Cancel
Save