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.
feat(db): store user agent and last-access time in sessionTokens
- Loading branch information
Showing
9 changed files
with
203 additions
and
15 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,71 @@ | ||
-- Add userAgent and lastAccessTime fields to sessionTokens table | ||
|
||
ALTER TABLE sessionTokens ADD COLUMN userAgent VARCHAR(255) NOT NULL DEFAULT ''; | ||
ALTER TABLE sessionTokens ADD COLUMN lastAccessTime BIGINT UNSIGNED NOT NULL DEFAULT 0; | ||
|
||
CREATE PROCEDURE `createSessionToken_2` ( | ||
IN tokenId BINARY(32), | ||
IN tokenData BINARY(32), | ||
IN uid BINARY(16), | ||
IN createdAt BIGINT UNSIGNED, | ||
IN userAgent VARCHAR(255), | ||
IN lastAccessTime BIGINT UNSIGNED | ||
) | ||
BEGIN | ||
INSERT INTO sessionTokens( | ||
tokenId, | ||
tokenData, | ||
uid, | ||
createdAt, | ||
userAgent, | ||
lastAccessTime | ||
) | ||
VALUES( | ||
tokenId, | ||
tokenData, | ||
uid, | ||
createdAt, | ||
userAgent, | ||
lastAccessTime | ||
); | ||
END; | ||
|
||
CREATE PROCEDURE `sessionToken_2` ( | ||
IN `inTokenId` BINARY(32) | ||
) | ||
BEGIN | ||
SELECT | ||
t.tokenData, | ||
t.uid, | ||
t.createdAt, | ||
t.userAgent, | ||
t.lastAccessTime, | ||
a.emailVerified, | ||
a.email, | ||
a.emailCode, | ||
a.verifierSetAt, | ||
a.locale | ||
FROM | ||
sessionTokens t, | ||
accounts a | ||
WHERE | ||
t.tokenId = inTokenId | ||
AND | ||
t.uid = a.uid | ||
; | ||
END; | ||
|
||
CREATE PROCEDURE `updateSessionToken_1` ( | ||
IN userAgentArg VARCHAR(255), | ||
IN lastAccessTimeArg BIGINT UNSIGNED, | ||
IN tokenIdArg BINARY(32) | ||
) | ||
BEGIN | ||
UPDATE sessionTokens | ||
SET userAgent = userAgentArg, | ||
lastAccessTime = lastAccessTimeArg | ||
WHERE tokenId = tokenIdArg; | ||
END; | ||
|
||
UPDATE dbMetadata SET value = '15' 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,11 @@ | ||
-- -- drop new stored procedures | ||
-- DROP PROCEDURE `createSessionToken_2`; | ||
-- DROP PROCEDURE `sessionToken_2`; | ||
-- DROP PROCEDURE `updateSessionToken_1`; | ||
|
||
-- -- drop new columns | ||
-- ALTER TABLE sessionTokens DROP COLUMN userAgent; | ||
-- ALTER TABLE sessionTokens DROP COLUMN lastAccessTime; | ||
|
||
-- -- Schema patch-level decrement. | ||
-- UPDATE dbMetadata SET value = '14' WHERE name = 'schema-patch-level'; |