File tree Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change 11BEGIN ;
22
3- -- Drop helper functions (now using RETURNS TABLE syntax)
3+ -- Drop helper functions
44DROP FUNCTION IF EXISTS decrypt_api_key(BYTEA , TEXT );
55DROP FUNCTION IF EXISTS encrypt_api_key(TEXT , TEXT );
66
Original file line number Diff line number Diff line change @@ -43,31 +43,28 @@ CREATE INDEX IF NOT EXISTS idx_api_keys_metadata ON api_keys USING gin(metadata)
4343CREATE INDEX IF NOT EXISTS idx_api_keys_deleted_at ON api_keys(deleted_at) WHERE deleted_at IS NULL ;
4444
4545-- Helper functions for encryption/decryption (following secrets pattern)
46- -- Modified to return TABLE so they can be tracked by Hasura
4746CREATE OR REPLACE FUNCTION encrypt_api_key (
4847 p_value TEXT ,
4948 p_key TEXT
50- ) RETURNS TABLE(encrypted_value BYTEA ) AS $$
49+ ) RETURNS BYTEA AS $$
5150BEGIN
52- RETURN QUERY SELECT
53- pgp_sym_encrypt(
54- p_value,
55- p_key,
56- ' cipher-algo=aes256'
57- );
51+ RETURN pgp_sym_encrypt(
52+ p_value,
53+ p_key,
54+ ' cipher-algo=aes256'
55+ );
5856END;
5957$$ LANGUAGE plpgsql SECURITY DEFINER;
6058
6159CREATE OR REPLACE FUNCTION decrypt_api_key (
6260 p_encrypted_value BYTEA ,
6361 p_key TEXT
64- ) RETURNS TABLE(decrypted_value TEXT ) AS $$
62+ ) RETURNS TEXT AS $$
6563BEGIN
66- RETURN QUERY SELECT
67- pgp_sym_decrypt(
68- p_encrypted_value,
69- p_key
70- );
64+ RETURN pgp_sym_decrypt(
65+ p_encrypted_value,
66+ p_key
67+ );
7168END;
7269$$ LANGUAGE plpgsql SECURITY DEFINER;
7370
You can’t perform that action at this time.
0 commit comments