-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): remove postgres cleanup timer and use postgres triggers ins…
…tead
- Loading branch information
Showing
6 changed files
with
57 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
return { | ||
postgres = { | ||
up = [[ | ||
CREATE OR REPLACE FUNCTION batch_delete_expired_rows() RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
IF RANDOM() < 0.01 THEN | ||
EXECUTE FORMAT('WITH rows AS (SELECT ctid FROM %s WHERE ttl < CURRENT_TIMESTAMP AT TIME ZONE ''UTC'' ORDER BY ttl LIMIT 50000 FOR UPDATE SKIP LOCKED) DELETE FROM %s WHERE ctid IN (TABLE rows)', TG_TABLE_NAME, TG_TABLE_NAME); | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$$; | ||
]], | ||
}, | ||
cassandra = { | ||
up = [[]], | ||
} | ||
} |
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 |
---|---|---|
|
@@ -16,4 +16,5 @@ return { | |
"016_280_to_300", | ||
"017_300_to_310", | ||
"018_310_to_320", | ||
"019_320_to_330", | ||
} |
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,33 @@ | ||
return { | ||
postgres = { | ||
up = [[ | ||
DROP TRIGGER IF EXISTS "oauth2_authorization_codes_ttl_trigger" ON "oauth2_authorization_codes"; | ||
DO $$ | ||
BEGIN | ||
CREATE TRIGGER "oauth2_authorization_codes_ttl_trigger" | ||
AFTER INSERT ON "oauth2_authorization_codes" | ||
FOR EACH STATEMENT | ||
EXECUTE PROCEDURE batch_delete_expired_rows(); | ||
EXCEPTION WHEN UNDEFINED_COLUMN OR UNDEFINED_TABLE THEN | ||
-- Do nothing, accept existing state | ||
END$$; | ||
DROP TRIGGER IF EXISTS "oauth2_tokens_ttl_trigger" ON "oauth2_tokens"; | ||
DO $$ | ||
BEGIN | ||
CREATE TRIGGER "oauth2_tokens_ttl_trigger" | ||
AFTER INSERT ON "oauth2_tokens" | ||
FOR EACH STATEMENT | ||
EXECUTE PROCEDURE batch_delete_expired_rows(); | ||
EXCEPTION WHEN UNDEFINED_COLUMN OR UNDEFINED_TABLE THEN | ||
-- Do nothing, accept existing state | ||
END$$; | ||
]], | ||
}, | ||
cassandra = { | ||
up = [[]], | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ return { | |
"003_130_to_140", | ||
"004_200_to_210", | ||
"005_210_to_211", | ||
"006_320_to_330", | ||
} |