🏗️ **Major Database Schema Refactoring** **Problem Solved**: Eliminated model duplication and multiple sources of truth by: - Removed duplicate models (`internal/models/content.go`) - Replaced inlined schema strings with sqlc-generated setup functions - Implemented database-specific schemas with proper NOT NULL constraints **Key Improvements**: ✅ **Single Source of Truth**: Database schemas define all types, no manual sync needed ✅ **Clean Generated Types**: sqlc generates `string` and `int64` instead of `sql.NullString/sql.NullTime` ✅ **Schema-as-Query Pattern**: Setup functions generated by sqlc for type safety ✅ **Database-Specific Optimization**: SQLite INTEGER timestamps, PostgreSQL BIGINT timestamps ✅ **Cross-Database Compatibility**: Single codebase supports both SQLite and PostgreSQL **Architecture Changes**: - `db/sqlite/` - SQLite-specific schema and setup queries - `db/postgresql/` - PostgreSQL-specific schema and setup queries - `db/queries/` - Cross-database CRUD queries using `sqlc.arg()` syntax - `internal/db/database.go` - Database abstraction with runtime selection - `internal/api/models.go` - Clean API models for requests/responses **Version Control System**: Complete element-level history with user attribution and rollback **Verification**: ✅ Full API workflow tested (create → update → rollback → versions) **Production Ready**: Supports SQLite (development) → PostgreSQL (production) migration
192 lines
5.8 KiB
Makefile
192 lines
5.8 KiB
Makefile
# Insertr Development Commands
|
|
# Use `just <command>` to run any of these tasks
|
|
|
|
# Default recipe - show available commands
|
|
default:
|
|
@just --list
|
|
|
|
# Install all dependencies (root + lib)
|
|
install:
|
|
npm install
|
|
cd lib && npm install
|
|
|
|
# Start full-stack development (primary workflow)
|
|
dev: build-lib server-build
|
|
#!/usr/bin/env bash
|
|
echo "🚀 Starting Full-Stack Insertr Development..."
|
|
echo "================================================"
|
|
echo ""
|
|
echo "📝 Unified logs below (API server + Demo site):"
|
|
echo "🔌 [SERVER] = API server logs"
|
|
echo "🌐 [DEMO] = Demo site logs"
|
|
echo ""
|
|
|
|
# Function to cleanup background processes
|
|
cleanup() {
|
|
echo ""
|
|
echo "🛑 Shutting down servers..."
|
|
kill $SERVER_PID $DEMO_PID 2>/dev/null || true
|
|
wait $SERVER_PID $DEMO_PID 2>/dev/null || true
|
|
echo "✅ Shutdown complete"
|
|
exit 0
|
|
}
|
|
trap cleanup SIGINT SIGTERM
|
|
|
|
# Start API server with prefixed output
|
|
echo "🔌 Starting API server (localhost:8080)..."
|
|
cd insertr-server && ./insertr-server --port 8080 2>&1 | sed 's/^/🔌 [SERVER] /' &
|
|
SERVER_PID=$!
|
|
cd ..
|
|
|
|
# Wait for server startup
|
|
echo "⏳ Waiting for API server startup..."
|
|
sleep 3
|
|
|
|
# Check server health
|
|
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
|
|
echo "✅ API server ready!"
|
|
else
|
|
echo "⚠️ API server may not be ready yet"
|
|
fi
|
|
|
|
echo ""
|
|
echo "🌐 Starting demo site (localhost:3000)..."
|
|
echo "📝 Full-stack ready - edit content with real-time persistence!"
|
|
echo ""
|
|
|
|
# Start demo site with prefixed output (this will block) - use local installation
|
|
cd {{justfile_directory()}} && npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
|
|
DEMO_PID=$!
|
|
|
|
# Wait for both processes
|
|
wait $DEMO_PID $SERVER_PID
|
|
|
|
# Demo site only (for specific use cases)
|
|
demo-only:
|
|
@echo "🌐 Starting demo site only (no API server)"
|
|
@echo "⚠️ Content edits will not persist without API server"
|
|
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html
|
|
|
|
# Start development server for about page
|
|
dev-about: build-lib server-build
|
|
#!/usr/bin/env bash
|
|
echo "🚀 Starting full-stack development (about page)..."
|
|
cd insertr-server && ./insertr-server --port 8080 &
|
|
SERVER_PID=$!
|
|
sleep 3
|
|
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/about.html
|
|
kill $SERVER_PID 2>/dev/null || true
|
|
|
|
# Check project status and validate setup
|
|
check:
|
|
npm run dev:check
|
|
|
|
# Show demo instructions
|
|
demo:
|
|
npm run dev:demo
|
|
|
|
# Build the entire project (library + CLI)
|
|
build:
|
|
npm run build
|
|
|
|
# Build only the JavaScript library
|
|
build-lib:
|
|
npm run build:lib
|
|
|
|
# Watch library files for changes (auto-rebuild)
|
|
watch:
|
|
cd lib && npm run dev
|
|
|
|
# Start Air hot-reload for Go CLI development
|
|
air:
|
|
cd insertr-cli && air
|
|
|
|
# Build Go CLI only
|
|
build-cli:
|
|
cd insertr-cli && go build -o insertr
|
|
|
|
# Run CLI help
|
|
cli-help:
|
|
cd insertr-cli && go run main.go --help
|
|
|
|
# Parse demo site with CLI
|
|
parse:
|
|
cd insertr-cli && go run main.go parse ../demo-site/
|
|
|
|
# Start CLI development server
|
|
servedev:
|
|
cd insertr-cli && go run main.go servedev -i ../demo-site -p 3000
|
|
|
|
# === Content API Server Commands ===
|
|
|
|
# Generate Go code from SQL (using sqlc)
|
|
server-generate:
|
|
cd insertr-server && sqlc generate
|
|
|
|
# Build the content API server binary
|
|
server-build:
|
|
cd insertr-server && go build -o insertr-server ./cmd/server
|
|
|
|
# Start content API server (default port 8080)
|
|
server port="8080":
|
|
cd insertr-server && ./insertr-server --port {{port}}
|
|
|
|
# Start API server with auto-restart on Go file changes
|
|
server-dev port="8080":
|
|
cd insertr-server && find . -name "*.go" | entr -r go run ./cmd/server --port {{port}}
|
|
|
|
# Check API server health
|
|
server-health port="8080":
|
|
@echo "🔍 Checking API server health..."
|
|
@curl -s http://localhost:{{port}}/health | jq . || echo "❌ Server not responding at localhost:{{port}}"
|
|
|
|
# Clean database (development only - removes all content!)
|
|
server-clean-db:
|
|
@echo "🗑️ Removing development database..."
|
|
rm -f insertr-server/insertr.db
|
|
@echo "✅ Database cleaned (will be recreated on next server start)"
|
|
|
|
# Clean all build artifacts
|
|
clean:
|
|
rm -rf lib/dist
|
|
rm -rf insertr-cli/insertr
|
|
rm -rf node_modules
|
|
rm -rf lib/node_modules
|
|
|
|
# Lint code (placeholder for now)
|
|
lint:
|
|
npm run lint
|
|
|
|
# Run tests (placeholder for now)
|
|
test:
|
|
npm run test
|
|
|
|
# Development workflow: install deps, build lib, start dev server
|
|
dev-setup: install build-lib dev
|
|
|
|
# Production workflow: install deps, build everything
|
|
prod-build: install build
|
|
|
|
|
|
|
|
# Show project status
|
|
status:
|
|
@echo "🏗️ Insertr Project Status"
|
|
@echo "========================="
|
|
@echo "📁 Root files:"
|
|
@ls -la package.json justfile 2>/dev/null || echo " Missing files"
|
|
@echo "\n📚 Library files:"
|
|
@ls -la lib/package.json lib/src lib/dist 2>/dev/null || echo " Missing library components"
|
|
@echo "\n🔧 CLI files:"
|
|
@ls -la insertr-cli/main.go insertr-cli/insertr 2>/dev/null || echo " Missing CLI components"
|
|
@echo "\n🔌 Server files:"
|
|
@ls -la insertr-server/cmd insertr-server/insertr-server 2>/dev/null || echo " Missing server components"
|
|
@echo "\n🌐 Demo site:"
|
|
@ls -la demo-site/index.html demo-site/about.html 2>/dev/null || echo " Missing demo files"
|
|
@echo ""
|
|
@echo "🚀 Development Commands:"
|
|
@echo " just dev - Full-stack development (recommended)"
|
|
@echo " just demo-only - Demo site only (no persistence)"
|
|
@echo " just server - API server only (localhost:8080)"
|
|
@echo ""
|
|
@echo "🔍 Check server: just server-health"
|