133 lines
3.5 KiB
Markdown
133 lines
3.5 KiB
Markdown
# 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:
|
|
1. Owned by root (read-only for your user)
|
|
2. 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:
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
python3 scripts/migrate_dev_db.py
|
|
```
|
|
|
|
This will add these columns to the `roster` table:
|
|
- `slm_host`
|
|
- `slm_tcp_port`
|
|
- `slm_model`
|
|
- `slm_serial_number`
|
|
- `slm_frequency_weighting`
|
|
- `slm_time_weighting`
|
|
- `slm_measurement_range`
|
|
- `slm_last_check`
|
|
|
|
### Step 3: Add Test Data to DEV
|
|
|
|
Now you can safely add test data to the DEV database:
|
|
|
|
```bash
|
|
# 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:
|
|
1. `scripts/add_test_slms.py` - Now uses `data-dev/seismo_fleet.db`
|
|
2. `scripts/add_test_modems.py` - Now uses `data-dev/seismo_fleet.db`
|
|
|
|
### Scripts Created:
|
|
1. `scripts/remove_test_data_from_prod.py` - Removes test data from production (already run)
|
|
2. `scripts/update_dev_db_schema.py` - Updates schema (doesn't work for SQLite ALTER)
|
|
3. `scripts/migrate_dev_db.py` - Adds SLM columns to DEV database
|
|
|
|
All helper scripts are located in the `scripts/` directory. See [scripts/README.md](../scripts/README.md) for detailed usage instructions.
|
|
|
|
## Verification
|
|
|
|
After running the steps above, verify everything worked:
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
```bash
|
|
# 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:
|
|
1. Point SFM to use the DEV database temporarily
|
|
2. Or keep test data in production (not recommended)
|
|
3. 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!
|