Skip to content

Commit 7c680dd

Browse files
committed
fixup! Data model and repository for user registration tokens
1 parent 9726f35 commit 7c680dd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

crates/storage-pg/migrations/20250602212100_user_registration_tokens.sql

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,29 @@ CREATE TABLE "user_registration_tokens" (
2929
"revoked_at" TIMESTAMP WITH TIME ZONE
3030
);
3131

32+
-- Create a few indices on the table, as we use those for filtering
33+
-- They are safe to create non-concurrently, as the table is empty at this point
34+
CREATE INDEX "user_registration_tokens_usage_limit_idx"
35+
ON "user_registration_tokens" ("usage_limit");
36+
37+
CREATE INDEX "user_registration_tokens_times_used_idx"
38+
ON "user_registration_tokens" ("times_used");
39+
40+
CREATE INDEX "user_registration_tokens_created_at_idx"
41+
ON "user_registration_tokens" ("created_at");
42+
43+
CREATE INDEX "user_registration_tokens_last_used_at_idx"
44+
ON "user_registration_tokens" ("last_used_at");
45+
46+
CREATE INDEX "user_registration_tokens_expires_at_idx"
47+
ON "user_registration_tokens" ("expires_at");
48+
49+
CREATE INDEX "user_registration_tokens_revoked_at_idx"
50+
ON "user_registration_tokens" ("revoked_at");
51+
3252
-- Add foreign key reference to registration tokens in user registrations
53+
-- A second migration will add the index for this foreign key
3354
ALTER TABLE "user_registrations"
3455
ADD COLUMN "user_registration_token_id" UUID
3556
REFERENCES "user_registration_tokens" ("user_registration_token_id")
36-
ON DELETE SET NULL;
57+
ON DELETE SET NULL;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- no-transaction
2+
-- Copyright 2025 New Vector Ltd.
3+
--
4+
-- SPDX-License-Identifier: AGPL-3.0-only
5+
-- Please see LICENSE in the repository root for full details.
6+
7+
CREATE INDEX CONCURRENTLY
8+
user_registrations_user_registration_token_id_fk
9+
ON user_registrations (user_registration_token_id);

0 commit comments

Comments
 (0)