alles andere
This commit is contained in:
263
packages/orchestrator/prisma/schema.prisma
Normal file
263
packages/orchestrator/prisma/schema.prisma
Normal file
@@ -0,0 +1,263 @@
|
||||
// Prisma schema for Self-Replicating Business System
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// BUSINESS MODEL
|
||||
// ============================================
|
||||
model Business {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
idea String @db.Text
|
||||
status BusinessStatus @default(VALIDATING)
|
||||
viable Boolean?
|
||||
|
||||
// URLs
|
||||
mvpUrl String?
|
||||
landingPageUrl String?
|
||||
|
||||
// Feature flags
|
||||
seoOptimized Boolean @default(false)
|
||||
adsActive Boolean @default(false)
|
||||
emailAutomation Boolean @default(false)
|
||||
|
||||
// Revenue metrics
|
||||
monthlyRevenue Float @default(0)
|
||||
totalRevenue Float @default(0)
|
||||
|
||||
// Validation data (JSONB)
|
||||
validationResult Json?
|
||||
targetAudience String?
|
||||
budget Float?
|
||||
|
||||
// Relationships
|
||||
workflows WorkflowRun[]
|
||||
campaigns Campaign[]
|
||||
metrics Metric[]
|
||||
decisions Decision[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([status, monthlyRevenue])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
enum BusinessStatus {
|
||||
VALIDATING
|
||||
VALIDATION_FAILED
|
||||
DEVELOPING_MVP
|
||||
LAUNCHING
|
||||
RUNNING_ADS
|
||||
OPTIMIZING
|
||||
SCALING
|
||||
SELLING
|
||||
SHUTDOWN
|
||||
PAUSED
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// WORKFLOW EXECUTION MODEL
|
||||
// ============================================
|
||||
model WorkflowRun {
|
||||
id String @id @default(cuid())
|
||||
businessId String
|
||||
business Business @relation(fields: [businessId], references: [id], onDelete: Cascade)
|
||||
|
||||
workflowType WorkflowType
|
||||
status WorkflowStatus @default(PENDING)
|
||||
|
||||
inputData Json @default("{}")
|
||||
outputData Json?
|
||||
error String? @db.Text
|
||||
|
||||
attempts Int @default(0)
|
||||
maxRetries Int @default(3)
|
||||
|
||||
startedAt DateTime?
|
||||
completedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([businessId, workflowType])
|
||||
@@index([status])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
enum WorkflowType {
|
||||
MARKET_VALIDATION
|
||||
MVP_DEVELOPMENT
|
||||
LANDING_PAGE_SEO
|
||||
PAID_ADS
|
||||
CONTENT_MARKETING
|
||||
EMAIL_AUTOMATION
|
||||
ANALYTICS_SETUP
|
||||
OPTIMIZATION_LOOP
|
||||
}
|
||||
|
||||
enum WorkflowStatus {
|
||||
PENDING
|
||||
IN_PROGRESS
|
||||
COMPLETED
|
||||
FAILED
|
||||
RETRYING
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// CAMPAIGN MODEL
|
||||
// ============================================
|
||||
model Campaign {
|
||||
id String @id @default(cuid())
|
||||
businessId String
|
||||
business Business @relation(fields: [businessId], references: [id], onDelete: Cascade)
|
||||
|
||||
platform Platform
|
||||
campaignId String? // External campaign ID
|
||||
adSetId String? // External ad set ID
|
||||
|
||||
name String
|
||||
budget Float
|
||||
dailyBudget Float?
|
||||
active Boolean @default(true)
|
||||
|
||||
// Metrics
|
||||
impressions Int @default(0)
|
||||
clicks Int @default(0)
|
||||
conversions Int @default(0)
|
||||
spend Float @default(0)
|
||||
revenue Float @default(0)
|
||||
|
||||
// Campaign config (JSONB)
|
||||
targeting Json?
|
||||
creative Json?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([businessId, platform])
|
||||
@@index([active])
|
||||
}
|
||||
|
||||
enum Platform {
|
||||
FACEBOOK
|
||||
GOOGLE
|
||||
ORGANIC
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// METRICS MODEL
|
||||
// ============================================
|
||||
model Metric {
|
||||
id String @id @default(cuid())
|
||||
businessId String
|
||||
business Business @relation(fields: [businessId], references: [id], onDelete: Cascade)
|
||||
|
||||
timestamp DateTime @default(now())
|
||||
|
||||
// Financial metrics
|
||||
revenue Float @default(0)
|
||||
adSpend Float @default(0)
|
||||
profit Float @default(0)
|
||||
roas Float? // Return on Ad Spend
|
||||
|
||||
// Traffic metrics
|
||||
visitors Int @default(0)
|
||||
pageViews Int @default(0)
|
||||
bounceRate Float?
|
||||
avgSessionDuration Float?
|
||||
|
||||
// Conversion metrics
|
||||
conversions Int @default(0)
|
||||
conversionRate Float?
|
||||
|
||||
// Source breakdown (JSONB)
|
||||
sourceBreakdown Json?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([businessId, timestamp])
|
||||
@@index([timestamp])
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DECISION MODEL
|
||||
// ============================================
|
||||
model Decision {
|
||||
id String @id @default(cuid())
|
||||
businessId String
|
||||
business Business @relation(fields: [businessId], references: [id], onDelete: Cascade)
|
||||
|
||||
decisionType DecisionType
|
||||
action String @db.Text
|
||||
reasoning String @db.Text
|
||||
|
||||
revenueAtDecision Float?
|
||||
metricsSnapshot Json? // Snapshot of all metrics at decision time
|
||||
|
||||
executed Boolean @default(false)
|
||||
executedAt DateTime?
|
||||
executionResult Json?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([businessId, decisionType])
|
||||
@@index([executed])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
enum DecisionType {
|
||||
SCALE_PRODUCT
|
||||
SELL_BUSINESS
|
||||
SHUTDOWN
|
||||
PAUSE_CAMPAIGN
|
||||
INCREASE_BUDGET
|
||||
HIRE_VA
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// ALERT/NOTIFICATION MODEL
|
||||
// ============================================
|
||||
model Alert {
|
||||
id String @id @default(cuid())
|
||||
businessId String?
|
||||
|
||||
type AlertType
|
||||
severity AlertSeverity @default(INFO)
|
||||
|
||||
title String
|
||||
message String @db.Text
|
||||
metadata Json?
|
||||
|
||||
read Boolean @default(false)
|
||||
acknowledged Boolean @default(false)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([businessId])
|
||||
@@index([type, severity])
|
||||
@@index([read])
|
||||
}
|
||||
|
||||
enum AlertType {
|
||||
WORKFLOW_FAILED
|
||||
WORKFLOW_COMPLETED
|
||||
REVENUE_MILESTONE
|
||||
DECISION_EXECUTED
|
||||
API_ERROR
|
||||
BUDGET_THRESHOLD
|
||||
SYSTEM_ERROR
|
||||
}
|
||||
|
||||
enum AlertSeverity {
|
||||
INFO
|
||||
WARNING
|
||||
ERROR
|
||||
CRITICAL
|
||||
}
|
||||
Reference in New Issue
Block a user