diff --git a/autogpt_platform/backend/migrations/20251126113000_add_llm_registry/migration.sql b/autogpt_platform/backend/migrations/20251126113000_add_llm_registry/migration.sql index 704bc17486..017c4244d6 100644 --- a/autogpt_platform/backend/migrations/20251126113000_add_llm_registry/migration.sql +++ b/autogpt_platform/backend/migrations/20251126113000_add_llm_registry/migration.sql @@ -70,6 +70,9 @@ CREATE INDEX "LlmModelCost_llmModelId_idx" ON "LlmModelCost"("llmModelId"); -- CreateIndex CREATE INDEX "LlmModelCost_credentialProvider_idx" ON "LlmModelCost"("credentialProvider"); +-- CreateIndex +CREATE UNIQUE INDEX "LlmModelCost_llmModelId_credentialProvider_unit_key" ON "LlmModelCost"("llmModelId", "credentialProvider", "unit"); + -- AddForeignKey ALTER TABLE "LlmModel" ADD CONSTRAINT "LlmModel_providerId_fkey" FOREIGN KEY ("providerId") REFERENCES "LlmProvider"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/autogpt_platform/backend/migrations/20251126120000_seed_llm_registry/migration.sql b/autogpt_platform/backend/migrations/20251126120000_seed_llm_registry/migration.sql index a59ee716fa..2163d533bf 100644 --- a/autogpt_platform/backend/migrations/20251126120000_seed_llm_registry/migration.sql +++ b/autogpt_platform/backend/migrations/20251126120000_seed_llm_registry/migration.sql @@ -221,5 +221,6 @@ FROM (VALUES ('v0-1.0-md', 1) ) AS costs(model_slug, cost) JOIN model_ids m ON m."slug" = costs.model_slug -JOIN provider_ids p ON p."id" = m."providerId"; +JOIN provider_ids p ON p."id" = m."providerId" +ON CONFLICT ("llmModelId", "credentialProvider", "unit") DO NOTHING; diff --git a/autogpt_platform/backend/schema.prisma b/autogpt_platform/backend/schema.prisma index 3a248320c2..84b101a1dd 100644 --- a/autogpt_platform/backend/schema.prisma +++ b/autogpt_platform/backend/schema.prisma @@ -1198,6 +1198,7 @@ model LlmModelCost { llmModelId String Model LlmModel @relation(fields: [llmModelId], references: [id], onDelete: Cascade) + @@unique([llmModelId, credentialProvider, unit]) @@index([llmModelId]) @@index([credentialProvider]) }