Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to end up with multiple players with the same route #623

Open
sussexrick opened this issue Sep 17, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@sussexrick
Copy link
Member

sussexrick commented Sep 17, 2022

SELECT PlayerRoute, COUNT(PlayerId) FROM StoolballPlayer GROUP BY PlayerRoute HAVING COUNT(PlayerId) > 1 returns the affected players.

This was already the case before the implementation of #615

Affected player identities are the same name and the same team, which should have matched the existing identity. The following query shows the players who were affected, even after the fix below:

SELECT PlayerIdentityName, COUNT(PlayerIdentityId) FROM StoolballPlayerIdentity GROUP BY PlayerIdentityName, TeamId HAVING COUNT(PlayerIdentityId) > 1

Many are players with no statistics, which would not be there if #555 was completed, so #555 might solve this. However statistics are not used in matching an existing identity, so this doesn't explain why they weren't matched.

Script used to fix the affected players:

DECLARE @playerId uniqueidentifier, @duplicatedRoute nvarchar(255), @revisedRoute nvarchar(255)
SET @duplicatedRoute = '/players/affected-name'
SET @revisedRoute = '/players/affected-name-1'

-- Find a new route that works
SELECT PlayerId FROM StoolballPlayer WHERE PlayerRoute = @revisedRoute
IF @@ROWCOUNT = 0
BEGIN
	-- Apply new route
	PRINT 'New route is unused. Applying.'

	BEGIN TRAN
	SELECT TOP 1 @playerId = PlayerId FROM StoolballPlayer WHERE PlayerRoute = @duplicatedRoute
	UPDATE StoolballPlayer SET PlayerRoute = @revisedRoute WHERE PlayerId = @playerId
	UPDATE StoolballPlayerInMatchStatistics SET PlayerRoute = @revisedRoute WHERE PlayerId = @playerId
	COMMIT TRAN
END
ELSE
	PRINT 'New route in use. Try another.'
@sussexrick sussexrick added the bug Something isn't working label Sep 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant