-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration_fix_embedding_logs.sql
More file actions
49 lines (45 loc) · 1.42 KB
/
Copy pathmigration_fix_embedding_logs.sql
File metadata and controls
49 lines (45 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Migration to fix embedding_logs table
-- First drop the table if it exists (since it has incorrect schema)
DROP TABLE IF EXISTS public.embedding_logs;
-- Create the table with the correct schema
CREATE TABLE IF NOT EXISTS public.embedding_logs (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
timestamp TIMESTAMP WITH TIME ZONE DEFAULT now(),
provider VARCHAR NOT NULL,
input_type VARCHAR,
success BOOLEAN NOT NULL,
error_message TEXT,
character_count INTEGER,
processing_time_ms INTEGER,
endpoint VARCHAR,
object_type VARCHAR,
object_id VARCHAR
);
-- Create indexes for faster querying
CREATE INDEX embedding_logs_provider_idx ON public.embedding_logs(provider);
CREATE INDEX embedding_logs_timestamp_idx ON public.embedding_logs(timestamp);
CREATE INDEX embedding_logs_success_idx ON public.embedding_logs(success);
-- Add comment to the table
COMMENT ON TABLE public.embedding_logs IS 'Logs for embedding generation operations';
-- Create a helper function to get table columns (for schema migrations/compatibility)
CREATE OR REPLACE FUNCTION get_table_columns(table_name text)
RETURNS TABLE (
column_name text,
data_type text,
is_nullable boolean
)
LANGUAGE sql
SECURITY DEFINER
AS $$
SELECT
column_name::text,
data_type::text,
(is_nullable = 'YES') as is_nullable
FROM
information_schema.columns
WHERE
table_schema = 'public'
AND table_name = $1
ORDER BY
ordinal_position;
$$;