mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
feat: add database CHECK constraints for data integrity
Per CodeRabbit feedback - enforce numeric domain rules at DB level: Migration: - priceTier: CHECK (priceTier BETWEEN 1 AND 3) - creditCost: CHECK (creditCost >= 0) - nodeCount: CHECK (nodeCount >= 0) - customCreditCost: CHECK (customCreditCost IS NULL OR customCreditCost >= 0) Schema comments: - Document constraints inline for developer visibility Prevents invalid data (negative costs, out-of-range tiers) from entering the database, matching backend/blocks/llm.py contract.
This commit is contained in:
@@ -138,3 +138,14 @@ ALTER TABLE "platform"."LlmModel" ADD CONSTRAINT "LlmModel_creatorId_fkey" FOREI
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "platform"."LlmModelCost" ADD CONSTRAINT "LlmModelCost_llmModelId_fkey" FOREIGN KEY ("llmModelId") REFERENCES "platform"."LlmModel"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddCheckConstraints (enforce data integrity)
|
||||
ALTER TABLE "platform"."LlmModel"
|
||||
ADD CONSTRAINT "LlmModel_priceTier_check" CHECK ("priceTier" BETWEEN 1 AND 3);
|
||||
|
||||
ALTER TABLE "platform"."LlmModelCost"
|
||||
ADD CONSTRAINT "LlmModelCost_creditCost_check" CHECK ("creditCost" >= 0);
|
||||
|
||||
ALTER TABLE "platform"."LlmModelMigration"
|
||||
ADD CONSTRAINT "LlmModelMigration_nodeCount_check" CHECK ("nodeCount" >= 0),
|
||||
ADD CONSTRAINT "LlmModelMigration_customCreditCost_check" CHECK ("customCreditCost" IS NULL OR "customCreditCost" >= 0);
|
||||
|
||||
@@ -1384,7 +1384,7 @@ model LlmModel {
|
||||
|
||||
contextWindow Int
|
||||
maxOutputTokens Int?
|
||||
priceTier Int @default(1) // 1=cheapest, 2=medium, 3=expensive
|
||||
priceTier Int @default(1) // 1=cheapest, 2=medium, 3=expensive (DB constraint: 1-3)
|
||||
isEnabled Boolean @default(true)
|
||||
isRecommended Boolean @default(false)
|
||||
|
||||
@@ -1412,7 +1412,7 @@ model LlmModelCost {
|
||||
updatedAt DateTime @updatedAt
|
||||
unit LlmCostUnit @default(RUN)
|
||||
|
||||
creditCost Int
|
||||
creditCost Int // DB constraint: >= 0
|
||||
|
||||
credentialProvider String
|
||||
credentialId String?
|
||||
@@ -1460,7 +1460,7 @@ model LlmModelMigration {
|
||||
// Track affected nodes as JSON array of node IDs
|
||||
// Format: ["node-uuid-1", "node-uuid-2", ...]
|
||||
migratedNodeIds Json @default("[]")
|
||||
nodeCount Int // Number of nodes migrated
|
||||
nodeCount Int // Number of nodes migrated (DB constraint: >= 0)
|
||||
|
||||
// Custom pricing override for migrated workflows during the migration period.
|
||||
// Use case: When migrating users from an expensive model (e.g., GPT-4) to a cheaper
|
||||
@@ -1473,7 +1473,7 @@ model LlmModelMigration {
|
||||
// If null, the target model's normal cost applies.
|
||||
//
|
||||
// TODO: Integrate with billing system to apply this override during cost calculation.
|
||||
customCreditCost Int?
|
||||
customCreditCost Int? // DB constraint: >= 0 when not null
|
||||
|
||||
// Revert tracking
|
||||
isReverted Boolean @default(false)
|
||||
|
||||
Reference in New Issue
Block a user