	--VendorSettingsTypes
	DECLARE @VendorSettingsTypes TABLE (RowId uniqueidentifier NOT NULL,[Name] [nvarchar](500) NOT NULL,SettingsType int NOT NULL);

    INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('56B0FED3-404D-4384-909F-68498CFBE937', N'MFALoginBlockAfterFailedRetriesGetCodeInMinutes',3);
    INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('0C2D2B62-E797-4C51-AE88-2FD6A8E0BB09', N'MFALoginBlockAfterFailedRetriesVerifyCodeInMinutes',3);


    INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('D91A9480-3DD3-4FB6-9A70-28F25F15D80D', N'MFAMaxRetryGetCode',3);
    INSERT into @VendorSettingsTypes (RowId, [Name], SettingsType) VALUES ('8CD7D76D-10D4-4575-BA1A-40F5E68B3F8F', N'MFAMaxRetryVerifyCode',3);

    MERGE INTO dbo.[VendorSettingsTypes] AS TARGET  
		USING @VendorSettingsTypes AS SOURCE  
		ON TARGET.RowId = SOURCE.RowId	
		WHEN MATCHED THEN    
			UPDATE SET	[Name] = SOURCE.[Name],
						[SettingsType] = SOURCE.[SettingsType]
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (RowId, [Name], SettingsType) VALUES (SOURCE.RowId, SOURCE.[Name], SOURCE.SettingsType)  
	OUTPUT $action, SOURCE.*;

	--VendorSettings
	DECLARE @VendorSettings TABLE (VendorId int NOT NULL, SettingTypeId int NOT NULL, Value nvarchar(1024) NULL);

	--Get the settings DB Id

    declare @MFALoginBlockAfterFailedRetriesGetCodeInMinutes int
    select @MFALoginBlockAfterFailedRetriesGetCodeInMinutes  = Id from VendorSettingsTypes where RowId='56B0FED3-404D-4384-909F-68498CFBE937'
    INSERT into @VendorSettings select VendorTbl.VendorId,@MFALoginBlockAfterFailedRetriesGetCodeInMinutes ,'15' from VendorTbl order by VendorId

    declare @MFALoginBlockAfterFailedRetriesVerifyCodeInMinutes int
    select @MFALoginBlockAfterFailedRetriesVerifyCodeInMinutes = Id from VendorSettingsTypes where RowId='0C2D2B62-E797-4C51-AE88-2FD6A8E0BB09'
    INSERT into @VendorSettings select VendorTbl.VendorId,@MFALoginBlockAfterFailedRetriesVerifyCodeInMinutes,'15' from VendorTbl order by VendorId

    declare @MFAMaxRetryGetCode int
    select @MFAMaxRetryGetCode= Id from VendorSettingsTypes where RowId='D91A9480-3DD3-4FB6-9A70-28F25F15D80D'
    INSERT into @VendorSettings select VendorTbl.VendorId,@MFAMaxRetryGetCode,'3' from VendorTbl order by VendorId

    declare @MFAMaxRetryVerifyCode int
    select @MFAMaxRetryVerifyCode = Id from VendorSettingsTypes where RowId='8CD7D76D-10D4-4575-BA1A-40F5E68B3F8F'
        INSERT into @VendorSettings select VendorTbl.VendorId,@MFAMaxRetryVerifyCode ,'3' from VendorTbl order by VendorId


        MERGE INTO dbo.[VendorSettings] AS TARGET  
		USING @VendorSettings AS SOURCE  
		ON TARGET.VendorId = SOURCE.VendorId and TARGET.SettingTypeId = SOURCE.SettingTypeId	
		WHEN MATCHED THEN    
			UPDATE SET	[Value] = SOURCE.[Value],
						[UpdatedUtc] = GetUtcDate()
		WHEN NOT MATCHED BY TARGET THEN   
			INSERT (VendorId, SettingTypeId, [Value],CreatedUtc,UpdatedUtc) VALUES (SOURCE.VendorId, SOURCE.SettingTypeId, SOURCE.[Value],GetUtcDate(),GetUtcDate())  
	OUTPUT $action, SOURCE.*;

	-- remove the old block field
	declare @MFALoginBlockAfterFailedRetriesInMinutes int
    select @MFALoginBlockAfterFailedRetriesInMinutes = Id from VendorSettingsTypes where RowId='53B794F2-F3AE-4F28-8D74-B423B8077122'
	delete from vendorsettings where SettingTypeId = @MFALoginBlockAfterFailedRetriesInMinutes
	delete from vendorsettingstypes where id=@MFALoginBlockAfterFailedRetriesInMinutes

	-- remove the old maxRetry field
    declare @MFAMaxRetry int
    select @MFAMaxRetry= Id from VendorSettingsTypes where RowId='61F6A9BF-AEB2-4FF8-B3ED-1AC27281BF1C'
    delete from vendorsettings where SettingTypeId = @MFAMaxRetry
    delete from vendorsettingstypes where id=@MFAMaxRetry
