**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.
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 siteGET /api/content/{id}?site_id={site}- Get single content itemGET /api/content/bulk?site_id={site}&ids[]={id1}&ids[]={id2}- Get multiple content itemsPOST /api/content- Create new contentPUT /api/content/{id}?site_id={site}- Update existing contentDELETE /api/content/{id}?site_id={site}- Delete content
Version Control
GET /api/content/{id}/versions?site_id={site}- Get version historyPOST /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 versionscontent_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
- Database: Consider PostgreSQL for production scale
- Authentication: Integrate with your auth system via middleware
- CORS: Configure appropriate CORS policies
- SSL: Serve over HTTPS
- Monitoring: Add logging and metrics collection