# Test Database Setup - Post-ERG Guide for deploying the test database to production server. --- ## ๐ŸŽฏ Quick Deploy ```bash just deploy-db ``` This automatically: 1. โœ… Checks remote DB doesn't exist (safety check) 2. โœ… Uploads `storage/test.db` to the server 3. โœ… Sets correct permissions (660, www-data:posterg) --- ## ๐Ÿ”ง Prerequisites (One-Time Setup) ### 1. Install PHP SQLite Extension ```bash ssh posterg sudo apt update sudo apt install php8.4-sqlite3 sudo systemctl restart php8.4-fpm ``` ### 2. Verify Installation ```bash ssh posterg php -m | grep sqlite3 # Should output: pdo_sqlite, sqlite3 ``` --- ## ๐Ÿงช Complete Testing Workflow ### 1. Create Test Data Locally ```bash # Create empty test database from schema just init-db # Or create with sample fixtures just fixtures ``` ### 2. Deploy Test Database ```bash just deploy-db ``` ### 3. Test the Site Visit: https://posterg.erg.be/ ### 4. Check What Database is Being Used ```bash ssh posterg php -r "require_once '/var/www/posterg/src/Database.php'; echo 'Using: ' . Database::getInstance()->getDatabasePath() . PHP_EOL;" ``` ### 5. Switch Back to Production ```bash ssh posterg rm /var/www/posterg/storage/test.db ``` --- ## ๐Ÿ”’ Permissions Explained ``` /var/www/posterg/storage/ drwxrwxr-x www-data posterg # 775 - group writable /var/www/posterg/storage/test.db -rw-rw---- www-data posterg # 660 - owner/group read/write ``` --- ## ๐Ÿ› Troubleshooting ### "could not find driver" ```bash ssh posterg sudo apt install php8.4-sqlite3 sudo systemctl restart php8.4-fpm ``` ### "unable to open database file" ```bash ssh posterg chown www-data:posterg /var/www/posterg/storage/test.db chmod 660 /var/www/posterg/storage/test.db chmod 775 /var/www/posterg/storage/ ``` ### "attempt to write a readonly database" ```bash ssh posterg chmod 775 /var/www/posterg/storage/ rm -f /var/www/posterg/storage/test.db-* ``` --- ## โš ๏ธ Important Notes ### Production Safety `just deploy` **excludes all `.db` files** by default. Only `just deploy-db` uploads the test database. ### Backup Production Database ```bash ssh posterg cp /var/www/posterg/storage/posterg.db /var/www/posterg/storage/posterg.db.backup.$(date +%Y%m%d) ``` --- ## ๐Ÿ“š Related Commands | Command | Description | |---------|-------------| | `just init-db` | Create empty test database | | `just fixtures` | Create test database with sample data | | `just deploy-db` | Deploy test database to server | --- ## โœ… Deployment Checklist After running `just deploy-db`, verify: - [ ] Database file exists: `ssh posterg "ls -la /var/www/posterg/storage/test.db"` - [ ] Correct permissions: `-rw-rw---- www-data posterg` - [ ] Site loads: Visit https://posterg.erg.be/ - [ ] No errors in logs: `ssh posterg "tail /var/log/nginx/posterg_error.log"`