> ## Documentation Index
> Fetch the complete documentation index at: https://cona.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Update schema

# Database Schema Updates - Turbo Cache Management

This guide explains how to properly handle database schema changes in the CONA monorepo to ensure Turbo doesn't use stale cached builds.

## 🔧 **Auto-Invalidation Setup**

The project is now configured to automatically detect schema changes and invalidate Turbo cache when needed.

### **What Gets Tracked**

✅ **Schema file changes**: `packages/database/prisma/schema.prisma`\
✅ **Migration changes**: `packages/database/prisma/migrations/**`\
✅ **Generated Prisma client**: `.prisma/**` and `node_modules/.prisma/**`\
✅ **Database package builds**: Any change triggers dependent package rebuilds

## 🚀 **Quick Commands**

### **When You Update the Schema**

```bash theme={null}
# One command to handle cache invalidation:
pnpm schema:update
```

This command:

1. Regenerates the Prisma client with latest schema
2. Force rebuilds all dependent packages (`@cona/core`, `@cona/temporal-workflows`, etc.)

**For migrations, run separately:**

```bash theme={null}
# Apply database migrations first
pnpm db:migrate

# Then update caches and rebuild
pnpm schema:update
```

### **Alternative Commands**

```bash theme={null}
# Just apply migrations
pnpm db:migrate

# Just regenerate Prisma client
pnpm --filter=@cona/database generate

# Force rebuild everything
pnpm turbo build --force
```

## 🎯 **Automatic Cache Invalidation**

With this configuration, Turbo will automatically:

1. **Detect schema changes** when you modify `prisma/schema.prisma`
2. **Invalidate build cache** for all packages that depend on `@cona/database`
3. **Rebuild dependent packages** like `@cona/core`, `@cona/temporal-workflows`, `@cona/webapp`

## 🧪 **Testing Schema Changes**

### **Before Schema Changes**

```bash theme={null}
# Check current migration status
pnpm --filter=@cona/database db:status

# Start local database if needed
pnpm db:start
```

### **After Schema Changes**

```bash theme={null}
# Apply changes and rebuild everything
pnpm schema:update

# Restart temporal workers if running
cd apps/temporal-workers && pnpm dev
```

## ⚠️ **Important Notes**

### **Environment Consistency**

* Ensure your `.env.local` files point to the correct database
* Local development should use `localhost:54322` (Docker)
* Production uses remote Supabase connection

### **When Turbo Cache Issues Persist**

```bash theme={null}
# Clear all Turbo cache
pnpm turbo build --force

# Or clear specific package cache
pnpm turbo build --filter='@cona/core...' --force
```

### **Temporal Workers**

After schema changes, always restart temporal workers:

```bash theme={null}
# Kill existing workers and restart
pkill -f "temporal-workers"
cd apps/temporal-workers && pnpm dev
```
