Skip to content

Commit c219c9e

Browse files
committed
fix: db schema for postgres and mysql
1 parent b9b116c commit c219c9e

File tree

24 files changed

+672
-72
lines changed

24 files changed

+672
-72
lines changed

v2/community/database-setup/mysql.mdx

+28-4
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,46 @@ CREATE TABLE `app_id_to_user_id` (
175175
`app_id` varchar(64) NOT NULL DEFAULT 'public',
176176
`user_id` char(36) NOT NULL,
177177
`recipe_id` varchar(128) NOT NULL,
178+
`primary_or_recipe_user_id` char(36) NOT NULL,
179+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
178180
PRIMARY KEY (`app_id`,`user_id`),
179-
CONSTRAINT `app_id_to_user_id_ibfk_1` FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE
181+
FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE,
182+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
180183
);
181184

182185
CREATE TABLE `all_auth_recipe_users` (
183186
`app_id` varchar(64) NOT NULL DEFAULT 'public',
184187
`tenant_id` varchar(64) NOT NULL DEFAULT 'public',
185188
`user_id` char(36) NOT NULL,
189+
`primary_or_recipe_user_id` char(36) NOT NULL,
190+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
186191
`recipe_id` varchar(128) NOT NULL,
187192
`time_joined` bigint unsigned NOT NULL,
193+
`primary_or_recipe_user_time_joined` bigint unsigned NOT NULL,
188194
PRIMARY KEY (`app_id`,`tenant_id`,`user_id`),
189195
KEY `app_id` (`app_id`,`user_id`),
190196
FOREIGN KEY (`app_id`, `tenant_id`) REFERENCES `tenants` (`app_id`, `tenant_id`) ON DELETE CASCADE,
191-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
197+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE,
198+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
192199
);
193200

