fix: create user_binary row on character creation (#176)

New characters were missing their user_binary record, preventing them
from entering their house. Both sign server and API character creation
paths now insert the row. A backfill migration fixes existing databases.
This commit is contained in:
Houmgaor
2026-03-16 17:11:55 +01:00
parent 1ae7dffe7b
commit 5009a37d19
3 changed files with 19 additions and 3 deletions

View File

@@ -42,6 +42,10 @@ func (r *APICharacterRepository) Create(ctx context.Context, userID uint32, last
RETURNING id, name, is_female, weapon_type, hr, gr, last_login`,
userID, lastLogin,
)
if err != nil {
return character, err
}
_, err = r.db.ExecContext(ctx, `INSERT INTO user_binary (id) VALUES ($1)`, character.ID)
return character, err
}

View File

@@ -0,0 +1,6 @@
-- Backfill user_binary rows for characters that were created without one.
-- This fixes #176: new characters could not enter their house.
INSERT INTO user_binary (id)
SELECT c.id FROM characters c
LEFT JOIN user_binary ub ON ub.id = c.id
WHERE ub.id IS NULL;

View File

@@ -24,13 +24,19 @@ func (r *SignCharacterRepository) CountNewCharacters(uid uint32) (int, error) {
}
func (r *SignCharacterRepository) CreateCharacter(uid uint32, lastLogin uint32) error {
_, err := r.db.Exec(`
var charID int
err := r.db.QueryRow(`
INSERT INTO characters (
user_id, is_female, is_new_character, name, unk_desc_string,
hr, gr, weapon_type, last_login)
VALUES($1, False, True, '', '', 0, 0, 0, $2)`,
VALUES($1, False, True, '', '', 0, 0, 0, $2)
RETURNING id`,
uid, lastLogin,
)
).Scan(&charID)
if err != nil {
return err
}
_, err = r.db.Exec(`INSERT INTO user_binary (id) VALUES ($1)`, charID)
return err
}