Last active
October 16, 2015 16:06
-
-
Save cadecairos/a8c44ef236969d51a09c to your computer and use it in GitHub Desktop.
Generate uuid v4 reset codes using a plpgsql function and a trigger
This file contains hidden or 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
CREATE EXTENSION IF NOT EXISTS pgcrypto; | |
CREATE OR REPLACE FUNCTION generate_reset_code() | |
RETURNS TRIGGER AS $$ | |
BEGIN | |
NEW.code = gen_random_uuid(); | |
RETURN NEW; | |
END; | |
$$ language 'plpgsql'; | |
CREATE TRIGGER trigger_generate_reset_code BEFORE CREATE ON reset_codes | |
FOR EACH ROW EXECUTE PROCEDURE generate_reset_code(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment