mirror of
https://github.com/FromGram/server.git
synced 2026-11-17 21:11:41 +03:00
migration: drop collectible_usernames_owner_active_idx constraint allowing users to own multiple active/collectible usernames
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
DROP INDEX IF EXISTS public.collectible_usernames_owner_active_nonunique_idx;
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS collectible_usernames_owner_active_idx ON public.collectible_usernames (owner_user_id) WHERE active AND owner_user_id IS NOT NULL;
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP INDEX IF EXISTS public.collectible_usernames_owner_active_idx;
|
||||
CREATE INDEX IF NOT EXISTS collectible_usernames_owner_active_nonunique_idx ON public.collectible_usernames (owner_user_id) WHERE owner_user_id IS NOT NULL;
|
||||
@@ -119,6 +119,11 @@ func (s *CollectibleUsernameStore) Issue(ctx context.Context, cu domain.Collecti
|
||||
if found && !owner.matches(peerUsernameTypeUser, cu.OwnerUserID) {
|
||||
return domain.ErrUsernameOccupied
|
||||
}
|
||||
if cu.Active {
|
||||
if _, err := tx.Exec(ctx, `UPDATE public.collectible_usernames SET active = false, updated_at = now() WHERE owner_user_id = $1 AND username != $2 AND active`, cu.OwnerUserID, normalized); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO peer_usernames (username_lower, peer_type, peer_id)
|
||||
VALUES ($1, $2, $3)
|
||||
|
||||
Reference in New Issue
Block a user