refactor: implement database-specific schema architecture with schema-as-query pattern
🏗️ **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
This commit is contained in:
10
justfile
10
justfile
@@ -119,6 +119,10 @@ servedev:
|
||||
|
||||
# === 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
|
||||
@@ -136,6 +140,12 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user