Skip to content

Commit

Permalink
feat: bulk inserting the bulk migration data
Browse files Browse the repository at this point in the history
  • Loading branch information
tamassoltesz committed Nov 15, 2024
1 parent b0b9564 commit 714e4c7
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

import java.util.List;
import java.util.Map;

public interface AuthRecipeSQLStorage extends AuthRecipeStorage, SQLStorage {

AuthRecipeUserInfo getPrimaryUserById_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
String userId)
throws StorageQueryException;

List<AuthRecipeUserInfo> getPrimaryUsersByIds_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
List<String> userIds)
throws StorageQueryException;

// lock order:
// - emailpassword table
// - thirdparty table
Expand All @@ -52,9 +59,15 @@ AuthRecipeUserInfo[] listPrimaryUsersByThirdPartyInfo_Transaction(AppIdentifier
void makePrimaryUser_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String userId)
throws StorageQueryException;

void makePrimaryUsers_Transaction(AppIdentifier appIdentifier, TransactionConnection con, List<String> userIds)
throws StorageQueryException;

void linkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String recipeUserId,
String primaryUserId) throws StorageQueryException;

void linkMultipleAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
Map<String, String> recipeUserIdByPrimaryUserId) throws StorageQueryException;

void unlinkAccounts_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String primaryUserId,
String recipeUserId)
throws StorageQueryException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.bulkimport;

import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;

