This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db): ensure that devices get deleted with session tokens
- Loading branch information
Showing
9 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Update deleteSessionToken stored procedure to delete from devices. | ||
CREATE PROCEDURE `deleteSessionToken_3` ( | ||
IN `tokenIdArg` BINARY(32) | ||
) | ||
BEGIN | ||
DECLARE EXIT HANDLER FOR SQLEXCEPTION | ||
BEGIN | ||
ROLLBACK; | ||
RESIGNAL; | ||
END; | ||
|
||
START TRANSACTION; | ||
|
||
DELETE FROM sessionTokens WHERE tokenId = tokenIdArg; | ||
DELETE FROM unverifiedTokens WHERE tokenId = tokenIdArg; | ||
DELETE FROM devices WHERE sessionTokenId = tokenIdArg; | ||
|
||
COMMIT; | ||
END; | ||
|
||
-- Prior to this migration, it was possible to delete a session token | ||
-- without deleting the associated device (if a device record exists). | ||
-- That's fixed by deleteSessionTokens_3, but we should also purge any | ||
-- historical devices that have reached this state. | ||
DELETE FROM devices | ||
USING devices LEFT JOIN sessionTokens | ||
ON devices.sessionTokenId = sessionTokens.tokenId | ||
WHERE sessionTokens.tokenId IS NULL; | ||
|
||
-- Update the patch level. | ||
UPDATE dbMetadata SET value = '30' WHERE name = 'schema-patch-level'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- DROP PROCEDURE `deleteSessionToken_3`; | ||
|
||
-- UPDATE dbMetadata SET value = '29' WHERE name = 'schema-patch-level'; | ||
|