fix(manage): migrate legacy config path during start/update (#316)

## Summary
- simplified `migrate_config` in `manage.sh` to only migrate legacy
`./config.json` into `${PROD_DATA}/config.json`
- removed the custom destination-path prompt to avoid suggesting
unsupported runtime paths
- added mode-aware behavior:
  - `cmd_start` calls `migrate_config "$PROD_DATA"` (interactive prompt)
- `cmd_update` calls `migrate_config "$PROD_DATA" auto` (non-interactive
auto-migration)
- improved interactive migration copy with explicit source/destination
and runtime note
- when migration is declined from `cmd_start`, script aborts with clear
instructions

## Behavior details
- If `${PROD_DATA}/config.json` exists: no-op
- If only `./config.json` exists:
  - `cmd_start` shows:
    - `Source: ./config.json (repo root)`
    - `Destination: ${PROD_DATA}/config.json`
    - `Note: CoreScope reads config from the data directory at runtime.`
  - prompt: `Move to ${PROD_DATA}/config.json? [Y/n]`
  - yes/default: copies to `${PROD_DATA}/config.json`
  - no: aborts with guidance to move the file and rerun
  - `cmd_update`: auto-copies with:
- `→ Migrating config.json from repo root to
${PROD_DATA}/config.json...`
    - `✓ Config migrated.`
- If neither exists: existing `ensure_config` fallback remains in place

## Validation performed
-  Target exists (`${PROD_DATA}/config.json`) → no-op
-  Legacy exists (`./config.json`), `cmd_start` → prompts, copies on
yes
-  Legacy exists (`./config.json`), `cmd_update` → auto-copies without
prompt
-  Both missing → `ensure_config` fallback flow still handles config
creation/abort path
-  `bash -n manage.sh` passes

## Tests run
- `bash -n manage.sh`
- `node test-packet-filter.js`
- `node test-aging.js`
- `node test-frontend-helpers.js`
- `go test ./...` in `cmd/server`
- `go test ./...` in `cmd/ingestor`

---------

Co-authored-by: Kpa-clawbot <259247574+Kpa-clawbot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Kpa-clawbot
2026-03-30 23:32:31 -07:00
committed by GitHub
co-authored by Kpa-clawbot Copilot
parent 114b6eea1f
commit 1211d2fcbf
+45
View File
@@ -916,6 +916,48 @@ container_health() {
# ─── Start / Stop / Restart ──────────────────────────────────────────────
# Migrate legacy root config.json to data directory path
migrate_config() {
local mode="${1:-interactive}"
local legacy_config="./config.json"
local target_config="$PROD_DATA/config.json"
local reply=""
mkdir -p "$PROD_DATA"
if [ -f "$target_config" ]; then
return 0
fi
if [ ! -f "$legacy_config" ]; then
return 0
fi
if [ "$mode" = "auto" ]; then
echo "→ Migrating config.json from repo root to ${PROD_DATA}/config.json..."
cp "$legacy_config" "$target_config"
echo "✓ Config migrated."
return 0
fi
echo ""
echo "Found legacy config location:"
echo " Source: ./config.json (repo root)"
echo " Destination: ${PROD_DATA}/config.json"
echo " Note: CoreScope reads config from the data directory at runtime."
read -p "Move to ${PROD_DATA}/config.json? [Y/n] " reply
if [ -z "$reply" ] || [[ "$reply" =~ ^[Yy]$ ]]; then
cp "$legacy_config" "$target_config"
log "Copied config.json to ${target_config}"
return 0
fi
warn "Migration aborted."
echo "Move ./config.json to ${PROD_DATA}/config.json, then run this command again."
return 1
}
# Ensure config.json exists in the data directory before starting
ensure_config() {
local data_dir="$1"
@@ -986,6 +1028,7 @@ cmd_start() {
fi
fi
migrate_config || exit 1
# Always check prod config
ensure_config "$PROD_DATA"
@@ -1254,6 +1297,8 @@ cmd_update() {
info "Pulling latest code..."
git pull --ff-only
migrate_config auto
info "Rebuilding image..."
dc_prod build prod