-- create a utility that bootstraps a user
CREATE OR REPLACE FUNCTION bootstrap_users() RETURNS void AS $$
DECLARE
 test_user VARCHAR(64);
BEGIN
-- non guid used for test user.  test user won't be in actual database,     but '1' is much easier to script that 242423-42-4-24234
-- password is jam123
    SELECT id INTO STRICT test_user FROM users WHERE id = '1';
    
    UPDATE users SET name = 'test', email = 'test@jamkazam.com', remember_token = 'NQubl-z16Em94tnSdofObw', password_digest = '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', email_confirmed=true WHERE id = '1';
    
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            INSERT INTO users (id, name, email, remember_token, password_digest, email_confirmed) VALUES ('1', 'test', 'test@jamkazam.com', 'NQubl-z16Em94tnSdofObw', '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', true);
            RETURN;
        WHEN TOO_MANY_ROWS THEN
            RAISE EXCEPTION 'user id 1 not unique';
END;
$$ LANGUAGE plpgsql;
 
select bootstrap_users();

