Skip to content

Commit c511746

Browse files
committed
feat(identities): backfill user_identities from better-auth account rows
1 parent 855bcc5 commit c511746

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Opportunistic backfill: users who signed in with GitHub via better-auth
2+
-- get their user_identities row seeded automatically.
3+
4+
INSERT INTO user_identities
5+
(user_id, provider, external_id, external_handle, linked_at, last_verified_at)
6+
SELECT
7+
a.user_id,
8+
'github'::identity_provider,
9+
a.account_id,
10+
COALESCE(u.name, a.account_id),
11+
NOW(),
12+
NOW()
13+
FROM account a
14+
JOIN "user" u ON u.id = a.user_id
15+
WHERE a.provider_id = 'github'
16+
ON CONFLICT (provider, external_id) DO NOTHING;

apps/dashboard/server/db/migrations/meta/_journal.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
"when": 1776968447311,
6565
"tag": "0008_solid_marauders",
6666
"breakpoints": true
67+
},
68+
{
69+
"idx": 9,
70+
"version": "7",
71+
"when": 1776970200000,
72+
"tag": "0009_backfill_user_identities_from_account",
73+
"breakpoints": true
6774
}
6875
]
6976
}

0 commit comments

Comments
 (0)