Skip to content

Commit f5fd7a2

Browse files
fix: Fix functions return types
1 parent 25fac5b commit f5fd7a2

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
BEGIN;
22

3-
-- Drop helper functions (updated signatures due to composite type returns)
3+
-- Drop helper functions (now using RETURNS TABLE syntax)
44
DROP FUNCTION IF EXISTS decrypt_api_key(BYTEA, TEXT);
55
DROP FUNCTION IF EXISTS encrypt_api_key(TEXT, TEXT);
66

7-
-- Drop composite types
8-
DROP TYPE IF EXISTS decrypted_api_key_result;
9-
DROP TYPE IF EXISTS encrypted_api_key_result;
10-
117
-- Drop trigger and function
128
DROP TRIGGER IF EXISTS update_api_keys_timestamp_trigger ON api_keys;
139
DROP FUNCTION IF EXISTS update_api_keys_timestamp();

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

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,32 @@ CREATE INDEX IF NOT EXISTS idx_api_keys_name ON api_keys(name);
4242
CREATE INDEX IF NOT EXISTS idx_api_keys_metadata ON api_keys USING gin(metadata);
4343
CREATE INDEX IF NOT EXISTS idx_api_keys_deleted_at ON api_keys(deleted_at) WHERE deleted_at IS NULL;
4444

45-
-- Create composite types for function return values (so they can be tracked by Hasura)
46-
DO $$
47-
BEGIN
48-
IF NOT EXISTS (
49-
SELECT 1 FROM pg_type WHERE typname = 'encrypted_api_key_result'
50-
) THEN
51-
CREATE TYPE encrypted_api_key_result AS (
52-
encrypted_value BYTEA
53-
);
54-
END IF;
55-
END $$;
56-
57-
DO $$
58-
BEGIN
59-
IF NOT EXISTS (
60-
SELECT 1 FROM pg_type WHERE typname = 'decrypted_api_key_result'
61-
) THEN
62-
CREATE TYPE decrypted_api_key_result AS (
63-
decrypted_value TEXT
64-
);
65-
END IF;
66-
END $$;
67-
6845
-- Helper functions for encryption/decryption (following secrets pattern)
69-
-- Modified to return SETOF composite types so they return tables that Hasura can track
46+
-- Modified to return TABLE so they can be tracked by Hasura
7047
CREATE OR REPLACE FUNCTION encrypt_api_key(
7148
p_value TEXT,
7249
p_key TEXT
73-
) RETURNS SETOF encrypted_api_key_result AS $$
50+
) RETURNS TABLE(encrypted_value BYTEA) AS $$
7451
BEGIN
7552
RETURN QUERY SELECT
7653
pgp_sym_encrypt(
7754
p_value,
7855
p_key,
7956
'cipher-algo=aes256'
80-
) AS encrypted_value;
57+
);
8158
END;
8259
$$ LANGUAGE plpgsql SECURITY DEFINER;
8360

8461
CREATE OR REPLACE FUNCTION decrypt_api_key(
8562
p_encrypted_value BYTEA,
8663
p_key TEXT
87-
) RETURNS SETOF decrypted_api_key_result AS $$
64+
) RETURNS TABLE(decrypted_value TEXT) AS $$
8865
BEGIN
8966
RETURN QUERY SELECT
9067
pgp_sym_decrypt(
9168
p_encrypted_value,
9269
p_key
93-
) AS decrypted_value;
70+
);
9471
END;
9572
$$ LANGUAGE plpgsql SECURITY DEFINER;
9673

0 commit comments

Comments
 (0)