mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
6
server/migrations/sql/0006_backfill_user_binary.sql
Normal file
6
server/migrations/sql/0006_backfill_user_binary.sql
Normal 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;
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user