Overview85 ModelsWorkflowsERD & Schema

ERD & Prisma 8 Contract Inspector

Inspect the canonical erd.mmd, Prisma 8 prisma.config.ts, emitted contract.d.ts, and all 13 modular prisma/schema/*.prisma contract sources.

erd.mmd (Synced Main ERD)
1,104 lines
---
config:
  layout: elk
  elk:
    direction: TB
---
erDiagram

  TargetRollup {
    TEXT   TargetRollupID    PK
    TEXT   PairType             "OKR | IKPI | Program"
    TEXT   ObjectiveID      FK "→ Objective (nullable)"
    TEXT   KRID             FK "→ KR (nullable)"
    TEXT   InitiativeID     FK "→ Initiative (nullable)"
    TEXT   KPIID            FK "→ KPI (nullable)"
    TEXT   ProgramID        FK "→ Program (nullable)"
    TEXT   ProgramTargetID  FK "→ ProgramTarget (nullable)"
    TEXT   Name
    TEXT   Measure              "synced from KR / KPI / ProgramTarget"
    FLOAT  Target               "synced from KR / KPI / ProgramTarget"
    TEXT   UOM                  "synced from KR / KPI / ProgramTarget"
    TEXT   ParentTargetID   FK "→ TargetRollup (nullable)"
    TEXT   OwnerID          FK "→ User"
  }

  subgraph "Strategy"
    Objective {
      TEXT   ObjectiveID      PK
      TEXT   Objective
      TEXT   Description
      TEXT   TeamIDs              "array of Team IDs"
      TEXT   OwnerID          FK "→ User (Team Lead)"
      TEXT   FiscalPeriod         "multi-select"
      DATE   StartDate            "derived from FiscalPeriod"
      DATE   EndDate              "derived from FiscalPeriod"
    }
    KR {
      TEXT   KRID             PK
      TEXT   ObjectiveID      FK "→ Objective"
      TEXT   Measure
      FLOAT  Target
      TEXT   UOM
      TEXT   TeamIDs              "array of Team IDs"
      TEXT   OwnerID          FK "→ User (Team Lead)"
    }
    KPI {
      TEXT   KPIID            PK
      TEXT   InitiativeID     FK "→ Initiative"
      TEXT   Measure
      FLOAT  Target
      TEXT   UOM
      TEXT   TeamIDs              "array of Team IDs"
      TEXT   OwnerID          FK "→ User (Team Lead)"
    }
    Initiative {
      TEXT   InitiativeID          PK
      TEXT   ObjectiveID           FK "→ Objective (nullable)"
      TEXT   InitiativeName
      TEXT   Description
      TEXT   InitiativeType       FK "→ InitiativeType"
      TEXT   InitiativeSubType    FK "→ InitiativeSubType"
      TEXT   Priority
      TEXT   TeamIDs                   "array of Team IDs"
      TEXT   OwnerID               FK "→ User (Team Lead)"
      TEXT   FiscalPeriod              "multi-select"
      DATE   LaunchDate
      DATE   EndDate                   "derived from FiscalPeriod"
      TEXT   Collaborators
      TEXT   Status                    "Draft | Active | Completed | Cancelled"
      BOOL   Active
      TEXT   ApprovalStatus            "Pending | Approved | Rejected"
      TEXT   LaunchQtr                 "derived from LaunchDate if available"
      BOOL   Evergreen
      TEXT   Region
      TEXT   SubRegion
      TEXT   Country
      TEXT   City
      TEXT   TargetPersona
      TEXT   TargetSegment
      TEXT   TargetIndustry
      DECIMAL BudgetPlanned
      DECIMAL TotalSpend
      BOOL   IsEvent
      TEXT   SponsorshipLevel
      TEXT   Tags
      TEXT   Notes
      TEXT   CustomerAccounts
      TEXT   PartnerAccounts
    }
    Objective ||--o{ KR : "breaks down into"
    Objective ||--o{ Initiative : "motivates"
    Initiative ||--o{ KPI : "measured by"
  end

  subgraph "Program Plan"
    Program {
      TEXT   ProgramID        PK
      TEXT   ProgramName
      TEXT   ProgramGroup
      TEXT   ProgramType
      TEXT   ProgramSubType
      TEXT   Description
      TEXT   Priority
      BOOL   ProgramTier
      TEXT   OwnerID          FK "→ User"
      TEXT   TeamID           FK "→ Team (lookup from OwnerID)"
      TEXT   Status               "Draft | Active | Completed | Cancelled"
      BOOL   Active
      TEXT   ApprovalStatus       "Pending | Approved | Rejected"
      DATE   LaunchDate
      TEXT   LaunchQtr            "derived from LaunchDate if available"
      DATE   EventDate
      DATE   EndDate
      BOOL   Evergreen
      TEXT   Region
      TEXT   SubRegion
      TEXT   Country              FK "→ Country"
      TEXT   City
      TEXT   Goals
      TEXT   Initiatives
      TEXT   TargetPersona
      TEXT   TargetSegment
      TEXT   TargetIndustry
      DECIMAL BudgetPlanned
      DECIMAL TotalSpend
      BOOL   IsEvent
      TEXT   Venue
      TEXT   SponsorshipLevel
      TEXT   TypeCode             FK "→ ProgramType"
      TEXT   SubTypeCode          FK "→ ProgramSubType"
      TEXT   Tags
      TEXT   CustomerAccounts
      TEXT   PartnerAccounts
    }
    ProgramTarget {
      TEXT   ProgramTargetID      PK
      TEXT   ProgramID            FK "→ Program"
      TEXT   Measure
      FLOAT  Target
      TEXT   UOM
      TEXT   OwnerID              FK "→ User (inherited from Program)"
    }
    Program ||--o{ ProgramTarget : "targets"
  end


  Attachment {
    TEXT   AttachmentID     PK
    TEXT   ProgramID        FK "→ Program (nullable)"
    TEXT   BOMID            FK "→ BOM (nullable)"
    TEXT   ObjectiveID      FK "→ Objective (nullable)"
    TEXT   OwnerID          FK "→ User"
  }

  subgraph "Spend Management"
    Spend {
      TEXT   SpendID               PK
      TEXT   ProgramID             FK, UK "→ Program (nullable)"
      TEXT   InitiativeID          FK, UK "→ Initiative (nullable)"
      TEXT   BOMAssetID            FK, UK "→ BOMAsset (nullable)"
      TEXT   SpendShortDescription
      TEXT   OwnerID               FK "→ User"
      TEXT   PlanItem
      TEXT   PlanItemType          "Program | Initiative | BOMAsset"
      DATE   LaunchDate
      TEXT   LaunchQtr
      DECIMAL SumOfDraft
      DECIMAL SumOfPlanned
      DECIMAL SumOfSubmitted
      DECIMAL SumOfCommitted
      DECIMAL SumOfInvoiced
    }
    SpendForecast {
      TEXT   SpendForecastID   PK
      TEXT   SpendID           FK "→ Spend"
      TEXT   FiscalMonth
      TEXT   FiscalYear
      TEXT   OwnerID           FK "→ User"
    }
    Spend ||--o{ SpendForecast : "forecasts"
    Spend ||--o{ PurchaseRequest : "raises"

    subgraph "Purchase"
      PurchaseRequest {
        TEXT   PurchaseRequestID PK
        TEXT   SpendID           FK "→ Spend"
        TEXT   SupplierID        FK "→ Supplier"
        TEXT   SpendCategoryID   FK "→ SpendCategory"
        TEXT   Status                "Draft | Submitted | Approved | Rejected | Committed | Invoiced"
        TEXT   PurchaseDescription
        TEXT   SpendType
        TEXT   Requestor
        TEXT   OwnerID           FK "→ User"
        TEXT   TeamID            FK "→ Team"
        TEXT   BudgetSponsor
        TEXT   CostCenter
        TEXT   ChargeString
        DATE   StartDate
        DATE   EndDate
        DECIMAL TotalAmount
        TEXT   PRNumber
        TEXT   PONumber
      }
      PurchaseRequestLineItem {
        TEXT   LineItemID        PK
        TEXT   PurchaseRequestID FK "→ PurchaseRequest"
        TEXT   SpendCategoryID   FK "→ SpendCategory"
        INT    SequenceNumber
        TEXT   Description
        DECIMAL Amount
        TEXT   OwnerID           FK "→ User"
      }
      PurchaseRequestAllocation {
        TEXT   AllocationID      PK
        TEXT   PurchaseRequestID FK "→ PurchaseRequest"
        TEXT   LineItemID        FK "→ PurchaseRequestLineItem (nullable)"
        DECIMAL AllocatedAmount
        TEXT   OwnerID           FK "→ User"
      }
      ProcurementDocument {
        TEXT   DocumentID        PK
        TEXT   PurchaseRequestID FK "→ PurchaseRequest"
        TEXT   DocumentType          "SOW | PO | Invoice | Contract | Other"
        TEXT   DocumentReference
        DATE   DocumentDate
        TEXT   OwnerID           FK "→ User"
      }
      Supplier {
        TEXT   SupplierID        PK
        TEXT   Name
        TEXT   ContactEmail
        TEXT   Country
        TEXT   OwnerID           FK "→ User"
      }
      PurchaseRequest ||--o{ PurchaseRequestLineItem : "itemizes"
      PurchaseRequest ||--o{ PurchaseRequestAllocation : "allocates to"
      PurchaseRequest ||--o{ ProcurementDocument : "documents"
      PurchaseRequest }o--|| Supplier : "sourced from"
    end
  end

  subgraph "Budget"
    BudgetEnvelope {
      TEXT   BudgetEnvelopeID    PK
      TEXT   Name
      TEXT   TeamID              FK "→ Team"
      TEXT   ParentEnvelopeID   FK "→ BudgetEnvelope (nullable)"
      DECIMAL PlannedAmount
      DECIMAL ReleasedAmount
      DECIMAL CommittedAmount
      DECIMAL ActualAmount
      TEXT   OwnerID             FK "→ User"
    }
    BudgetTransaction {
      TEXT   TransactionID           PK
      TEXT   BudgetEnvelopeID        FK "→ BudgetEnvelope"
      TEXT   CounterpartyEnvelopeID  FK "→ BudgetEnvelope (nullable)"
      TEXT   PurchaseRequestID       FK "→ PurchaseRequest (nullable)"
      TEXT   BudgetRequestID         FK "→ BudgetRequest (nullable)"
      TEXT   TransactionType             "Spend Commitment | Transfer In | Transfer Out | Adjustment"
      TEXT   LedgerType                  "Debit | Credit"
      DECIMAL Amount
      DATE   TransactionDate
      TEXT   OwnerID                 FK "→ User"
    }
    BudgetRequest {
      TEXT   BudgetRequestID      PK
      TEXT   RequestingEnvelopeID FK "→ BudgetEnvelope"
      DECIMAL RequestedAmount
      TEXT   Status                   "Pending | Approved | Rejected"
      TEXT   OwnerID              FK "→ User"
    }
    BudgetEnvelope |o--o{ BudgetEnvelope : "rolls up to"
    BudgetEnvelope ||--o{ BudgetTransaction : "records"
    BudgetEnvelope ||--o{ BudgetRequest : "requests from"
  end

  subgraph "Bill-Of-Material"
    BOMTemplate {
      TEXT   BOMTemplateID    PK
      TEXT   TemplateName
      TEXT   Description
      TEXT   OwnerID          FK "→ User"
    }
    BOM {
      TEXT     BOMID                PK
      TEXT     BOMName              "Auto-set on create: BOM: [Program Name or Initiative Name]"
      INT      SortOrder
      datetime CreatedAt
      TEXT     ProgramID            FK "→ Program (nullable)"
      TEXT     InitiativeID         FK "→ Initiative (nullable)"
      TEXT     AttachmentID         FK "→ Attachment (nullable)"
      TEXT     OwnerID              FK "→ User"
    }
    BOMAsset {
      TEXT   BOMAssetID        PK
      TEXT   BOMID              FK "→ BOM"
      TEXT   TaxonomyID         FK "→ Taxonomy (AssetType level, shared with the DAM; rolls up to AssetCategory and AssetGroup)"
      TEXT   AssetID            FK "→ Asset (nullable; null when non-DAM asset)"
      TEXT   AdID               FK "→ Ad (nullable; Ads only. Tells which content set and network this BOM asset is)"
      TEXT   PostID             FK "→ SocialPost (nullable; Social Posts only. Tells which SocialPostContentSet and Network this BOM asset is)"
      TEXT   EventID            FK "→ Event (nullable; Campaign Offer > Event types)"
      TEXT   SFDCCampaignID     FK "→ SalesforceCampaign (nullable; System > Salesforce Campaigns)"
      TEXT   HubspotCampaignID  FK "→ HubspotCampaign (nullable; System > Hubspot Campaigns)"
      TEXT   AssetName             "Only for BOM assets that have no DAM asset (Event, Salesforce Campaign, Hubspot Campaign types) and for blueprints. Otherwise read Asset.Title"
      BOOL   IsBlueprint
      TEXT   OwnerID            FK "→ User"
    }
    BOMTemplateProgramType {
      TEXT   BOMTemplateID   PK, FK "→ BOMTemplate"
      TEXT   TypeCode        PK, FK "→ ProgramType"
    }
    PostDelivery {
      TEXT   PostDeliveryID        PK
      TEXT   PostID                FK, UK "→ SocialPost (DAM)"
      TEXT   Status                   "Draft | In review | Scheduled | Published | Failed"
      DATE   FinalDeliveryDate        "admin-set schedule"
      DATE   PublishedDate            "actual publish timestamp"
      TEXT   ReferenceKey
    }
    AdDelivery {
      TEXT   AdID                  PK, FK "→ Ad (DAM); one delivery row per ad"
      TEXT   AdAccountID           FK "→ AdAccount"
      TEXT   Status                   "Draft | In review | Scheduled | Live | Paused | Rejected | Failed | Completed | Cancelled"
      TEXT   ReviewStatus             "in_review | approved | rejected | with_issues"
      TEXT   ConfiguredStatus         "ACTIVE | PAUSED (the ad's own switch; Zernio AdActivationStatus)"
      TEXT   LaunchShape              "standalone | multi-creative | attach"
      TEXT   AttachAdSetID            "PlatformAdSetId to attach to (nullable; attach shape)"
      DECIMAL SubmittedBudgetAmount   "Per-ad budget at submission (standalone or multi-creative)"
      TEXT   BudgetType               "Daily | Lifetime"
      TEXT   Currency
      DATETIME StartsAt
      DATETIME EndsAt
      TEXT   TargetingSnapshotJSON    "Accepted targeting at submission"
      TEXT   IdempotencyKey        UK "Retry-safe launch; validateOnly runs validate the same request without persisting"
      TEXT   ZernioAdID
      TEXT   PlatformAdAccountID      "Zernio Ad response mirrors; read-only"
      TEXT   PlatformCampaignID       "Auto-created by Zernio or supplied"
      TEXT   PlatformAdSetID          "Nullable: attach shape, or a later ad joining the set"
      TEXT   PlatformAdID
      TEXT   CampaignName             "Zernio response mirror"
      TEXT   AdSetName                "Zernio response mirror"
      BOOL   IsExternal               "Markefin-created vs synced from the platform"
      DATETIME LaunchedAt
      DATETIME LastSyncedAt
    }
    AdDeliveryRequest {
      TEXT   AdDeliveryRequestID   PK
      TEXT   AdID                  FK, UK "→ Ad (DAM); the ad carries its own creative, kind and network"
      TEXT   RequestName
      DATE   ProposedDeliveryDate     "requester preference"
      TEXT   ProposedDeliveryTime
      TEXT   TimeZone
      TEXT   Flexibility              "Flexible | Somewhat | Fixed"
      TEXT   Notes
      TEXT   SubmittedByUserID    FK "→ User"
    }
    PostDeliveryRequest {
      TEXT   PostDeliveryRequestID PK
      TEXT   PostID                FK, UK "→ SocialPost (DAM); the post tells which content set it belongs to"
      TEXT   RequestName
      DATE   ProposedDeliveryDate     "requester preference"
      TEXT   ProposedDeliveryTime
      TEXT   TimeZone
      TEXT   Flexibility              "Flexible | Somewhat | Fixed"
      TEXT   Notes
      TEXT   SubmittedByUserID    FK "→ User"
    }
    BOM ||--o{ BOMAsset : "includes"
    BOMTemplate ||--o{ BOMTemplateProgramType : "typed by"
  end

  subgraph "Events"
    Event {
      TEXT     EventID          PK
      TEXT     ProgramID        FK, UK "→ Program"
      TEXT     Name
      DATE     StartDate
      DATE     EndDate
      TEXT     Type                 "In-Person Event | Webinar | Online Event | Video on Demand"
      TEXT     OwnerID          FK "→ User"
      TEXT     SharedWith
      INT      RowHeight            "agenda row height in px"
      TEXT     HeaderMode           "track | location"
      TEXT     Timezone             "online only"
      TEXT     CreatedByUserID  FK "→ User"
    }
    Venue {
      TEXT     VenueID          PK
      TEXT     EventID          FK "→ Event"
      TEXT     Name
      TEXT     Address
      TEXT     CreatedByUserID  FK "→ User"
    }
    Track {
      TEXT     TrackID          PK
      TEXT     EventID          FK "→ Event"
      TEXT     Name
      TEXT     Description
      TEXT     Color
      TEXT     CreatedByUserID  FK "→ User"
    }
    Talk {
      TEXT     TalkID           PK
      TEXT     EventID          FK "→ Event"
      TEXT     Title
      TEXT     Code
      TEXT     Description
      TEXT     Type                 "talk | break | blocker"
      BOOL     Scheduled            "on grid or in sidebar"
      INT      DayIndex             "0-based day"
      TEXT     StartTime            "HH:mm format"
      TEXT     EndTime              "HH:mm format"
      TEXT     TrackID          FK "→ Track"
      TEXT     LocationID       FK "→ Location (nullable)"
      TEXT     SpeakerIDs           "array → Speaker"
      TEXT     CreatedByUserID  FK "→ User"
    }
    LocationAssignment {
      TEXT     LocationAssignmentID PK
      TEXT     EventID          FK "→ Event (nullable)"
      TEXT     LocationID       FK "→ Location"
      TEXT     TrackID          FK "→ Track"
      INT      DayIndex             "0-based day"
      BOOL     FullDay              "all-day assignment"
      TEXT     StartTime
      TEXT     EndTime
      TEXT     CreatedByUserID  FK "→ User"
    }
    CFPForm {
      TEXT     CFPFormID        PK
      TEXT     EventID          FK "→ Event"
      TEXT     Title
      TEXT     Description
      TEXT     EnabledFields        "active field IDs array"
      TEXT     Fields               "field definitions array"
      TEXT     CustomFields         "user-added fields array"
      TEXT     ConfirmationMessage
      BOOL     ConfirmationEmail
      DATE     StartDate
      DATE     EndDate
      INT      MaxSubmissions
      BOOL     RequireApproval
      BOOL     Active
      TEXT     DeactivationMessage
      TEXT     CreatedByUserID  FK "→ User"
    }
    Location {
      TEXT     LocationID       PK
      TEXT     Name
      TEXT     VenueID          FK "→ Venue"
      TEXT     LocationType         "room | booth | service-point | other"
      TEXT     Floor
      TEXT     FloorSpace
      TEXT     FloorSpaceUnit       "sqm | sqft"
      TEXT     Layout               "classroom | theatre | boardroom | u-shape | banquet | lounge | cocktail | custom"
      INT      MaxCapacity
      TEXT     CreatedByUserID  FK "→ User"
    }
    Equipment {
      TEXT     EquipmentID      PK
      TEXT     LocationID       FK "→ Location"
      TEXT     Name
      TEXT     Category
      TEXT     SubCategory
      TEXT     Description
      DECIMAL  Cost
      INT      Quantity
      TEXT     Notes
      TEXT     CreatedByUserID  FK "→ User"
    }
    DutyPersonnel {
      TEXT     DutyPersonnelID  PK
      TEXT     LocationID       FK "→ Location"
      TEXT     Name
      TEXT     StartTime
      TEXT     EndTime
      TEXT     Duration
      TEXT     CreatedByUserID  FK "→ User"
    }
    FloorPlan {
      TEXT     FloorPlanID      PK
      TEXT     LocationID       FK, UK "→ Location"
      TEXT     FPObjects            "placed items array"
      TEXT     FPWalls              "wall segments array"
      TEXT     FPDoors              "door placements array"
      TEXT     FPDiagramData        "dxDiagram.export() JSON string"
      TEXT     CreatedByUserID  FK "→ User"
    }
    Speaker {
      TEXT     SpeakerID        PK
      TEXT     FirstName
      TEXT     LastName
      TEXT     Company
      TEXT     Title
      TEXT     Bio
      TEXT     Photo                "URL path to upload"
      TEXT     Social               "linkedin | facebook | instagram | youtube | tiktok | x | website"
      TEXT     Specialization       "tag array"
      TEXT     CreatedByUserID  FK "→ User"
    }
    CFPSubmission {
      TEXT     CFPSubmissionID  PK
      TEXT     CFPFormID        FK "→ CFPForm"
      TEXT     Data                 "submitted field values"
      TEXT     Status               "pending | approved | rejected"
      DATE     SubmittedAt
      TEXT     CreatedByUserID  FK "→ User"
    }
    FPObject {
      TEXT     FPObjectID       PK
      TEXT     FloorPlanID      FK "→ FloorPlan"
      TEXT     Type                 "shape type from 336 custom shapes"
      TEXT     Label
      INT      X
      INT      Y
      INT      W
      INT      H
      TEXT     Color
      TEXT     Icon
      TEXT     CreatedByUserID  FK "→ User"
    }
    FPWall {
      TEXT     FPWallID         PK
      TEXT     FloorPlanID      FK "→ FloorPlan"
      INT      X1
      INT      Y1
      INT      X2
      INT      Y2
      TEXT     CreatedByUserID  FK "→ User"
    }
    Event ||--o{ Venue : "has (in-person)"
    Event ||--o{ Track : "contains"
    Event ||--o{ Talk : "contains"
    Event ||--o{ LocationAssignment : "schedules"
    Event ||--o{ CFPForm : "publishes"
    Venue ||--o{ Location : "contains"
    Location ||--o{ Equipment : "stocks"
    Location ||--o{ DutyPersonnel : "staffs"
    Location |o--o| FloorPlan : "has layout"
    FloorPlan ||--o{ FPObject : "contains"
    FloorPlan ||--o{ FPWall : "defines"
    Talk }o--o| Track : "assigned to"
    Talk }o--o| Location : "located in"
    LocationAssignment }o--|| Location : "maps"
    LocationAssignment }o--|| Track : "to"
    CFPForm ||--o{ CFPSubmission : "receives"
  end

  subgraph "Salesforce"
    SalesforceCampaign {
      TEXT     SFDCCampaignID       PK
      TEXT     ProgramID            FK "→ Program"
      TEXT     OwnerID              FK "→ User"
      TEXT     CampaignName
      TEXT     RespondentType           "Picklist"
      TEXT     CampaignOwner            "Lookup(User)"
      TEXT     CampaignRecordType       "Record Type"
      TEXT     CreatedBy                "Lookup(User)"
      TEXT     Description              "Text Area (Long)"
      DATE     StartDate
      DATE     EndDate
      FLOAT    ExpectedResponsePct      "Percent"
      DECIMAL  ExpectedRevenue          "Currency"
      TEXT     LastModifiedBy           "Lookup(User)"
      TEXT     ParentCampaignID     FK "→ SalesforceCampaign (nullable)"
      TEXT     Type                     "Picklist"
      TEXT     SubType                  "Picklist"
      TEXT     TargetAudience
      TEXT     Persona                  "Picklist"
      TEXT     Geography                "Picklist"
      DATE     EventDate
      TEXT     BusinessUnit             "Picklist"
      TEXT     GoalObjective            "Text Area"
      TEXT     CustomerSegment          "Picklist"
      TEXT     Industry                 "Picklist"
      DECIMAL  ActualCost               "Currency"
      DECIMAL  BudgetedCost             "Currency"
      TEXT     CampaignCurrency         "Picklist"
      TEXT     CampaignStage            "Picklist"
      TEXT     Status
      BOOL     Active
    }
    SalesforceCampaign |o--o{ SalesforceCampaign : "rolls up to"
  end

  subgraph "Hubspot"
    HubspotCampaign {
      TEXT   HubspotCampaignID  PK
      TEXT   ProgramID          FK "→ Program"
    }
  end

  subgraph "Access Management"
    Team {
      TEXT   TeamID         PK
      TEXT   TeamName
      TEXT   TeamType                  "Reporting | Project | Vendor"
      TEXT   VendorTeamAllowedDomains     "nullable"
      TEXT   ParentTeamID          FK "→ Team (nullable)"
      INT    Level                     "0-10"
      TEXT   OwnerID               FK "→ User"
    }
    User {
      TEXT      UserID       PK
      TEXT      Email        UK
      TEXT      DisplayName
      TEXT      Role
      TEXT      TeamID       FK "→ Team (nullable)"
      TEXT      UserType        "Internal | Supplier"
      TEXT      Company         "Suppliers only (nullable)"
      datetime  CreatedAt
      BOOL      IsActive
    }
    Role {
      TEXT   RoleID       PK
      TEXT   RoleName         "Team Lead | Team Admin | Team Budget Admin | Team Member"
      TEXT   Description
    }
    UserRole {
      TEXT   UserRoleID   PK
      TEXT   UserID       FK "→ User"
      TEXT   RoleID       FK "→ Role"
      TEXT   TeamID       FK "→ Team"
    }
    Permission {
      TEXT   PermissionID PK
      TEXT   RoleID       FK "→ Role"
      TEXT   Resource
      TEXT   Action           "Read | Write | Delete | Admin"
    }
    Team |o--o{ Team : "rolls up to"
    Team ||--o{ User : "belongs to"
    User ||--o{ UserRole : "assigned"
    Role ||--o{ UserRole : "grants"
    Team ||--o{ UserRole : "scoped to"
    Role ||--o{ Permission : "defines"
  end

  subgraph "Settings"
    ProgramType {
      TEXT   TypeCode          PK
      TEXT   TypeName
      INT    Priority
    }
    ProgramSubType {
      TEXT   SubTypeCode       PK
      TEXT   TypeCode          FK "→ ProgramType"
      TEXT   SubTypeName
      INT    Priority
    }
    SpendCategory {
      TEXT   SpendCategoryID   PK
      TEXT   CategoryName
      TEXT   ParentCategoryID  FK "→ SpendCategory (nullable; self-ref)"
      TEXT   OwnerID           FK "→ User"
    }
    Measurement {
      TEXT   MeasureCategory   PK "Revenue Impact | Lead Generation | Responses | Publicity | Social Media Engagements | Email Performance | Customer Success | Brand Equity | Milestone | Cost Efficiency"
      TEXT   Measure           PK
      TEXT   DataType              "Float | Integer | Boolean"
      TEXT   DisplaySymbol         "$ | %"
      TEXT   SymbolPosition        "Prefix | Suffix"
      TEXT   Visualization         "Number | Linear/Circular Gauge | Scale | Numeric | Pass/Fail Icon"
      TEXT   MarkefinNotes
    }
    TimeZone {
      TEXT   TimeZoneCode      PK
      TEXT   Regions               "Africa | Americas | Antarctica | Asia | Atlantic Ocean | Australia | Indian Ocean | Pacific Ocean"
      TEXT   TimeZoneName
      TEXT   CodeInSummer
      TEXT   NameInSummer
      TEXT   CountriesRegions
      TEXT   UTCOffset
    }
    Country {
      TEXT   ISOCode2          PK
      TEXT   CountryName
      TEXT   DialingCode
      TEXT   ISOCode3
      TEXT   SubRegionCode     FK "→ SubRegion"
    }
    Region {
      TEXT   RegionCode        PK
      TEXT   RegionName
      TEXT   Description
    }
    SubRegion {
      TEXT   SubRegionCode     PK
      TEXT   SubRegionName
      TEXT   Description
      TEXT   RegionCode        FK "→ Region"
    }
    InitiativeType {
      TEXT   TypeCode          PK
      TEXT   TypeName
      INT    Priority
    }
    InitiativeSubType {
      TEXT   SubTypeCode       PK
      TEXT   TypeCode          FK "→ InitiativeType"
      TEXT   SubTypeName
      INT    Priority
    }
    Workspace {
      TEXT   WorkspaceID          PK
      TEXT   Name
      TEXT   ZernioAPIKeyRef          "Vault reference; BYOK secret never stored here"
      TEXT   ZernioProfileID          "Tenant Zernio profile; null = Default"
      BOOL   ApprovalsEnabled         "Default true"
      TEXT   Status
      TEXT   OwnerID              FK "→ User"
    }
    Connection {
      TEXT   ConnectionID         PK
      TEXT   WorkspaceID          FK "→ Workspace"
      TEXT   OfferingCode         FK  "→ MarkefinAdAndSocialOffering (Zernio networks only)"
      TEXT   ZernioAccountID
      TEXT   IdentityLabel
      TEXT   Status                   "Active | Error | Disconnected"
      TEXT   HealthJSON
    }
    AdAccount {
      TEXT   AdAccountID          PK
      TEXT   ConnectionID         FK "→ Connection"
      TEXT   PlatformAdAccountID
      TEXT   Name
      TEXT   Currency
      TEXT   TimeZone
      DECIMAL MinDailyBudget
      BOOL   Selectable
    }
    ProgramType ||--o{ ProgramSubType : "classifies"
    SpendCategory ||--o{ SpendCategory : "rolls up to"
    Region ||--o{ SubRegion : "contains"
    SubRegion ||--o{ Country : "contains"
    InitiativeType ||--o{ InitiativeSubType : "classifies"
    MarkefinAdAndSocialOffering {
      TEXT  OfferingCode         PK  "LinkedIn | Facebook | Instagram | X | Reddit | Google | Microsoft Bing | ChatGPT"
      TEXT  Name
      TEXT  Type                     "Social | Search and Display | LLM"
      BOOL  OrganicSocial            "Offered for Social Posts (built by Markefin)"
      BOOL  PaidSocial               "Offered for Paid Social Ads (Zernio)"
      BOOL  SearchAds                "Zernio"
      BOOL  DisplayAds               "Zernio"
      BOOL  ConversationalAds        "Zernio"
      TEXT      Notes
      BOOL      IsActive
      datetime  CreatedAt
    }
    SocialIntegration {
      TEXT      SocialIntegrationID  PK  "One connected account on one network; Social Posts only, not Zernio"
      TEXT      OfferingCode         FK  "→ MarkefinAdAndSocialOffering (OrganicSocial = true only)"
      TEXT      ExternalAccountID        "The network's own ID for the account or page"
      TEXT      Username
      TEXT      DisplayName
      TEXT      AvatarUri
      TEXT      CredentialRef            "Vault reference; token never stored here"
      TEXT      Status                   "Active | Disconnected | Needs reconnect"
      datetime  TokenExpiresAt
      datetime  CreatedAt
      TEXT      CreatedByUserID       FK  "→ User"
    }
    Workspace ||--o{ Connection : "connects"
    Connection ||--o{ AdAccount : "exposes"
    MarkefinAdAndSocialOffering ||--o{ SocialIntegration : "connected as"
  end

  TargetRollup |o--o{ TargetRollup : "parent of"

  subgraph "DAM"
    Taxonomy {
      TEXT      TaxonomyID        PK
      TEXT      ParentTaxonomyID  FK "→ Taxonomy (nullable)"
      INT       Level                "1 AssetGroup | 2 AssetCategory | 3 AssetType | 4 AssetSubType"
      TEXT      Code              UK "Editable, unique (enforced by API)"
      TEXT      Name
      TEXT      Description
      INT       SortOrder
      datetime  CreatedAt
      BOOL      IsActive
      TEXT      CreatedByUserID    FK "→ User"
    }
    Asset {
      TEXT      AssetID          PK
      TEXT      Title
      TEXT      Description
      TEXT      MediaType           "Image | Video | Document | Email | Audio | Other (detected from file)"
      TEXT      FileFormat          "Detected from file, e.g. PNG | MP4 | PDF"
      TEXT      StorageUri          "Current file (nullable)"
      TEXT      AssetStatus         "DAM asset readiness for other marketers: Draft | Pending approval | Published | Retired. Never delivery status (that lives on the BOM)"
      TEXT      Visibility          "Internal | External"
      TEXT      TeamOwnershipID  FK "→ Team"
      TEXT      OwnerUserID      FK "→ User (nullable)"
      datetime  UpdatedAt
      datetime  CreatedAt
      BOOL      IsActive
      TEXT      CreatedByUserID   FK "→ User"
    }
    AssetVersion {
      TEXT      AssetVersionID    PK
      TEXT      AssetID           FK "→ Asset"
      INT       VersionNo            "Unique per Asset"
      TEXT      FileName
      TEXT      StorageUri
      TEXT      FileFormat
      INT       FileSize             "Bytes (nullable)"
      TEXT      UploadedByUserID  FK "→ User"
      datetime  UploadedAt
      BOOL      IsCurrent            "One current version per Asset"
    }
    AssetTaxonomyAssignment {
      TEXT      AssetTaxonomyAssignmentID  PK
      TEXT      AssetID                    FK "→ Asset"
      TEXT      TaxonomyID                 FK "→ Taxonomy"
      BOOL      IsPrimary                     "One primary per Asset"
      TEXT      Source                        "Human | AI"
      FLOAT     ConfidenceScore               "AI only (nullable)"
      BOOL      IsReviewed
      datetime  CreatedAt
      TEXT      CreatedByUserID             FK "→ User"
    }
    Facet {
      TEXT      FacetID         PK
      TEXT      Code            UK
      TEXT      Name
      TEXT      Description
      TEXT      DataType           "List | Text | Date | Color"
      BOOL      IsMultiSelect
      BOOL      IsHierarchical
      BOOL      IsRequired
      INT       SortOrder
      datetime  CreatedAt
      BOOL      IsActive
      TEXT      CreatedByUserID  FK "→ User"
    }
    FacetValue {
      TEXT      FacetValueID        PK
      TEXT      FacetID             FK "→ Facet"
      TEXT      ParentFacetValueID  FK "→ FacetValue (nullable)"
      TEXT      Code                UK "Unique within Facet"
      TEXT      Label
      INT       SortOrder
      datetime  CreatedAt
      BOOL      IsActive
      TEXT      CreatedByUserID      FK "→ User"
    }
    AssetFacetValue {
      TEXT      AssetFacetValueID  PK
      TEXT      AssetID            FK "→ Asset"
      TEXT      FacetValueID       FK "→ FacetValue"
      TEXT      Source                "Human | AI"
      FLOAT     ConfidenceScore       "AI only (nullable)"
      BOOL      IsReviewed
      datetime  CreatedAt
      TEXT      CreatedByUserID     FK "→ User"
    }
    WorkflowSetting {
      TEXT      SettingID        PK
      TEXT      Name
      TEXT      Value
      datetime  UpdatedAt
      TEXT      UpdatedByUserID  FK "→ User (nullable)"
    }
    Collection {
      TEXT      CollectionID     PK
      TEXT      BOMID            FK, UK "→ BOM (nullable; set when this is the collection of a BOM; empty for a standalone collection)"
      TEXT      Name
      TEXT      Description
      TEXT      Status
      TEXT      TeamOwnershipID  FK "→ Team"
      datetime  CreatedAt
      BOOL      IsActive
      TEXT      CreatedByUserID   FK "→ User"
    }
    CollectionAsset {
      TEXT      CollectionAssetID  PK
      TEXT      CollectionID       FK "→ Collection"
      TEXT      AssetID            FK "→ Asset; name and description read live from Asset"
      INT       SortOrder
      TEXT      Note
      datetime  CreatedAt
      TEXT      CreatedByUserID     FK "→ User"
    }
    AssetApproval {
      TEXT      AssetApprovalID   PK
      TEXT      AssetID           FK "→ Asset"
      TEXT      ApprovedByUserID  FK "→ User"
      datetime  ApprovedAt           "When it was approved"
      TEXT      Comment              "Optional"
    }
    ProductTaxonomy {
      TEXT      ProductTaxonomyID        PK
      TEXT      ParentProductTaxonomyID  FK "→ ProductTaxonomy (nullable; no parent = top of tree; max 5 deep)"
      TEXT      Code                     UK "Editable, unique"
      TEXT      Name
      TEXT      Description
      INT       SortOrder
      BOOL      IsActive                    "Inactive: not offered for new tagging, still valid on assets already tagged"
      datetime  CreatedAt
      TEXT      CreatedByUserID           FK "→ User"
    }
    AssetProductTaxonomyAssignment {
      TEXT      AssetProductTaxonomyAssignmentID  PK
      TEXT      AssetID                           FK "→ Asset"
      TEXT      ProductTaxonomyID                 FK "→ ProductTaxonomy (any level of tree)"
      TEXT      Source                               "Human | AI"
      FLOAT     ConfidenceScore                      "AI only (nullable)"
      BOOL      IsReviewed
      datetime  CreatedAt
      TEXT      CreatedByUserID                    FK "→ User"
    }
    subgraph "SocialPostAssetContent"
      SocialPostContentSet {
        TEXT      ContentSetID  PK  "Social Posts content shared by its posts; each ad kind gets its own table"
        TEXT      TeamID        FK "→ Team"
        TEXT      OwnerID       FK "→ User"
        TEXT      Caption
        TEXT      FirstComment
        TEXT      MediaJSON        "Images and videos held in the content: list of file, type, width, height, size. Not separate DAM assets"
        datetime  CreatedAt
        TEXT      CreatedByUserID  FK "→ User"
      }
      SocialPost {
        TEXT      PostID                PK  "One row per network the content set is for"
        TEXT      AssetID               FK, UK "→ Asset; the post is the DAM asset and carries the asset status, set by the status rules (not by posting)"
        TEXT      ContentSetID          FK "→ SocialPostContentSet"
        TEXT      OfferingCode          FK "→ MarkefinAdAndSocialOffering (the network); must have an Active SocialIntegration"
        TEXT      SocialIntegrationID   FK "→ SocialIntegration (nullable while the post is a draft)"
        TEXT      TeamID                FK "→ Team"
        TEXT      OwnerID               FK "→ User"
        datetime  CreatedAt
        TEXT      CreatedByUserID        FK "→ User"
      }
      Asset ||--o| SocialPost : "is a social post"
      SocialPostContentSet ||--o{ SocialPost : "shared creative across networks"
    end

    subgraph "AdAssetContent"
      PaidSocialAdContentSet {
        TEXT  ContentSetID  PK  "Paid Social Ads creative master, shared by its ads; each ad kind gets its own table"
        TEXT  TeamID        FK "→ Team"
        TEXT  OwnerID       FK "→ User"
        TEXT  Headline          "Limit varies by network (see network-specs-table.md)"
        TEXT  Body              "Primary text"
        TEXT  CallToAction      "Zernio CTA enum"
        TEXT  LinkURL           "Destination"
        TEXT  MediaJSON         "Images and videos held in the content: list of file, type, width, height, size. Not separate DAM assets"
        TEXT  LeadGenFormID  FK "→ LeadForm (nullable; lead_generation goal)"
      }
      SearchAdContentSet {
        TEXT  ContentSetID      PK  "Responsive Search Ads creative master; each ad kind gets its own table"
        TEXT  TeamID            FK "→ Team"
        TEXT  OwnerID           FK "→ User"
        TEXT  HeadlinesJSON         "Up to 15 headlines, 30 chars each on Google"
        TEXT  DescriptionsJSON      "Up to 4 descriptions, 90 chars each"
        TEXT  KeywordsJSON          "Final match keywords"
        TEXT  LinkURL               "Final URL"
        TEXT  PathFieldsJSON        "Display path fields"
      }
      DisplayAdContentSet {
        TEXT  ContentSetID   PK  "Responsive Display Ads creative master; each ad kind gets its own table"
        TEXT  TeamID         FK "→ Team"
        TEXT  OwnerID        FK "→ User"
        TEXT  Headline           "30 chars"
        TEXT  LongHeadline       "90 chars"
        TEXT  Description        "90 chars"
        TEXT  BusinessName       "25 chars"
        TEXT  ImagesJSON         "Logo and marketing image roles"
        TEXT  AspectRatio        "1.91:1 | 1:1 | landscape | square"
      }
      ConversationalAdContentSet {
        TEXT  ContentSetID  PK  "Conversational (LLM) ads creative master; each ad kind gets its own table"
        TEXT  TeamID        FK "→ Team"
        TEXT  OwnerID       FK "→ User"
        TEXT  Headline
        TEXT  Body              "Conversation opener"
        TEXT  CallToAction      "Zernio CTA enum"
        TEXT  LinkURL           "Destination"
      }
      Ad {
        TEXT  AdID          PK  "One row per ad; two ads may share a network"
        TEXT  AssetID       FK, UK "→ Asset; the ad is the DAM asset. Title: DAM.AssetTitle default per AssetType (Paid_Social_N, SEM_N, Display_Ad_N, Conversational_Ad_N); Description: the ad specs; AssetStatus: set by the status rules (not by launching)"
        TEXT  TeamID        FK "→ Team"
        TEXT  OwnerID       FK "→ User"
        TEXT  OfferingCode  FK  "→ MarkefinAdAndSocialOffering; the network. Must be offered for this ad kind"
        TEXT  AdKind            "PaidSocial | Conversational | SearchAds | DisplayAds; exactly one content set matches"
        TEXT  Goal              "Zernio campaign objective for this ad's launch, platform-dependent. NOT the Program objective"
        TEXT  PaidSocialContentSetID     FK "→ PaidSocialAdContentSet (AdKind=PaidSocial)"
        TEXT  SearchContentSetID         FK "→ SearchAdContentSet (AdKind=SearchAds)"
        TEXT  DisplayContentSetID        FK "→ DisplayAdContentSet (AdKind=DisplayAds)"
        TEXT  ConversationalContentSetID FK "→ ConversationalAdContentSet (AdKind=Conversational)"
        TEXT  Headline          "Per-ad override; null falls back to the content set"
        TEXT  LongHeadline      "Per-ad override; Google Display only"
        TEXT  Body              "Per-ad override; null falls back to the content set"
        TEXT  CallToAction      "Per-ad override; Zernio CTA enum"
        TEXT  LinkURL           "Per-ad override; tracking applied at launch"
        TEXT  BoostedPostID     FK "→ SocialPost (nullable; Zernio adType=boost promotes an organic post)"
        BOOL  AIGenerated
        BOOL  AIDisclosure      "Meta aiDisclosure"
      }
      Asset ||--o| Ad : "is an ad"
      PaidSocialAdContentSet ||--o{ Ad : "shared creative for paid social ads"
      SearchAdContentSet ||--o{ Ad : "shared creative for search ads"
      DisplayAdContentSet ||--o{ Ad : "shared creative for display ads"
      ConversationalAdContentSet ||--o{ Ad : "shared creative for conversational ads"
    end

    Taxonomy ||--o{ Taxonomy : "parent of"
    Asset ||--o{ AssetVersion : "has versions"
    Asset ||--o{ AssetTaxonomyAssignment : "classified by"
    Taxonomy ||--o{ AssetTaxonomyAssignment : "assigned to"
    Facet ||--o{ FacetValue : "has values"
    FacetValue ||--o{ FacetValue : "parent of"
    Asset ||--o{ AssetFacetValue : "tagged with"
    FacetValue ||--o{ AssetFacetValue : "applied to"
    Collection ||--o{ CollectionAsset : "contains"
    Asset ||--o{ CollectionAsset : "included in"
    Asset ||--o{ AssetApproval : "approved via"
    ProductTaxonomy ||--o{ ProductTaxonomy : "parent of"
    Asset ||--o{ AssetProductTaxonomyAssignment : "tagged with products"
    ProductTaxonomy ||--o{ AssetProductTaxonomyAssignment : "assigned to"
  end

  subgraph "Ad Publishing (Zernio)"
    LeadForm {
      TEXT   LeadFormID           PK
      TEXT   WorkspaceID          FK "→ Workspace"
      TEXT   ConnectionID         FK "→ Connection"
      TEXT   Platform                 "Meta | LinkedIn"
      TEXT   LeadGenFormID
      TEXT   FieldsJSON
      TEXT   PrivacyURL
      TEXT   Status
    }
    Lead {
      TEXT   LeadID               PK
      TEXT   LeadFormID           FK "→ LeadForm"
      TEXT   AdID                 FK "→ Ad (DAM); attributes the lead to the ad"
      DATETIME SubmittedAt
      TEXT   PayloadJSON              "Encrypted at rest"
      TEXT   RouteStatus              "Pending | Routed | Failed"
      DATETIME RoutedAt
    }
    MetricSnapshot {
      TEXT   MetricSnapshotID     PK
      TEXT   AdID                 FK "→ Ad (DAM)"
      DATE   MetricDate
      TEXT   MetricsJSON              "Spend, impressions, clicks, conversions"
      TEXT   Currency                 "Never blended across currencies"
      DATETIME SyncedAt
    }
    LeadForm ||--o{ Lead : "collects"
  end

  %% Cross-subgraph relationships
  Program |o--o| Spend : "drives"
  Initiative |o--o| Spend : "drives"
  BOMAsset |o--o| Spend : "drives"
  ProgramType ||--o{ Program : "classifies"
  ProgramSubType ||--o{ Program : "sub-classifies"
  Country ||--o{ Program : "locates"
  PurchaseRequest }o--|| SpendCategory : "categorized as"
  PurchaseRequestLineItem }o--|| SpendCategory : "categorized as"
  BudgetTransaction }o--o| PurchaseRequest : "settles"
  Program ||--o| Event : "manages as event"
  Program ||--o{ SalesforceCampaign : "syncs to"
  Program ||--o{ HubspotCampaign : "syncs to"
  Objective ||--o{ Attachment : "attaches"
  Program ||--o{ BOM : "deployed via"
  Initiative ||--o{ BOM : "deployed via"
  BOM ||--o{ Attachment : "attaches"
  BudgetEnvelope }|--|| Team : "owned by"
  ProgramType ||--o{ BOMTemplateProgramType : "applies to"
  BOMAsset }o--|| Taxonomy : "typed by (shared taxonomy)"
  BOMAsset }o--o| Asset : "primary DAM reference"
  BOMAsset }o--o| Ad : "ad: network and content set"
  BOMAsset }o--o| Event : "non-DAM: Campaign Offer events"
  BOMAsset }o--o| SalesforceCampaign : "non-DAM: Salesforce Campaigns"
  BOMAsset }o--o| HubspotCampaign : "non-DAM: Hubspot Campaigns"
  BOMAsset }o--o| SocialPost : "social post: network and content set"
  SocialPost ||--o| PostDelivery : "delivery facts stay on the BOM"
  SocialPost ||--o| PostDeliveryRequest : "submitted with"
  Ad ||--o| AdDelivery : "delivery facts stay on the BOM"
  Ad ||--o| AdDeliveryRequest : "submitted with"
  Ad ||--o{ MetricSnapshot : "reports"
  Ad ||--o{ Lead : "generates"
  Workspace ||--o{ LeadForm : "hosts"
  PaidSocialAdContentSet }o--o| LeadForm : "uses (lead_generation goal)"
  AdDelivery }o--|| AdAccount : "bills to"
  BOM ||--o| Collection : "has collection (created with the first DAM asset, or attached later)"
  SocialIntegration ||--o{ SocialPost : "posts through"
  MarkefinAdAndSocialOffering ||--o{ SocialPost : "network of"
  MarkefinAdAndSocialOffering ||--o{ Ad : "network of"
  MarkefinAdAndSocialOffering ||--o{ Connection : "network of"
  Objective |o--o{ TargetRollup : "paired in"
  KR |o--o{ TargetRollup : "paired in"
  Initiative |o--o{ TargetRollup : "paired in"
  KPI |o--o{ TargetRollup : "paired in"
  Program |o--o{ TargetRollup : "paired in"
  ProgramTarget |o--o{ TargetRollup : "paired in"
  InitiativeType ||--o{ Initiative : "classifies"
  InitiativeSubType ||--o{ Initiative : "sub-classifies"