Skip to content

Commit 3f6d8ad

Browse files
authored
fix: bulk migration account linking test fixes (#256)
* fix: fixing possible transactional lockup while bulk migrating * fix: add user_id index to user roles table * fix: change user_id index to user roles table to compound index * fix: change user id index in user roles to smaller one * chore: build version number
1 parent be6c938 commit 3f6d8ad

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [8.1.2]
11+
12+
- Adds user_id index to the user roles table
13+
14+
### Migration
15+
16+
```sql
17+
CREATE INDEX IF NOT EXISTS user_roles_app_id_user_id_index ON user_roles (app_id, user_id);
18+
```
19+
1020
## [8.1.1]
1121

1222
- Adds more null and empty checks for bulk migration

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'java-library'
33
}
44

5-
version = "8.1.1"
5+
version = "8.1.2"
66

77
repositories {
88
mavenCentral()

src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
534534
update(con, UserRolesQueries.getQueryToCreateUserRolesRoleIndex(start), NO_OP_SETTER);
535535
update(con, UserRolesQueries.getQueryToCreateTenantIdIndexForUserRolesTable(start), NO_OP_SETTER);
536536
update(con, UserRolesQueries.getQueryToCreateRoleIndexForUserRolesTable(start), NO_OP_SETTER);
537+
update(con, UserRolesQueries.getQueryToCreateUserIdIndexForUserRolesTable(start), NO_OP_SETTER);
537538
}
538539

539540
if (!doesTableExists(start, con, Config.getConfig(start).getUserIdMappingTable())) {
@@ -1567,13 +1568,6 @@ public static AuthRecipeUserInfo[] listPrimaryUsersByMultipleEmailsOrPhonesOrThi
15671568
throws SQLException, StorageQueryException {
15681569
Set<String> userIds = new HashSet<>();
15691570

1570-
//I am not really sure this is really needed..
1571-
EmailPasswordQueries.lockEmail_Transaction(start, sqlCon, appIdentifier, emails);
1572-
ThirdPartyQueries.lockEmail_Transaction(start, sqlCon, appIdentifier, emails);
1573-
PasswordlessQueries.lockEmail_Transaction(start, sqlCon, appIdentifier, emails);
1574-
PasswordlessQueries.lockPhoneAndTenant_Transaction(start, sqlCon, appIdentifier, phones);
1575-
ThirdPartyQueries.lockThirdPartyInfoAndTenant_Transaction(start, sqlCon, appIdentifier, thirdpartyUserIdToThirdpartyId);
1576-
15771571
//collect ids by email
15781572
userIds.addAll(EmailPasswordQueries.getPrimaryUserIdsUsingMultipleEmails_Transaction(start, sqlCon, appIdentifier,
15791573
emails));

src/main/java/io/supertokens/storage/postgresql/queries/UserRolesQueries.java

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public static String getQueryToCreateUserRolesRoleIndex(Start start) {
116116
+ "(app_id, tenant_id, role);";
117117
}
118118

119+
public static String getQueryToCreateUserIdIndexForUserRolesTable(Start start) {
120+
return "CREATE INDEX IF NOT EXISTS user_roles_app_id_user_id_index ON " + getConfig(start).getUserRolesTable() +
121+
"(app_id, user_id);";
122+
}
123+
119124
public static boolean createNewRoleOrDoNothingIfExists_Transaction(Start start, Connection con,
120125
AppIdentifier appIdentifier, String role)
121126
throws SQLException, StorageQueryException {

0 commit comments

Comments
 (0)