Files
terra-view/scripts/README.md
2026-01-06 07:50:58 +00:00

3.1 KiB

Helper Scripts

This directory contains helper scripts for database management and testing.

Database Migration Scripts

migrate_dev_db.py

Migrates the DEV database schema to add SLM-specific columns to the roster table.

Usage:

cd /home/serversdown/sfm/seismo-fleet-manager
python3 scripts/migrate_dev_db.py

What it does:

  • Adds 8 SLM-specific columns to the DEV database (data-dev/seismo_fleet.db)
  • Columns: slm_host, slm_tcp_port, slm_model, slm_serial_number, slm_frequency_weighting, slm_time_weighting, slm_measurement_range, slm_last_check
  • Safe to run multiple times (skips existing columns)

update_dev_db_schema.py

Inspects and displays the DEV database schema.

Usage:

python3 scripts/update_dev_db_schema.py

What it does:

  • Shows all tables in the DEV database
  • Lists all columns in the roster table
  • Useful for verifying schema after migrations

Test Data Scripts

add_test_slms.py

Adds test Sound Level Meter units to the DEV database.

Usage:

python3 scripts/add_test_slms.py

What it creates:

  • nl43-001: NL-43 SLM at Construction Site A
  • nl43-002: NL-43 SLM at Construction Site B
  • nl53-001: NL-53 SLM at Residential Area
  • nl43-003: NL-43 SLM (not deployed, spare unit)

add_test_modems.py

Adds test modem units to the DEV database and assigns them to SLMs.

Usage:

python3 scripts/add_test_modems.py

What it creates:

  • modem-001, modem-002, modem-003: Deployed modems (Raven XTV and Sierra Wireless)
  • modem-004: Spare modem (not deployed)

Modem assignments:

  • nl43-001 → modem-001
  • nl43-002 → modem-002
  • nl53-001 → modem-003

Cleanup Scripts

remove_test_data_from_prod.py

⚠️ PRODUCTION DATABASE CLEANUP

Removes test data from the production database (data/seismo_fleet.db).

Status: Already executed successfully. Production database is clean.

What it removed:

  • All test SLM units (nl43-001, nl43-002, nl53-001, nl43-003)
  • All test modem units (modem-001, modem-002, modem-003, modem-004)

Database Cloning

clone_db_to_dev.py

Clones the production database to create/update the DEV database.

Usage:

python3 scripts/clone_db_to_dev.py

What it does:

  • Copies data/seismo_fleet.db → data-dev/seismo_fleet.db
  • Useful for syncing DEV database with production schema/data

Setup Sequence

To set up a fresh DEV database with test data:

cd /home/serversdown/sfm/seismo-fleet-manager

# 1. Fix permissions (if needed)
sudo chown -R serversdown:serversdown data-dev/

# 2. Migrate schema
python3 scripts/migrate_dev_db.py

# 3. Add test data
python3 scripts/add_test_slms.py
python3 scripts/add_test_modems.py

# 4. Verify
sqlite3 data-dev/seismo_fleet.db "SELECT id, device_type FROM roster WHERE device_type IN ('sound_level_meter', 'modem');"

Important Notes

  • DEV Database: data-dev/seismo_fleet.db - Used for development and testing
  • Production Database: data/seismo_fleet.db - Used by the running application
  • All test scripts are configured to use the DEV database only
  • Never run test data scripts against production