Skip to content

Commit 0e11491

Browse files
committed
fix: add user_id index to user roles table
1 parent c9c168d commit 0e11491

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1010
## [8.1.1]
1111

1212
- Adds more null and empty checks for bulk migration
13+
- Adds user_id index to the user roles table
1314

15+
### Migration
16+
17+
```sql
18+
CREATE INDEX IF NOT EXISTS user_roles_user_id_index ON user_roles (user_id);
19+
```
1420
## [8.1.0]
1521

1622
- Adds support for webauthn (passkeys)

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

Lines changed: 1 addition & 0 deletions
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())) {

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

Lines changed: 5 additions & 0 deletions
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_user_id_index ON " + getConfig(start).getUserRolesTable() +
121+
"(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)