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:
29
README.md
29
README.md
@@ -52,9 +52,11 @@ Containers with `class="insertr"` automatically make their viable children edita
|
||||
|
||||
**✅ Complete Full-Stack CMS**
|
||||
- **Professional Editor**: Modal forms, markdown support, authentication system
|
||||
- **Content Persistence**: SQLite database with REST API
|
||||
- **Content Persistence**: SQLite database with REST API, version control
|
||||
- **Version History**: Complete edit history with user attribution and one-click rollback
|
||||
- **CLI Enhancement**: Parse HTML, inject database content, build-time optimization
|
||||
- **Smart Detection**: Auto-detects content types (text/markdown/link)
|
||||
- **Deterministic IDs**: Content-based ID generation for consistent developer experience
|
||||
- **Full Integration**: Seamless development workflow with hot reload
|
||||
|
||||
**🔄 Ready for Production**
|
||||
@@ -114,10 +116,35 @@ Running `just dev` gives you the **complete Insertr CMS**:
|
||||
|
||||
- ✅ **Professional Editor** - Modal forms, markdown support, authentication
|
||||
- ✅ **Real-Time Persistence** - SQLite database with REST API
|
||||
- ✅ **Version Control** - Complete edit history with user attribution and rollback
|
||||
- ✅ **Content Management** - Create, read, update content via browser
|
||||
- ✅ **Build Integration** - CLI enhances HTML with database content
|
||||
- ✅ **Hot Reload** - Changes reflected immediately
|
||||
|
||||
## 📚 **Version Control Features**
|
||||
|
||||
### **Complete Edit History**
|
||||
Every content change is automatically tracked with:
|
||||
- **User Attribution** - Who made each change
|
||||
- **Timestamps** - When changes were made
|
||||
- **Content Snapshots** - Full content preserved for each version
|
||||
|
||||
### **Easy Rollback**
|
||||
- **View History** button in any content editor
|
||||
- **One-Click Restore** to any previous version
|
||||
- **Version Comparison** - See what changed between versions
|
||||
- **Safe Rollback** - Current content is preserved before restoration
|
||||
|
||||
### **Example Workflow**
|
||||
```
|
||||
1. Editor clicks on any element with class="insertr"
|
||||
2. Professional editing modal opens
|
||||
3. Click "View History" to see all previous versions
|
||||
4. Each version shows: timestamp, author, content preview
|
||||
5. Click "Restore" on any version to rollback instantly
|
||||
6. All changes are tracked automatically
|
||||
```
|
||||
|
||||
### **Parse Existing Site**
|
||||
```bash
|
||||
# Analyze HTML for editable elements
|
||||
|
||||
Reference in New Issue
Block a user