Files
tranquil-pds/migrations/20260721_backfill_invite_code_for_account.sql
T
2026-07-25 08:27:39 +03:00

22 lines
908 B
SQL

-- The old insert path wrote for_account through without validating it
-- so an older row can contain any string at all
-- most often a handle or the literal 'admin' the column defaulted to
-- where the read path warns and drops whatever the Did newtype won't parse
-- so an unconverted row comes back with no for_account at all.
-- The first statement resolves the bare handles that still match a user
-- and the second covers every 'admin' row, since created_by_user is NOT NULL.
-- Nothing else converts
-- so a prefixed handle, a handle whose user has renamed since,
-- and anything that was never an identifier all stay as they are.
UPDATE invite_codes ic
SET for_account = u.did
FROM users u
WHERE LOWER(u.handle) = LOWER(ic.for_account)
AND ic.for_account NOT LIKE 'did:%';
UPDATE invite_codes ic
SET for_account = u.did
FROM users u
WHERE u.id = ic.created_by_user
AND ic.for_account = 'admin';