Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions migrations/V143__login_avatar_fk.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Add a single "currently selected avatar" reference on the login table.
-- The legacy `avatars.selected` flag is kept (and still user-writable) for
-- backwards compatibility; the API mirrors both sides on writes and exposes a
-- reconciler to repair any drift.

ALTER TABLE login
ADD COLUMN avatar_id int(11) unsigned DEFAULT NULL,
ADD CONSTRAINT fk_login_avatar
FOREIGN KEY (avatar_id) REFERENCES avatars_list (id)
ON DELETE SET NULL ON UPDATE CASCADE;

-- Backfill from the legacy selected flag.
UPDATE login l
JOIN avatars a ON a.idUser = l.id AND a.selected = 1
SET l.avatar_id = a.idAvatar;
Comment thread
Brutus5000 marked this conversation as resolved.