194-
CREATE INDEX `all_auth_recipe_users_pagination_index` ON `all_auth_recipe_users` (`time_joined` DESC,`user_id` DESC,`tenant_id` DESC,`app_id` DESC);
201+
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users
202+
(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
203+
204+
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users
205+
(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
206+
207+
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users
208+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
209+
210+
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users
211+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
212+
213+
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users
214+
(primary_or_recipe_user_id, app_id);
215+
216+
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users
217+
(app_id, recipe_id, tenant_id);
195218

196219
CREATE TABLE `userid_mapping` (
197220
`app_id` varchar(64) NOT NULL DEFAULT 'public',
@@ -286,9 +309,10 @@ CREATE TABLE `emailpassword_pswd_reset_tokens` (
286309
`user_id` char(36) NOT NULL,
287310
`token` varchar(128) NOT NULL,
288311
`token_expiry` bigint unsigned NOT NULL,
312+
`email` varchar(256),
289313
PRIMARY KEY (`app_id`,`user_id`,`token`),
290314
UNIQUE KEY `token` (`token`),
291-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `emailpassword_users` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
315+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
292316
);
293317

294318
CREATE INDEX `emailpassword_password_reset_token_expiry_index` ON `emailpassword_pswd_reset_tokens` (`token_expiry`);

v2/community/database-setup/postgresql.mdx

+28-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ CREATE TABLE app_id_to_user_id (
188188
app_id VARCHAR(64) DEFAULT 'public' NOT NULL,
189189
user_id character(36) NOT NULL,
190190
recipe_id VARCHAR(128) NOT NULL,
191+
primary_or_recipe_user_id CHAR(36) NOT NULL,
192+
is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE,
191193
CONSTRAINT app_id_to_user_id_pkey PRIMARY KEY (app_id, user_id),
194+
CONSTRAINT app_id_to_user_id_primary_or_recipe_user_id_fkey FOREIGN KEY(app_id, primary_or_recipe_user_id) REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE,
192195
CONSTRAINT app_id_to_user_id_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(app_id) ON DELETE CASCADE
193196
);
194197
@@ -198,14 +201,36 @@ CREATE TABLE all_auth_recipe_users (
198201
app_id VARCHAR(64) DEFAULT 'public' NOT NULL,
199202
tenant_id VARCHAR(64) DEFAULT 'public' NOT NULL,
200203
user_id character(36) NOT NULL,
204+
primary_or_recipe_user_id CHAR(36) NOT NULL,
205+
is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE,
201206
recipe_id VARCHAR(128) NOT NULL,
202207
time_joined BIGINT NOT NULL,
208+
primary_or_recipe_user_time_joined BIGINT NOT NULL,
203209
CONSTRAINT all_auth_recipe_users_pkey PRIMARY KEY (app_id, tenant_id, user_id),
204210
CONSTRAINT all_auth_recipe_users_tenant_id_fkey FOREIGN KEY (app_id, tenant_id) REFERENCES public.tenants(app_id, tenant_id) ON DELETE CASCADE,
211+
CONSTRAINT all_auth_recipe_users_primary_or_recipe_user_id_fkey FOREIGN KEY(app_id, primary_or_recipe_user_id) REFERENCES public.app_id_to_user_id (app_id, user_id) ON DELETE CASCADE,
205212
CONSTRAINT all_auth_recipe_users_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.app_id_to_user_id(app_id, user_id) ON DELETE CASCADE
206213
);
207214
208-
CREATE INDEX all_auth_recipe_users_pagination_index ON all_auth_recipe_users (time_joined DESC, user_id DESC, tenant_id DESC, app_id DESC);
215+
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users
216+
(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
217+
218+
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users
219+
(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
220+
221+
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users
222+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
223+
224+
225+
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users
226+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
227+
228+
229+
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users
230+
(primary_or_recipe_user_id, app_id);
231+
232+
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users
233+
(app_id, recipe_id, tenant_id);
209234
210235
CREATE INDEX all_auth_recipe_user_id_index ON all_auth_recipe_users (app_id, user_id);
211236
@@ -315,9 +340,10 @@ CREATE TABLE emailpassword_pswd_reset_tokens (
315340
user_id character(36) NOT NULL,
316341
token VARCHAR(128) NOT NULL,
317342
token_expiry BIGINT NOT NULL,
343+
email VARCHAR(256),
318344
CONSTRAINT emailpassword_pswd_reset_tokens_pkey PRIMARY KEY (app_id, user_id, token),
319345
CONSTRAINT emailpassword_pswd_reset_tokens_token_key UNIQUE (token),
320-
CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.emailpassword_users(app_id, user_id) ON UPDATE CASCADE ON DELETE CASCADE
346+
CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.app_id_to_user_id(app_id, user_id) ON UPDATE CASCADE ON DELETE CASCADE
321347
);
322348
323349
CREATE INDEX emailpassword_password_reset_token_expiry_index ON emailpassword_pswd_reset_tokens (token_expiry);

v2/emailpassword/custom-ui/init/database-setup/mysql.mdx

+28-4
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,46 @@ CREATE TABLE `app_id_to_user_id` (
175175
`app_id` varchar(64) NOT NULL DEFAULT 'public',
176176
`user_id` char(36) NOT NULL,
177177
`recipe_id` varchar(128) NOT NULL,
178+
`primary_or_recipe_user_id` char(36) NOT NULL,
179+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
178180
PRIMARY KEY (`app_id`,`user_id`),
179-
CONSTRAINT `app_id_to_user_id_ibfk_1` FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE
181+
FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE,
182+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
180183
);
181184

182185
CREATE TABLE `all_auth_recipe_users` (
183186
`app_id` varchar(64) NOT NULL DEFAULT 'public',
184187
`tenant_id` varchar(64) NOT NULL DEFAULT 'public',
185188
`user_id` char(36) NOT NULL,
189+
`primary_or_recipe_user_id` char(36) NOT NULL,
190+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
186191
`recipe_id` varchar(128) NOT NULL,
187192
`time_joined` bigint unsigned NOT NULL,
193+
`primary_or_recipe_user_time_joined` bigint unsigned NOT NULL,
188194
PRIMARY KEY (`app_id`,`tenant_id`,`user_id`),
189195
KEY `app_id` (`app_id`,`user_id`),
190196
FOREIGN KEY (`app_id`, `tenant_id`) REFERENCES `tenants` (`app_id`, `tenant_id`) ON DELETE CASCADE,
191-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
197+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE,
198+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
192199
);
193200

194-
CREATE INDEX `all_auth_recipe_users_pagination_index` ON `all_auth_recipe_users` (`time_joined` DESC,`user_id` DESC,`tenant_id` DESC,`app_id` DESC);
201+
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users
202+
(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
203+
204+
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users
205+
(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
206+
207+
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users
208+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
209+
210+
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users
211+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
212+
213+
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users
214+
(primary_or_recipe_user_id, app_id);
215+
216+
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users
217+
(app_id, recipe_id, tenant_id);
195218

196219
CREATE TABLE `userid_mapping` (
197220
`app_id` varchar(64) NOT NULL DEFAULT 'public',
@@ -286,9 +309,10 @@ CREATE TABLE `emailpassword_pswd_reset_tokens` (
286309
`user_id` char(36) NOT NULL,
287310
`token` varchar(128) NOT NULL,
288311
`token_expiry` bigint unsigned NOT NULL,
312+
`email` varchar(256),
289313
PRIMARY KEY (`app_id`,`user_id`,`token`),
290314
UNIQUE KEY `token` (`token`),
291-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `emailpassword_users` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
315+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
292316
);
293317

294318
CREATE INDEX `emailpassword_password_reset_token_expiry_index` ON `emailpassword_pswd_reset_tokens` (`token_expiry`);

v2/emailpassword/custom-ui/init/database-setup/postgresql.mdx

+28-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ CREATE TABLE app_id_to_user_id (
188188
app_id VARCHAR(64) DEFAULT 'public' NOT NULL,
189189
user_id character(36) NOT NULL,
190190
recipe_id VARCHAR(128) NOT NULL,
191+
primary_or_recipe_user_id CHAR(36) NOT NULL,
192+
is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE,
191193
CONSTRAINT app_id_to_user_id_pkey PRIMARY KEY (app_id, user_id),
194+
CONSTRAINT app_id_to_user_id_primary_or_recipe_user_id_fkey FOREIGN KEY(app_id, primary_or_recipe_user_id) REFERENCES app_id_to_user_id (app_id, user_id) ON DELETE CASCADE,
192195
CONSTRAINT app_id_to_user_id_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(app_id) ON DELETE CASCADE
193196
);
194197
@@ -198,14 +201,36 @@ CREATE TABLE all_auth_recipe_users (
198201
app_id VARCHAR(64) DEFAULT 'public' NOT NULL,
199202
tenant_id VARCHAR(64) DEFAULT 'public' NOT NULL,
200203
user_id character(36) NOT NULL,
204+
primary_or_recipe_user_id CHAR(36) NOT NULL,
205+
is_linked_or_is_a_primary_user BOOLEAN NOT NULL DEFAULT FALSE,
201206
recipe_id VARCHAR(128) NOT NULL,
202207
time_joined BIGINT NOT NULL,
208+
primary_or_recipe_user_time_joined BIGINT NOT NULL,
203209
CONSTRAINT all_auth_recipe_users_pkey PRIMARY KEY (app_id, tenant_id, user_id),
204210
CONSTRAINT all_auth_recipe_users_tenant_id_fkey FOREIGN KEY (app_id, tenant_id) REFERENCES public.tenants(app_id, tenant_id) ON DELETE CASCADE,
211+
CONSTRAINT all_auth_recipe_users_primary_or_recipe_user_id_fkey FOREIGN KEY(app_id, primary_or_recipe_user_id) REFERENCES public.app_id_to_user_id (app_id, user_id) ON DELETE CASCADE,
205212
CONSTRAINT all_auth_recipe_users_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.app_id_to_user_id(app_id, user_id) ON DELETE CASCADE
206213
);
207214
208-
CREATE INDEX all_auth_recipe_users_pagination_index ON all_auth_recipe_users (time_joined DESC, user_id DESC, tenant_id DESC, app_id DESC);
215+
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users
216+
(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
217+
218+
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users
219+
(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
220+
221+
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users
222+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
223+
224+
225+
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users
226+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
227+
228+
229+
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users
230+
(primary_or_recipe_user_id, app_id);
231+
232+
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users
233+
(app_id, recipe_id, tenant_id);
209234
210235
CREATE INDEX all_auth_recipe_user_id_index ON all_auth_recipe_users (app_id, user_id);
211236
@@ -315,9 +340,10 @@ CREATE TABLE emailpassword_pswd_reset_tokens (
315340
user_id character(36) NOT NULL,
316341
token VARCHAR(128) NOT NULL,
317342
token_expiry BIGINT NOT NULL,
343+
email VARCHAR(256),
318344
CONSTRAINT emailpassword_pswd_reset_tokens_pkey PRIMARY KEY (app_id, user_id, token),
319345
CONSTRAINT emailpassword_pswd_reset_tokens_token_key UNIQUE (token),
320-
CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.emailpassword_users(app_id, user_id) ON UPDATE CASCADE ON DELETE CASCADE
346+
CONSTRAINT emailpassword_pswd_reset_tokens_user_id_fkey FOREIGN KEY (app_id, user_id) REFERENCES public.app_id_to_user_id(app_id, user_id) ON UPDATE CASCADE ON DELETE CASCADE
321347
);
322348
323349
CREATE INDEX emailpassword_password_reset_token_expiry_index ON emailpassword_pswd_reset_tokens (token_expiry);

v2/emailpassword/pre-built-ui/setup/database-setup/mysql.mdx

+28-4
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,46 @@ CREATE TABLE `app_id_to_user_id` (
175175
`app_id` varchar(64) NOT NULL DEFAULT 'public',
176176
`user_id` char(36) NOT NULL,
177177
`recipe_id` varchar(128) NOT NULL,
178+
`primary_or_recipe_user_id` char(36) NOT NULL,
179+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
178180
PRIMARY KEY (`app_id`,`user_id`),
179-
CONSTRAINT `app_id_to_user_id_ibfk_1` FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE
181+
FOREIGN KEY (`app_id`) REFERENCES `apps` (`app_id`) ON DELETE CASCADE,
182+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
180183
);
181184

182185
CREATE TABLE `all_auth_recipe_users` (
183186
`app_id` varchar(64) NOT NULL DEFAULT 'public',
184187
`tenant_id` varchar(64) NOT NULL DEFAULT 'public',
185188
`user_id` char(36) NOT NULL,
189+
`primary_or_recipe_user_id` char(36) NOT NULL,
190+
`is_linked_or_is_a_primary_user` BOOLEAN NOT NULL DEFAULT FALSE,
186191
`recipe_id` varchar(128) NOT NULL,
187192
`time_joined` bigint unsigned NOT NULL,
193+
`primary_or_recipe_user_time_joined` bigint unsigned NOT NULL,
188194
PRIMARY KEY (`app_id`,`tenant_id`,`user_id`),
189195
KEY `app_id` (`app_id`,`user_id`),
190196
FOREIGN KEY (`app_id`, `tenant_id`) REFERENCES `tenants` (`app_id`, `tenant_id`) ON DELETE CASCADE,
191-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
197+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE,
198+
FOREIGN KEY (`app_id`, `primary_or_recipe_user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE
192199
);
193200

194-
CREATE INDEX `all_auth_recipe_users_pagination_index` ON `all_auth_recipe_users` (`time_joined` DESC,`user_id` DESC,`tenant_id` DESC,`app_id` DESC);
201+
CREATE INDEX all_auth_recipe_users_pagination_index1 ON all_auth_recipe_users
202+
(app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
203+
204+
CREATE INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users
205+
(app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
206+
207+
CREATE INDEX all_auth_recipe_users_pagination_index3 ON all_auth_recipe_users
208+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined DESC, primary_or_recipe_user_id DESC);
209+
210+
CREATE INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users
211+
(recipe_id, app_id, tenant_id, primary_or_recipe_user_time_joined ASC, primary_or_recipe_user_id DESC);
212+
213+
CREATE INDEX all_auth_recipe_users_primary_user_id_index ON all_auth_recipe_users
214+
(primary_or_recipe_user_id, app_id);
215+
216+
CREATE INDEX all_auth_recipe_users_recipe_id_index ON all_auth_recipe_users
217+
(app_id, recipe_id, tenant_id);
195218

196219
CREATE TABLE `userid_mapping` (
197220
`app_id` varchar(64) NOT NULL DEFAULT 'public',
@@ -286,9 +309,10 @@ CREATE TABLE `emailpassword_pswd_reset_tokens` (
286309
`user_id` char(36) NOT NULL,
287310
`token` varchar(128) NOT NULL,
288311
`token_expiry` bigint unsigned NOT NULL,
312+
`email` varchar(256),
289313
PRIMARY KEY (`app_id`,`user_id`,`token`),
290314
UNIQUE KEY `token` (`token`),
291-
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `emailpassword_users` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
315+
FOREIGN KEY (`app_id`, `user_id`) REFERENCES `app_id_to_user_id` (`app_id`, `user_id`) ON DELETE CASCADE ON UPDATE CASCADE
292316
);
293317

294318
CREATE INDEX `emailpassword_password_reset_token_expiry_index` ON `emailpassword_pswd_reset_tokens` (`token_expiry`);

0 commit comments

Comments
 (0)