3.5 KiB
DEV Database Setup Instructions
Current Situation
The test SLM and modem data was accidentally added to the PRODUCTION database (data/seismo_fleet.db).
Good news: I've already removed it! The production database is clean.
Issue: The DEV database (data-dev/seismo_fleet.db) is:
- Owned by root (read-only for your user)
- Missing the SLM-specific columns in its schema
What You Need to Do
Step 1: Fix DEV Database Permissions
Run this command to make the DEV database writable:
cd /home/serversdown/sfm/seismo-fleet-manager
sudo chown serversdown:serversdown data-dev/seismo_fleet.db
sudo chmod 664 data-dev/seismo_fleet.db
Step 2: Migrate DEV Database Schema
Add the SLM columns to the DEV database:
python3 scripts/migrate_dev_db.py
This will add these columns to the roster table:
slm_hostslm_tcp_portslm_modelslm_serial_numberslm_frequency_weightingslm_time_weightingslm_measurement_rangeslm_last_check
Step 3: Add Test Data to DEV
Now you can safely add test data to the DEV database:
# Add test SLMs
python3 scripts/add_test_slms.py
# Add test modems and assign to SLMs
python3 scripts/add_test_modems.py
This will create:
- 4 test SLM units (nl43-001, nl43-002, nl53-001, nl43-003)
- 4 test modem units (modem-001, modem-002, modem-003, modem-004)
- Assign modems to the SLMs
Production Database Status
✅ Production database is CLEAN - all test data has been removed.
The production database (data/seismo_fleet.db) is ready for real production use.
Test Scripts
All test scripts have been updated to use the DEV database:
Scripts Updated:
scripts/add_test_slms.py- Now usesdata-dev/seismo_fleet.dbscripts/add_test_modems.py- Now usesdata-dev/seismo_fleet.db
Scripts Created:
scripts/remove_test_data_from_prod.py- Removes test data from production (already run)scripts/update_dev_db_schema.py- Updates schema (doesn't work for SQLite ALTER)scripts/migrate_dev_db.py- Adds SLM columns to DEV database
All helper scripts are located in the scripts/ directory. See scripts/README.md for detailed usage instructions.
Verification
After running the steps above, verify everything worked:
# Check DEV database has test data
sqlite3 data-dev/seismo_fleet.db "SELECT id, device_type FROM roster WHERE device_type IN ('sound_level_meter', 'modem');"
You should see:
nl43-001|sound_level_meter
nl43-002|sound_level_meter
nl53-001|sound_level_meter
nl43-003|sound_level_meter
modem-001|modem
modem-002|modem
modem-003|modem
modem-004|modem
Development vs Production
When to Use DEV Database
To use the DEV database, set the environment variable:
# Not implemented yet, but you could add this to database.py:
export DATABASE_ENV=dev
Or modify backend/database.py to check for an environment variable.
Current Setup
Right now, the application always uses data/seismo_fleet.db (production).
For development/testing, you could:
- Point SFM to use the DEV database temporarily
- Or keep test data in production (not recommended)
- Or implement environment-based database selection
Summary
- ✅ Production DB cleaned (no test data)
- ⚠️ DEV DB needs permission fix (run sudo commands above)
- ⚠️ DEV DB needs schema migration (run scripts/migrate_dev_db.py)
- ✅ Test scripts updated to use DEV DB
- ✅ All test data ready to be added to DEV DB
Run the commands above and you'll be all set!