This directory contains SQL migration files for the Rustelo application database setup.
## Overview
The migration system sets up a complete database with authentication, content management, and auditing capabilities. **Rustelo now supports both PostgreSQL and SQLite** through a database-agnostic architecture.
## Migration Files
Rustelo provides **database-specific migration files** to support both PostgreSQL and SQLite:
7.**Database Location** - Store SQLite files outside web root
## Schema Evolution
For future schema changes:
1. Create **database-specific** migration files:
-`003_new_feature_postgres.sql`
-`003_new_feature_sqlite.sql`
2. Always use `CREATE TABLE IF NOT EXISTS` for safety
3. Add proper indexes for performance
4. Handle database-specific differences (UUID vs TEXT, etc.)
5. Test migrations on both database types
6. Include rollback scripts when possible
7. Test migrations on a copy of production data
### Database Differences to Consider
- **UUIDs**: PostgreSQL native vs SQLite TEXT
- **Timestamps**: PostgreSQL native vs SQLite TEXT (ISO 8601)
- **JSON**: PostgreSQL JSONB vs SQLite TEXT
- **Arrays**: PostgreSQL arrays vs SQLite JSON arrays
- **Booleans**: PostgreSQL BOOLEAN vs SQLite INTEGER
## Performance Notes
### PostgreSQL
- All tables have appropriate indexes for common queries
- Full-text search is enabled for content
- Partial indexes are used for filtered queries
- GIN indexes are used for JSONB and array columns
- Connection pooling for high concurrency
### SQLite
- Optimized indexes for single-user scenarios
- WAL mode enabled for better concurrency
- Foreign key constraints enabled
- Query planner optimizations
- Smaller memory footprint
## Troubleshooting
### Common Issues
#### PostgreSQL Issues
1.**Extension Error**: If you get an error about `uuid-ossp` extension, ensure your PostgreSQL user has superuser privileges or the extension is already installed.
2.**Permission Denied**: Ensure your database user has CREATE privileges.
3.**Connection Failed**: Check PostgreSQL service is running and connection details are correct.
#### SQLite Issues
1.**File Permission Error**: Ensure the SQLite file and directory have proper write permissions.
2.**Database Locked**: Close other connections to the SQLite file.
3.**Directory Not Found**: Ensure the directory for the SQLite file exists.
#### General Issues
1.**Constraint Violations**: Check that your data meets the constraint requirements (email format, username format, etc.).
2.**Migration Version Mismatch**: Ensure all migration files are present and properly numbered.
3.**Database Type Detection Failed**: Verify your `DATABASE_URL` format is correct.
### Verification
After running the migration, verify the setup:
#### PostgreSQL Verification
```sql
-- Check tables were created
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
-- Check default admin user
SELECT username, email, is_active FROM users WHERE username = 'admin';
-- Check permissions setup
SELECT COUNT(*) FROM permissions;
SELECT COUNT(*) FROM role_permissions;
-- Check sample content
SELECT slug, title, state FROM page_contents;
```
#### SQLite Verification
```sql
-- Check tables were created
SELECT name FROM sqlite_master WHERE type='table';
-- Check default admin user
SELECT username, email, is_active FROM users WHERE username = 'admin';