Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
chore(scripts): tweak some old migrations to fix explain errors
Browse files Browse the repository at this point in the history
Some of our old migrations don't conform to assumptions made by the
explain script. This change just tweaks some of the argument names so
that they stop showing up as errors in that script. There are no logical
changes to the stored procedures.
  • Loading branch information
philbooth committed Sep 17, 2018
1 parent 31fff59 commit 9e9457c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
30 changes: 15 additions & 15 deletions lib/db/schema/patch-039-040.sql
Expand Up @@ -31,11 +31,11 @@ END;


CREATE PROCEDURE `fetchVerificationReminders_2` (
IN currentTime BIGINT SIGNED,
IN reminderType VARCHAR(255),
IN reminderTime BIGINT SIGNED,
IN reminderTimeOutdated BIGINT SIGNED,
IN reminderLimit INTEGER
IN currentTimeArg BIGINT SIGNED,
IN reminderTypeArg VARCHAR(255),
IN reminderTimeArg BIGINT SIGNED,
IN reminderTimeOutdatedArg BIGINT SIGNED,
IN reminderLimitArg INTEGER
)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
Expand All @@ -60,29 +60,29 @@ BEGIN
FROM verificationReminders
-- Since we want to order by `createdAt`, we have to rearrange
-- the `WHERE` clauses so `createdAt` is positive rather than negated.
WHERE createdAt < currentTime - reminderTime
AND createdAt > currentTime - reminderTimeOutdated
AND type = reminderType
WHERE createdAt < currentTimeArg - reminderTimeArg
AND createdAt > currentTimeArg - reminderTimeOutdatedArg
AND type = reminderTypeArg
ORDER BY createdAt, uid, type
LIMIT reminderLimit;
LIMIT reminderLimitArg;

-- Because the query is deterministic we can delete
-- all the selected items at once, rather than calling
-- deleteVerificationReminder()
DELETE FROM verificationReminders
WHERE createdAt < currentTime - reminderTime
AND createdAt > currentTime - reminderTimeOutdated
AND type = reminderType
WHERE createdAt < currentTimeArg - reminderTimeArg
AND createdAt > currentTimeArg - reminderTimeOutdatedArg
AND type = reminderTypeArg
ORDER BY createdAt, uid, type
LIMIT reminderLimit;
LIMIT reminderLimitArg;

-- Clean up outdated reminders.
DELETE FROM
verificationReminders
WHERE
createdAt < currentTime - reminderTimeOutdated
createdAt < currentTimeArg - reminderTimeOutdatedArg
AND
type = reminderType;
type = reminderTypeArg;

-- Return the result
SELECT * FROM reminderResults;
Expand Down
4 changes: 2 additions & 2 deletions lib/db/schema/patch-046-047.sql
Expand Up @@ -2,10 +2,10 @@
-- Differs from `emailRecord` that returns a filtered account object

CREATE PROCEDURE `getSecondaryEmail_1` (
IN `email` VARCHAR(255)
IN `emailArg` VARCHAR(255)
)
BEGIN
SELECT * FROM emails WHERE normalizedEmail = LOWER(email);
SELECT * FROM emails WHERE normalizedEmail = LOWER(emailArg);
END;

UPDATE dbMetadata SET value = '47' WHERE name = 'schema-patch-level';
6 changes: 3 additions & 3 deletions lib/db/schema/patch-054-055.sql
Expand Up @@ -15,7 +15,7 @@ END;

CREATE PROCEDURE `consumeSigninCode_4` (
IN `hashArg` BINARY(32),
IN `newerThan` BIGINT UNSIGNED
IN `newerThanArg` BIGINT UNSIGNED
)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
Expand All @@ -30,13 +30,13 @@ BEGIN
FROM signinCodes AS sc
INNER JOIN emails AS e
ON sc.hash = hashArg
AND sc.createdAt > newerThan
AND sc.createdAt > newerThanArg
AND sc.uid = e.uid
AND e.isPrimary = true;

DELETE FROM signinCodes
WHERE hash = hashArg
AND createdAt > newerThan;
AND createdAt > newerThanArg;

COMMIT;
END;
Expand Down
16 changes: 8 additions & 8 deletions lib/db/schema/patch-068-069.sql
Expand Up @@ -6,7 +6,7 @@ UPDATE dbMetadata SET value = '0' WHERE name = 'sessionTokensPrunedUntil' AND va

-- Update prune to limit total number of sessionTokens examined,
-- and avoid producing the above empty-string bug.
CREATE PROCEDURE `prune_7` (IN `olderThan` BIGINT UNSIGNED)
CREATE PROCEDURE `prune_7` (IN `olderThanArg` BIGINT UNSIGNED)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
Expand All @@ -17,11 +17,11 @@ BEGIN
SELECT @lockAcquired := GET_LOCK('fxa-auth-server.prune-lock', 3);

IF @lockAcquired THEN
DELETE FROM accountResetTokens WHERE createdAt < olderThan ORDER BY createdAt LIMIT 10000;
DELETE FROM passwordForgotTokens WHERE createdAt < olderThan ORDER BY createdAt LIMIT 10000;
DELETE FROM passwordChangeTokens WHERE createdAt < olderThan ORDER BY createdAt LIMIT 10000;
DELETE FROM unblockCodes WHERE createdAt < olderThan ORDER BY createdAt LIMIT 10000;
DELETE FROM signinCodes WHERE createdAt < olderThan ORDER BY createdAt LIMIT 10000;
DELETE FROM accountResetTokens WHERE createdAt < olderThanArg ORDER BY createdAt LIMIT 10000;
DELETE FROM passwordForgotTokens WHERE createdAt < olderThanArg ORDER BY createdAt LIMIT 10000;
DELETE FROM passwordChangeTokens WHERE createdAt < olderThanArg ORDER BY createdAt LIMIT 10000;
DELETE FROM unblockCodes WHERE createdAt < olderThanArg ORDER BY createdAt LIMIT 10000;
DELETE FROM signinCodes WHERE createdAt < olderThanArg ORDER BY createdAt LIMIT 10000;

-- Pruning session tokens is complicated because:
-- * we can't prune them if there is an associated device record, and
Expand All @@ -42,14 +42,14 @@ BEGIN
-- *examine*, regardless of whether it actually delete them.
SELECT @pruneUntil := MAX(createdAt) FROM (
SELECT createdAt FROM sessionTokens
WHERE createdAt >= @pruneFrom AND createdAt < olderThan
WHERE createdAt >= @pruneFrom AND createdAt < olderThanArg
ORDER BY createdAt
LIMIT 10000
) AS candidatesForPruning;

-- This will be NULL if there are no expired tokens,
-- in which case we have nothing to do.
IF @pruneUntil IS NOT NULL THEN
IF @pruneUntil IS NOT NULL THEN

-- Step 3: Prune sessionTokens and unverifiedTokens tables.
-- Here we *do* filter on whether a device record exists.
Expand Down

0 comments on commit 9e9457c

Please sign in to comment.