docs/source/resources/db_setup/README.md
This directory contains SQL scripts needed to set up database tables for storing conversation state when using the OpenAI Responses API.
psql CLI tool or database admin accesspsql $DATABASE_URL -f docs/db_setup/conversation_states.sql
conversation_states.sqlConnect to your PostgreSQL database using your preferred client and execute the SQL from conversation_states.sql.
After running the setup, verify the table was created:
SELECT tablename FROM pg_tables WHERE tablename = 'conversation_states';
You should see conversation_states in the results.
After setting up the database table, configure your application to use Supabase storage by setting the appropriate environment variable or configuration parameter with your database connection string.
Important: Supabase requires different connection strings depending on your network:
IPv4 Networks (Most Common): Use the Session Pooler connection string (port 5432):
postgresql://postgres.[PROJECT-REF]:[PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres
IPv6 Networks: Use the direct connection (port 5432):
postgresql://postgres:[PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres
How to get your connection string:
[YOUR-PASSWORD] with your actual database password# becomes %23)Example:
# If your password is "P@ss#123", encode it as "P%40ss%23123"
export DATABASE_URL="postgresql://postgres.[YOUR-PROJECT-REF]:<your-url-encoded-password>@aws-0-[REGION].pooler.supabase.com:5432/postgres"
To test your connection string works:
export TEST_DATABASE_URL="your-connection-string-here"
cd crates/brightstaff
cargo test supabase -- --nocapture
The conversation_states table stores:
response_id (TEXT, PRIMARY KEY): Unique identifier for each conversationinput_items (JSONB): Array of conversation messages and contextcreated_at (BIGINT): Unix timestamp when conversation startedmodel (TEXT): Model name used for the conversationprovider (TEXT): LLM provider nameupdated_at (TIMESTAMP): Last update time (auto-managed)To prevent unbounded growth, consider periodically cleaning up old conversation states:
-- Delete conversations older than 7 days
DELETE FROM conversation_states
WHERE updated_at < NOW() - INTERVAL '7 days';
You can automate this with a cron job or database trigger.
If you encounter errors on first use: