Files
insertr/insertr-server
Joakim 4dc479ba9e docs: clarify sqlc DDL support limitations and correct implementation
**Discovery**: sqlc's DDL support is database-engine specific:

 **PostgreSQL**: sqlc generates functions for CREATE INDEX, CREATE FUNCTION
 **SQLite**: sqlc does NOT generate CREATE INDEX functions
 **Both**: sqlc does NOT generate CREATE TRIGGER functions

**Corrected Implementation**:
- Use sqlc-generated setup functions where available (tables always, PostgreSQL indexes)
- Use manual SQL where sqlc doesn't support (SQLite indexes, all triggers)
- Comments clarify why manual SQL is needed in each case

**Architecture Principle**: Use sqlc for what it supports, supplement with manual SQL for what it doesn't - this is the recommended hybrid approach.
2025-09-09 00:28:10 +02:00
..

Insertr Content Server

REST API server for the Insertr CMS system. Provides content management with version control and user attribution.

Features

  • Content Management: Full CRUD operations for content items
  • Version Control: Complete edit history with rollback functionality
  • User Attribution: Track who made each change
  • Type-Safe Database: Uses sqlc for generated Go code from SQL
  • SQLite & PostgreSQL: Database flexibility for development to production

API Endpoints

Content Operations

  • GET /api/content?site_id={site} - Get all content for a site
  • GET /api/content/{id}?site_id={site} - Get single content item
  • GET /api/content/bulk?site_id={site}&ids[]={id1}&ids[]={id2} - Get multiple content items
  • POST /api/content - Create new content
  • PUT /api/content/{id}?site_id={site} - Update existing content
  • DELETE /api/content/{id}?site_id={site} - Delete content

Version Control

  • GET /api/content/{id}/versions?site_id={site} - Get version history
  • POST /api/content/{id}/rollback?site_id={site} - Rollback to specific version

Health & Status

  • GET /health - Server health check

User Attribution

All content operations support user attribution via the X-User-ID header:

curl -X PUT "http://localhost:8080/api/content/hero-title?site_id=demo" \
  -H "Content-Type: application/json" \
  -H "X-User-ID: john@example.com" \
  -d '{"value": "Updated content"}'

Quick Start

# Build server
go build -o insertr-server ./cmd/server

# Start server
./insertr-server --port 8080

# Check health
curl http://localhost:8080/health

Development

Using sqlc

# Install sqlc
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest

# Generate Go code from SQL
sqlc generate

# Build with generated code
go build ./cmd/server

Database Schema

See db/schema/schema.sql for the complete schema. Key tables:

  • content - Current content versions
  • content_versions - Complete version history

Example Version Control Workflow

# Create content
curl -X POST "http://localhost:8080/api/content" \
  -H "Content-Type: application/json" \
  -H "X-User-ID: alice@example.com" \
  -d '{
    "id": "hero-title",
    "site_id": "demo", 
    "value": "Original Title",
    "type": "text"
  }'

# Update content (creates version)
curl -X PUT "http://localhost:8080/api/content/hero-title?site_id=demo" \
  -H "Content-Type: application/json" \
  -H "X-User-ID: bob@example.com" \
  -d '{"value": "Updated Title"}'

# View version history
curl "http://localhost:8080/api/content/hero-title/versions?site_id=demo"

# Rollback to version 1
curl -X POST "http://localhost:8080/api/content/hero-title/rollback?site_id=demo" \
  -H "Content-Type: application/json" \
  -H "X-User-ID: admin@example.com" \
  -d '{"version_id": 1}'

Configuration

Environment Variables

  • PORT - Server port (default: 8080)
  • DB_PATH - SQLite database file path (default: ./insertr.db)

Command Line Flags

./insertr-server --help

Production Deployment

  1. Database: Consider PostgreSQL for production scale
  2. Authentication: Integrate with your auth system via middleware
  3. CORS: Configure appropriate CORS policies
  4. SSL: Serve over HTTPS
  5. Monitoring: Add logging and metrics collection