Skip to content

Commit 46ed6db

Browse files
authored
fix new user signup (tldraw#7093)
ayyy I forgot to add the groups_backend flag for new users in tldraw#7058 which means that people who have been signing up since then have still been using the old data model. it's no biggie, just requires slight adjustment to the migration script. ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [x] `other` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Ensure new users get `groups_backend` flag and update the migration to use `ON CONFLICT DO NOTHING` for safe re-runs. > > - **Backend** > - Set `user.flags` to `groups_backend` on user creation in `apps/dotcom/sync-worker/src/TLUserDurableObject.ts`. > - **Database Migration** (`apps/dotcom/zero-cache/migrations/023_groups.sql`) > - Add `ON CONFLICT DO NOTHING` to inserts into `group`, `group_user`, and `group_file` in `migrate_user_to_groups` to make it idempotent. > - Standardize flag to `groups_backend` in migration flag updates and comments. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit cdf92fd. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 882ff73 commit 46ed6db

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

apps/dotcom/sync-worker/src/TLUserDurableObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class TLUserDurableObject extends DurableObject<Environment> {
111111
exportPadding: true,
112112
createdAt: now,
113113
updatedAt: now,
114-
flags: '',
114+
flags: 'groups_backend',
115115
})
116116
.execute()
117117
await tx

apps/dotcom/zero-cache/migrations/023_groups.sql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,13 @@ BEGIN
404404

405405
-- Create a home group for the user
406406
INSERT INTO public."group" ("id", "name", "createdAt", "updatedAt", "isDeleted", "inviteSecret")
407-
VALUES (target_user_id, target_user_id, v_now, v_now, FALSE, invite_secret);
407+
VALUES (target_user_id, target_user_id, v_now, v_now, FALSE, invite_secret)
408+
ON CONFLICT DO NOTHING;
408409

409410
-- Make the user a member of the home group
410411
INSERT INTO public."group_user" ("userId", "groupId", "createdAt", "updatedAt", "role", "index", "userName", "userColor")
411-
VALUES (target_user_id, target_user_id, v_now, v_now, 'owner', 'a1', '', '');
412+
VALUES (target_user_id, target_user_id, v_now, v_now, 'owner', 'a1', '', '')
413+
ON CONFLICT DO NOTHING;
412414

413415
-- For any files owned by the user, change the owningGroupId to the home group and set the ownerId to null
414416
UPDATE public."file"
@@ -420,7 +422,8 @@ BEGIN
420422
INSERT INTO public."group_file" ("fileId", "groupId", "createdAt", "updatedAt")
421423
SELECT fs."fileId", target_user_id, COALESCE(fs."firstVisitAt", f."createdAt", v_now), COALESCE(fs."lastEditAt", fs."firstVisitAt", f."updatedAt", f."createdAt", v_now)
422424
FROM public."file_state" fs JOIN public."file" f ON fs."fileId" = f."id"
423-
WHERE fs."userId" = target_user_id;
425+
WHERE fs."userId" = target_user_id
426+
ON CONFLICT DO NOTHING;
424427

425428
-- Update indexes for the group_file entries
426429
UPDATE public."group_file" gf
@@ -433,7 +436,7 @@ BEGIN
433436
) AS fs
434437
WHERE gf."fileId" = fs."fileId" AND gf."groupId" = target_user_id;
435438

436-
-- Add 'groups' flag to user
439+
-- Add 'groups_backend' flag to user
437440
IF v_current_flags IS NULL OR v_current_flags = '' THEN
438441
UPDATE public."user" SET flags = 'groups_backend' WHERE id = target_user_id;
439442
ELSE

0 commit comments

Comments
 (0)