Skip to content

Overview

I've successfully implemented optional video scripts with company-level settings and support for both long-form (YouTube) and short-form (YouTube Shorts, TikTok) content.

Changes Made

1. Schema Updates (backend/prisma/schema.prisma)

Company Model

  • Added: showScripts Boolean field (default: true)
    • Allows companies to enable/disable the script feature at the organization level
    • When disabled, videos can still be created, but scripts are optional
  • Added: Relation to VideoScript model

User Model

  • Added: Relation to VideoScript model for tracking user-created scripts

New VideoScript Model

  • Multi-tenant fields: companyId, userId (with proper relations)
  • Video Details: title, description
  • Platform & Type:
    • platform: "youtube", "youtube_shorts", "tiktok", "instagram_reels"
    • scriptType: "long_form" or "short_form"
  • Optional Script Content:
    • longFormScript (JSON, nullable): Structured script for YouTube videos
      json
      {
        "hook": "...",
        "intro": "...",
        "mainContent": [
          { "section": "...", "content": "...", "duration": "..." }
        ],
        "cta": "..."
      }
    • shortFormScript (JSON, nullable): Structured script for short-form content
      json
      {
        "hook": "...",
        "body": "...",
        "cta": "..."
      }
  • Video Metadata:
    • estimatedDuration
    • tags (array)
    • thumbnailPrompt
  • AI Tracking: aiProvider, modelName, promptUsed
  • Linked Content: linkedBlogId, campaignId
  • Status: "draft", "ready", "recorded", "published"
  • Proper indexes for performance optimization

2. Seed File Updates (backend/prisma/seed.ts)

Sample Data Created:

  1. Company 1 (TechFlow MSP) - Scripts enabled

    • Long-form YouTube video: "5 Critical Cybersecurity Mistakes Small Businesses Make"
    • Complete with structured script including hook, intro, 5 content sections, and CTA
  2. Company 2 (Wellness Chiropractic) - Scripts enabled

    • TikTok short: "Quick Desk Stretch to Relieve Back Pain" (30 seconds)
    • YouTube Shorts: "Myth Busting: Chiropractors Aren't Real Doctors" (45 seconds)
  3. Company 3 (Pawsitive Impact) - Scripts disabled (showScripts: false)

    • YouTube video: "Meet Luna: A Day in Service Dog Training"
    • Demonstrates how videos work when scripts are disabled (script content is null)

All sample videos include:

  • Platform-specific content
  • Appropriate script types
  • Tags and thumbnail prompts
  • AI generation metadata

3. Key Features Implemented

Optional Scripts

  • Scripts are optional at both the company level (via showScripts setting) and individual video level (nullable fields)

Company-Level Control

  • showScripts boolean in Company model
  • When false, the UI can hide script-related features
  • Videos can still be created without scripts

Long-Form Support (YouTube)

  • Structured with: hook, intro, main content sections (array), CTA
  • Each content section can have its own duration
  • Total estimated duration tracked

Short-Form Support (YouTube Shorts, TikTok)

  • Simpler structure: hook, body, CTA
  • Optimized for quick, engaging content
  • Platform-specific tags

Granular Permissions Ready

  • Individual videos can have scripts (not null) or no scripts (null)
  • User-level permissions will be handled separately per your requirements

Next Steps

1. Run Database Migration

⚠️ Important: You need to run the migration when DATABASE_URL is available.

bash
cd backend

# Option 1: If you have DATABASE_URL in environment
pnpm prisma migrate dev --name add_video_scripts_and_company_settings

# Option 2: Generate migration file for later deployment
pnpm prisma migrate dev --create-only --name add_video_scripts_and_company_settings

2. Verify Migration

bash
# Open Prisma Studio to see the new models
pnpm prisma studio

3. Seed Demo Data

bash
# Set NODE_ENV to development and run seed
NODE_ENV=development pnpm run seed

4. Frontend Integration

You'll need to:

  1. Update VideoIdea type to match the new schema
  2. Add company settings UI for showScripts toggle
  3. Create/update VideoStudio component to:
    • Check company's showScripts setting
    • Show/hide script editor based on setting
    • Support both long-form and short-form script editing
    • Allow creating videos without scripts
  4. Add script type selector (long_form vs short_form)
  5. Add platform selector (youtube, youtube_shorts, tiktok, instagram_reels)

Create these endpoints:

  • POST /api/videos - Create video with optional script
  • GET /api/videos - List videos (filtered by companyId)
  • GET /api/videos/:id - Get video details
  • PUT /api/videos/:id - Update video and script
  • DELETE /api/videos/:id - Delete video
  • POST /api/videos/:id/generate-script - AI-generate script
  • GET /api/company/settings - Get company settings (including showScripts)
  • PATCH /api/company/settings - Update company settings

Database Schema Summary

Company
  ├── showScripts: Boolean (default: true)
  └── videoScripts: VideoScript[]

User
  └── videoScripts: VideoScript[]

VideoScript
  ├── id: UUID
  ├── companyId: String (required)
  ├── userId: String (required)
  ├── title: String (required)
  ├── description: String? (optional)
  ├── platform: String (youtube|youtube_shorts|tiktok|instagram_reels)
  ├── scriptType: String (long_form|short_form)
  ├── longFormScript: JSON? (optional, for YouTube)
  ├── shortFormScript: JSON? (optional, for short-form content)
  ├── estimatedDuration: String?
  ├── tags: String[]
  ├── thumbnailPrompt: String?
  ├── aiProvider: String?
  ├── modelName: String?
  ├── promptUsed: String?
  ├── linkedBlogId: String?
  ├── campaignId: String?
  ├── status: String (draft|ready|recorded|published)
  ├── publishedAt: DateTime?
  ├── createdAt: DateTime
  └── updatedAt: DateTime

Sample Script Structures

Long-Form (YouTube)

json
{
  "hook": "Opening hook to grab attention",
  "intro": "Introduction to the topic",
  "mainContent": [
    {
      "section": "Section Title",
      "content": "Section content with details",
      "duration": "2:30"
    }
  ],
  "cta": "Call to action - subscribe, link, etc."
}

Short-Form (TikTok, YouTube Shorts)

json
{
  "hook": "Quick attention grabber",
  "body": "Main content in concise format",
  "cta": "Short CTA with hashtags"
}

Benefits

  1. Flexibility: Companies can choose whether to use scripts
  2. Platform-Specific: Different script structures for different platforms
  3. Optional: Videos can exist without scripts
  4. Multi-Tenant: Proper data isolation with companyId
  5. Scalable: Supports future platforms and script types
  6. AI-Ready: Fields for AI generation metadata
  7. Campaign Integration: Can link to campaigns and blog posts. AI scripts now ingest Campaign Brief/Goal for context-aware generation.

Status: ✅ Schema updated, seed file ready Remaining: Database migration needs to be run when DATABASE_URL is available

TendSocial Documentation