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
20 lines
803 B
SQL
20 lines
803 B
SQL
-- 0013_model_id_unique_per_provider
|
|
-- Change model_id uniqueness from global to per provider.
|
|
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'models_model_id_unique') THEN
|
|
ALTER TABLE models DROP CONSTRAINT models_model_id_unique;
|
|
END IF;
|
|
|
|
-- Only add old-style constraint when llm_provider_id column exists (pre-0061 schema).
|
|
-- Fresh databases already have provider_id with models_provider_id_model_id_unique.
|
|
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'models_provider_model_id_unique')
|
|
AND EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'models' AND column_name = 'llm_provider_id')
|
|
THEN
|
|
ALTER TABLE models
|
|
ADD CONSTRAINT models_provider_model_id_unique UNIQUE (llm_provider_id, model_id);
|
|
END IF;
|
|
END
|
|
$$;
|