public class ImportUserBase {

public String userId;
public String email;
public TenantIdentifier tenantIdentifier;
public long timeJoinedMSSinceEpoch;

public ImportUserBase(String userId, String email, TenantIdentifier tenantIdentifier, long timeJoinedMSSinceEpoch) {
this.userId = userId; //this will be the supertokens userId.
this.email = email;
this.tenantIdentifier = tenantIdentifier;
this.timeJoinedMSSinceEpoch = timeJoinedMSSinceEpoch;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.emailpassword;

import io.supertokens.pluginInterface.bulkimport.ImportUserBase;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;

public class EmailPasswordImportUser extends ImportUserBase {

public String passwordHash;

public EmailPasswordImportUser(String userId, String email, String passwordHash, TenantIdentifier tenantId, long timeJoinedInMSSinceEpoch) {
super(userId, email, tenantId, timeJoinedInMSSinceEpoch);
this.passwordHash = passwordHash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;

import java.util.List;

public interface EmailPasswordStorage extends AuthRecipeStorage {

// we pass tenantIdentifier here cause this also adds to the userId <-> tenantId mapping
Expand All @@ -35,6 +38,10 @@ AuthRecipeUserInfo signUp(TenantIdentifier tenantIdentifier, String id, String e
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException;

void signUpMultiple(List<EmailPasswordImportUser> users)
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException, StorageTransactionLogicException;

// password reset stuff is app wide cause changing the password for a user affects all the tenants
// across which it's shared.
void addPasswordResetToken(AppIdentifier appIdentifier, PasswordResetTokenInfo passwordResetTokenInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

import java.util.Map;

public interface EmailVerificationSQLStorage extends EmailVerificationStorage, SQLStorage {

EmailVerificationTokenInfo[] getAllEmailVerificationTokenInfoForUser_Transaction(TenantIdentifier tenantIdentifier,
Expand All @@ -42,6 +44,10 @@ void updateIsEmailVerified_Transaction(AppIdentifier appIdentifier, TransactionC
boolean isEmailVerified)
throws StorageQueryException, TenantOrAppNotFoundException;

void updateMultipleIsEmailVerified_Transaction(AppIdentifier appIdentifier, TransactionConnection con,
Map<String, String> emailToUserId, boolean isEmailVerified)
throws StorageQueryException, TenantOrAppNotFoundException;

void deleteEmailVerificationUserInfo_Transaction(TransactionConnection con, AppIdentifier appIdentifier,
String userId) throws StorageQueryException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.passwordless;

import io.supertokens.pluginInterface.bulkimport.ImportUserBase;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;

public class PasswordlessImportUser extends ImportUserBase {

public String phoneNumber;

public PasswordlessImportUser(String userId, String phoneNumber, String email, TenantIdentifier tenantIdentifier, long timeJoinedInMSSinceEpoch) {
super(userId, email, tenantIdentifier, timeJoinedInMSSinceEpoch);
this.phoneNumber = phoneNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.PasswordlessImportUser;
import io.supertokens.pluginInterface.passwordless.PasswordlessStorage;
import io.supertokens.pluginInterface.passwordless.exception.DuplicatePhoneNumberException;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;

public interface PasswordlessSQLStorage extends PasswordlessStorage, SQLStorage {
PasswordlessDevice getDevice_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
Expand Down Expand Up @@ -85,4 +87,7 @@ void updateUserPhoneNumber_Transaction(AppIdentifier appIdentifier, TransactionC
void deletePasswordlessUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

void importPasswordlessUsers_Transaction(TransactionConnection con, Collection<PasswordlessImportUser> users)
throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ KeyValueInfo getKeyValue_Transaction(TenantIdentifier tenantIdentifier, Transact
throws StorageQueryException;

interface TransactionLogic<T> {
T mainLogicAndCommit(TransactionConnection con) throws StorageQueryException, StorageTransactionLogicException;
T mainLogicAndCommit(TransactionConnection con)
throws StorageQueryException, StorageTransactionLogicException, TenantOrAppNotFoundException;
}

public enum TransactionIsolationLevel {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.supertokens.pluginInterface.thirdparty;

import io.supertokens.pluginInterface.bulkimport.ImportUserBase;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;

public class ThirdPartyImportUser extends ImportUserBase {

public String thirdpartyId;
public String thirdpartyUserId;

public ThirdPartyImportUser(String email, String userId, String thirdpartyId, String thirdpartyUserId,
TenantIdentifier tenantIdentifier, long timeJoinedInMSSinceEpoch) {
super(userId, email, tenantIdentifier, timeJoinedInMSSinceEpoch);
this.thirdpartyId = thirdpartyId;
this.thirdpartyUserId = thirdpartyUserId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.thirdparty.ThirdPartyImportUser;
import io.supertokens.pluginInterface.thirdparty.ThirdPartyStorage;

import java.util.Collection;

public interface ThirdPartySQLStorage extends ThirdPartyStorage, SQLStorage {

void updateUserEmail_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String thirdPartyId,
Expand All @@ -31,4 +34,7 @@ void updateUserEmail_Transaction(AppIdentifier appIdentifier, TransactionConnect
void deleteThirdPartyUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

void importThirdPartyUsers_Transaction(TransactionConnection con, Collection<ThirdPartyImportUser> usersToImport)
throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.supertokens.pluginInterface.totp.exception.UnknownTotpUserIdException;
import io.supertokens.pluginInterface.totp.exception.UsedCodeAlreadyExistsException;

import java.util.List;

public interface TOTPSQLStorage extends TOTPStorage, SQLStorage {
public int deleteDevice_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
String deviceName)
Expand Down Expand Up @@ -47,4 +49,7 @@ TOTPDevice getDeviceByName_Transaction(TransactionConnection con, AppIdentifier

TOTPDevice createDevice_Transaction(TransactionConnection con, AppIdentifier appIdentifier, TOTPDevice device)
throws StorageQueryException, DeviceAlreadyExistsException, TenantOrAppNotFoundException;

void createDevices_Transaction(TransactionConnection con, AppIdentifier appIdentifier, List<TOTPDevice> devices)
throws StorageQueryException, TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.usermetadata.UserMetadataStorage;

import java.util.List;
import java.util.Map;

public interface UserMetadataSQLStorage extends UserMetadataStorage, SQLStorage {
JsonObject getUserMetadata_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String userId)
throws StorageQueryException;

Map<String, JsonObject> getMultipleUsersMetadatas_Transaction(AppIdentifier appIdentifier, TransactionConnection
con, List<String> userIds)
throws StorageQueryException;

int setUserMetadata_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String userId,
JsonObject metadata)
throws StorageQueryException, TenantOrAppNotFoundException;

void setMultipleUsersMetadatas_Transaction(AppIdentifier appIdentifier, TransactionConnection con, Map<String, JsonObject> metadataByUserId)
throws StorageQueryException, TenantOrAppNotFoundException;

int deleteUserMetadata_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.supertokens.pluginInterface.userroles.UserRolesStorage;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

import java.util.Map;

public interface UserRolesSQLStorage extends UserRolesStorage, SQLStorage {

// delete role associated with the input userId from the input roles
Expand Down Expand Up @@ -56,4 +58,7 @@ boolean doesRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnec

void deleteAllRolesForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

void addRolesToUsers_Transaction(TransactionConnection connection, Map<TenantIdentifier, Map<String, String>> rolesToUserByTenants)
throws StorageQueryException;
}

0 comments on commit 714e4c7

Please sign in to comment.