mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
e9b7acd2b4
On fresh databases, 0001_init.up.sql creates providers/provider_id (not llm_providers/llm_provider_id). Migrations 0013, 0041, 0046, 0047 referenced the old names without guards, causing CI migration failures. - 0013: check llm_provider_id column exists before adding old constraint - 0041: check llm_providers table exists before backfill/constraint DDL - 0046: wrap CREATE TABLE in DO block with llm_providers existence check - 0047: use ALTER TABLE IF EXISTS + DO block guard
27 lines
1.2 KiB
SQL
27 lines
1.2 KiB
SQL
-- 0046_llm_provider_oauth
|
|
-- Add OAuth token storage for LLM providers to support OpenAI Codex OAuth.
|
|
-- On fresh databases, provider_oauth_tokens is already created by 0001_init.
|
|
|
|
DO $$
|
|
BEGIN
|
|
-- Only create old-style table when llm_providers still exists (pre-0061 schema).
|
|
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'llm_providers')
|
|
AND NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'llm_provider_oauth_tokens')
|
|
THEN
|
|
CREATE TABLE llm_provider_oauth_tokens (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
llm_provider_id UUID NOT NULL UNIQUE REFERENCES llm_providers(id) ON DELETE CASCADE,
|
|
access_token TEXT NOT NULL DEFAULT '',
|
|
refresh_token TEXT NOT NULL DEFAULT '',
|
|
expires_at TIMESTAMPTZ,
|
|
scope TEXT NOT NULL DEFAULT '',
|
|
token_type TEXT NOT NULL DEFAULT '',
|
|
state TEXT NOT NULL DEFAULT '',
|
|
pkce_code_verifier TEXT NOT NULL DEFAULT '',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX idx_llm_provider_oauth_tokens_state ON llm_provider_oauth_tokens(state) WHERE state != '';
|
|
END IF;
|
|
END $$;
|