Skip to content

Commit de989b4

Browse files
authored
Add login.avatar_id FK for selected avatar (#331)
Adds a nullable foreign key on the login table referencing avatars_list, making "currently selected avatar" a single authoritative value per user. The legacy avatars.selected flag is kept (and still writable) for backwards compatibility; the API mirrors both sides on writes and provides a reconciler to repair drift.
1 parent 3020887 commit de989b4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Add a single "currently selected avatar" reference on the login table.
2+
-- The legacy `avatars.selected` flag is kept (and still user-writable) for
3+
-- backwards compatibility; the API mirrors both sides on writes and exposes a
4+
-- reconciler to repair any drift.
5+
6+
ALTER TABLE login
7+
ADD COLUMN avatar_id int(11) unsigned DEFAULT NULL,
8+
ADD CONSTRAINT fk_login_avatar
9+
FOREIGN KEY (avatar_id) REFERENCES avatars_list (id)
10+
ON DELETE SET NULL ON UPDATE CASCADE;
11+
12+
-- Backfill from the legacy selected flag.
13+
UPDATE login l
14+
JOIN avatars a ON a.idUser = l.id AND a.selected = 1
15+
SET l.avatar_id = a.idAvatar;

0 commit comments

Comments
 (0)