# Supabase Content Publisher

> Create, validate, and publish content records in Supabase without touching the dashboard. Insert new entries, check for duplicates, and manage status transitions from draft to published.

Source: https://cotera.co/solutions/ops/supabase-content-publisher

---

- **Team:** Operations
- **Tools:** Supabase
- **Difficulty:** easy
- **Setup time:** 5 min
- **Time saved:** 30 min/batch

## How it works
1. **Create Content** — Inserts new records with all required fields, auto-populating timestamps and default status values
2. **Check Duplicates** — Searches for existing records by slug or title before creating so you never end up with collisions
3. **Update Metadata** — Changes categories, tags, SEO fields, and any other metadata on existing content records
4. **Manage Status** — Transitions content through draft, review, published, and archived states with validation

## Example requests
- Create a new product listing in the products table: name "Wireless Charger", slug "wireless-charger", price 29.99, category "electronics", status "draft".
- Find all posts in the posts table with status "review" and publish them by setting status to "published" and adding a published_at timestamp.
- Check if a blog post with slug "supabase-getting-started" already exists. If not, create it with title "Getting Started with Supabase" and status "draft".

## Prompt

```markdown
## Task

Use @Supabase/Create Record to insert new content records (blog posts, product listings, pages, or any CMS-style entries), @Supabase/Read Records to check for duplicates and retrieve existing content, and @Supabase/Update Record to change status, update metadata, or modify published content.

## Input

The user provides:
1. The content table name in Supabase (e.g., "posts", "products", "pages")
2. The action: create new content, check for duplicates, update status, or publish
3. Content data: title, body/description, slug, category, tags, author, metadata
4. Status transitions: draft, review, published, archived

**Example:** "Create a new blog post in the posts table with title 'Getting Started with Supabase', slug 'getting-started-supabase', status 'draft', and category 'tutorials'. Then check if any other post already has the same slug."

## Context

### Creating Content Records

1. Use @Supabase/Read Records to check if a record with the same slug or title already exists
2. If a duplicate is found, warn the user and show the existing record
3. Use @Supabase/Create Record to insert the new content with all provided fields
4. Auto-populate metadata fields:
   - created_at: current timestamp
   - updated_at: current timestamp
   - status: "draft" unless specified otherwise
   - author: as provided or default
5. Return the created record with its generated ID

### Duplicate Checking

1. Use @Supabase/Read Records to search by slug, title, or external_id
2. Report any matches with their current status and last updated date
3. Let the user decide whether to proceed with creation or update the existing record instead

### Updating Content

1. Use @Supabase/Read Records to find the content to update
2. Use @Supabase/Update Record to modify fields:
   - **Status changes:** draft to review, review to published, published to archived
   - **Metadata updates:** category, tags, SEO fields, featured image
   - **Content edits:** title, body, description, excerpt
3. Always update the updated_at timestamp when modifying a record
4. For status transitions, validate the transition is valid (e.g., do not go from archived back to draft without explicit confirmation)

### Bulk Publishing

If the user wants to publish multiple items:
1. Use @Supabase/Read Records to find all records matching the criteria (e.g., status = "review")
2. Show the list of records that would be published
3. Use @Supabase/Update Record to change status to "published" and set published_at timestamp
4. Report results for each item

### Safety Guidelines

- Always check for slug/title duplicates before creating
- Show the current state of a record before updating it
- Require confirmation for bulk status changes
- Never overwrite content body without showing the diff

## Output

**Content Operation Results:**

**Records Created:**
| Title | Slug | Status | ID |
|-------|------|--------|----|
| [title] | [slug] | [status] | [generated_id] |

**Duplicate Check:**
| Slug | Existing Title | Status | Last Updated |
|------|---------------|--------|-------------|
| [slug] | [title] | [status] | [date] |

**Records Updated:**
| ID | Field | Previous Value | New Value |
|----|-------|----------------|-----------|
| [id] | status | draft | published |
| [id] | updated_at | [old] | [new] |

**Summary:**
- Created: [n] new records
- Updated: [n] existing records
- Duplicates found: [n]
- Skipped: [n]
```

## Related reading
- [Supabase Realtime: How We Built Live Dashboards Without a WebSocket Server](https://cotera.co/articles/supabase-realtime-guide.md)

