SQLite Database Development Guide
Overview
SQLite is the default database for DeployStack development and small to medium deployments. It provides excellent performance, zero configuration, and a simple file-based architecture that makes it ideal for development, testing, and single-server deployments.Setup Instructions: For initial SQLite configuration, see the Database Setup Guide.
Technical Architecture
File-Based Database
SQLite stores the entire database in a single file, making it extremely portable and easy to manage:- Database File:
persistent_data/database/deploystack.db
- Zero Configuration: No server setup or network configuration required
- ACID Compliance: Full transaction support with rollback capabilities
- Cross-Platform: Works identically across all operating systems
Direct Driver Integration
DeployStack uses thebetter-sqlite3
driver for optimal SQLite performance:
Performance Characteristics
Advantages
Fast Local Operations:- No network latency for database operations
- Direct file system access for maximum speed
- Excellent read performance for concurrent operations
- Single file contains entire database
- No separate database server required
- Easy backup and restore operations
- Instant startup with no configuration
- Easy to reset and recreate for testing
- Perfect for local development workflows
Limitations
Single Server Only:- Cannot be shared across multiple application instances
- No built-in replication or clustering
- Limited to single-server deployments
- Single writer at a time (multiple readers supported)
- Write operations are serialized
- May become a bottleneck under heavy write loads
Development Workflow
Local Development Setup
SQLite is the recommended database for local development:Database File Management
Default Location:services/backend/persistent_data/database/deploystack.db
Directory Structure:
Testing with SQLite
SQLite is excellent for testing due to its simplicity:Global Settings Integration
Batch Operations
SQLite excels at batch operations and can handle large global settings initialization efficiently:- Large Batches: Can insert all 17+ global settings in a single transaction
- No Parameter Limits: Unlike D1, SQLite has no practical parameter limits
- Transaction Safety: All settings created atomically
Performance Benefits
Database Inspection and Debugging
SQLite CLI
The SQLite command-line interface is the primary tool for database inspection:GUI Tools
DB Browser for SQLite (Recommended):- Download: https://sqlitebrowser.org/
- Visual table browsing and editing
- Query execution with syntax highlighting
- Schema visualization
- SQLiteStudio: Cross-platform SQLite manager
- DBeaver: Universal database tool with SQLite support
- VS Code Extensions: SQLite Viewer, SQLite3 Editor
Programmatic Inspection
Backup and Recovery
File-Based Backup
SQLite’s file-based nature makes backup extremely simple:Automated Backup Script
Recovery
Performance Optimization
Indexing Strategy
SQLite benefits greatly from proper indexing:PRAGMA Settings
Optimize SQLite performance with PRAGMA settings:Connection Pooling
While SQLite doesn’t need traditional connection pooling, you can optimize connection usage:Migration Considerations
SQLite-Specific Features
SQLite has some unique characteristics for migrations:Migration Best Practices
- Test Migrations: Always test on a copy of production data
- Backup Before Migration: Create backup before applying migrations
- Use Transactions: Wrap migrations in transactions for rollback capability
- Check Constraints: Verify foreign key constraints after table recreation
Troubleshooting
Common Issues
“Database is locked”- Cause: Another process has the database open
- Solution: Ensure only one application instance accesses the database
- Prevention: Use WAL mode for better concurrency
- Cause: Migrations haven’t been applied
- Solution: Run
npm run db:up
or restart the server - Check: Verify migration files exist in
drizzle/migrations_sqlite/
- Cause: Missing indexes or suboptimal queries
- Solution: Add appropriate indexes and optimize queries
- Analysis: Use
EXPLAIN QUERY PLAN
to analyze query performance
- Cause: Unexpected shutdown or disk issues
- Solution: Restore from backup
- Prevention: Use WAL mode and regular backups
Debugging Queries
Production Considerations
When to Use SQLite in Production
Good For:- Single-server applications
- Read-heavy workloads
- Small to medium datasets (< 1TB)
- Applications with predictable load patterns
- Embedded applications
- Multiple application servers needed
- High concurrent write requirements
- Need for real-time replication
- Distributed deployment requirements
Production Optimizations
Monitoring
Integration with DeployStack Features
Global Settings
SQLite provides optimal performance for global settings:- Fast initialization: All settings created in single transaction
- No batching needed: No parameter limits to worry about
- Immediate consistency: All changes immediately visible
Plugin System
Plugins work seamlessly with SQLite:- Table creation: Plugin tables created through standard migrations
- Data operations: Full SQL feature support
- Performance: Excellent performance for plugin data operations
Migration System
SQLite migration advantages:- Fast execution: Local file operations are very fast
- Transaction safety: Full rollback support for failed migrations
- Simple debugging: Easy to inspect database state during development
Future Considerations
Scaling Beyond SQLite
When you outgrow SQLite, DeployStack makes migration easy:- Export Data: Use SQLite’s
.dump
command - Transform Schema: Convert to target database format
- Update Configuration: Change database type in setup
- Import Data: Load data into new database
Hybrid Approaches
Consider hybrid approaches for scaling:- Read Replicas: Use D1 or Turso for global read access
- Caching Layer: Add Redis for frequently accessed data
- Microservices: Split into multiple services with separate databases
For general database concepts and cross-database functionality, see the Database Development Guide. For initial setup and configuration, see the Database Setup Guide.