Skip to content

Commit 25fac5b

Browse files
fix: Fix encrypt function return type
1 parent 56e492d commit 25fac5b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

memory-store/migrations/000042_add_api_keys.up.sql

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,31 @@ BEGIN
6666
END $$;
6767

6868
-- Helper functions for encryption/decryption (following secrets pattern)
69-
-- Modified to return composite types so they can be tracked by Hasura
69+
-- Modified to return SETOF composite types so they return tables that Hasura can track
7070
CREATE OR REPLACE FUNCTION encrypt_api_key(
7171
p_value TEXT,
7272
p_key TEXT
73-
) RETURNS encrypted_api_key_result AS $$
73+
) RETURNS SETOF encrypted_api_key_result AS $$
7474
BEGIN
75-
RETURN ROW(
75+
RETURN QUERY SELECT
7676
pgp_sym_encrypt(
7777
p_value,
7878
p_key,
7979
'cipher-algo=aes256'
80-
)
81-
)::encrypted_api_key_result;
80+
) AS encrypted_value;
8281
END;
8382
$$ LANGUAGE plpgsql SECURITY DEFINER;
8483

8584
CREATE OR REPLACE FUNCTION decrypt_api_key(
8685
p_encrypted_value BYTEA,
8786
p_key TEXT
88-
) RETURNS decrypted_api_key_result AS $$
87+
) RETURNS SETOF decrypted_api_key_result AS $$
8988
BEGIN
90-
RETURN ROW(
89+
RETURN QUERY SELECT
9190
pgp_sym_decrypt(
9291
p_encrypted_value,
9392
p_key
94-
)
95-
)::decrypted_api_key_result;
93+
) AS decrypted_value;
9694
END;
9795
$$ LANGUAGE plpgsql SECURITY DEFINER;
9896

0 commit comments

Comments
 (0)