25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
901 B

  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. CONTAINER="db"
  4. DB_USER="postgres"
  5. DB_NAME="postgres"
  6. if ! docker inspect --format='{{.State.Running}}' "$CONTAINER" 2>/dev/null | grep -q true; then
  7. echo "ERROR: container '$CONTAINER' is not running" >&2
  8. exit 1
  9. fi
  10. echo "Ensuring indexes on '$DB_NAME' in container '$CONTAINER'..."
  11. docker exec -i "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" <<'SQL'
  12. \set ON_ERROR_STOP on
  13. CREATE INDEX IF NOT EXISTS idx_gateways_mac ON gateways(mac);
  14. CREATE INDEX IF NOT EXISTS idx_tracker_zones_tracker ON tracker_zones(tracker);
  15. CREATE INDEX IF NOT EXISTS idx_tracks_gateway ON tracks(gateway);
  16. CREATE INDEX IF NOT EXISTS idx_tracks_tracker ON tracks(tracker);
  17. CREATE INDEX IF NOT EXISTS idx_tracks_uuid_ts ON tracks(uuid, timestamp);
  18. CREATE INDEX IF NOT EXISTS idx_tracks_tracker_ts ON tracks(tracker, timestamp);
  19. \echo 'Done.'
  20. SQL