You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ai_synth/backend/migrations/20260321000008_create_user_...

18 lines
667 B
SQL

-- User API keys table: stores encrypted LLM provider API keys per user.
-- Each user can have at most one key per provider.
CREATE TABLE user_api_keys (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
provider_name VARCHAR(50) NOT NULL,
encrypted_key BYTEA NOT NULL,
nonce BYTEA NOT NULL,
key_prefix VARCHAR(10) NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(user_id, provider_name)
);
CREATE INDEX idx_user_api_keys_user_id ON user_api_keys(user_id);