feat(migrations): add migration system for v3→v4 config format

- Create abstract BaseMigration class with order, shouldRun(), migrate()
- Add MigrationRunner to execute migrations in order
- Add Migration v1→v2 (snmp → upsDevices)
- Add Migration v3→v4 (upsList → upsDevices)
- Update INupstConfig with version field
- Update loadConfig() to run migrations automatically
- Update saveConfig() to ensure version field and remove legacy fields
- Update Docker test scripts to use real UPS data from .nogit/env.json
- Remove colors.bright (not available in @std/fmt/colors)

Config migrations allow users to jump versions (e.g., v1→v4) with all
intermediate migrations running automatically. Version field tracks
config format for future migrations.
This commit is contained in:
2025-10-19 20:41:09 +00:00
parent 49f7a7da8b
commit 016681b77b
9 changed files with 310 additions and 64 deletions

View File

@@ -53,7 +53,7 @@ docker exec ${CONTAINER_NAME} bash -c "
echo "→ Installing prerequisites in container..."
docker exec ${CONTAINER_NAME} bash -c "
apt-get update -qq
apt-get install -y -qq git curl sudo
apt-get install -y -qq git curl sudo jq
"
echo "→ Cloning NUPST v3 (commit ${V3_COMMIT})..."
@@ -66,35 +66,59 @@ docker exec ${CONTAINER_NAME} bash -c "
git log -1 --oneline
"
echo "→ Running NUPST v3 installation script..."
echo "→ Running NUPST v3 installation directly (bypassing install.sh auto-update)..."
docker exec ${CONTAINER_NAME} bash -c "
cd /opt/nupst
bash install.sh -y
# Run setup.sh directly to avoid install.sh trying to update to v4
bash setup.sh -y
"
echo "→ Creating dummy NUPST configuration for testing..."
docker exec ${CONTAINER_NAME} bash -c "
mkdir -p /etc/nupst
cat > /etc/nupst/config.json << 'EOF'
echo "→ Creating NUPST configuration using real UPS data from .nogit/env.json..."
# Check if .nogit/env.json exists
if [ ! -f "../../.nogit/env.json" ]; then
echo "❌ Error: .nogit/env.json not found"
echo "This file contains test UPS credentials and is required for testing"
exit 1
fi
# Read UPS data from .nogit/env.json and create v3 config
docker exec ${CONTAINER_NAME} bash -c "mkdir -p /etc/nupst"
# Generate config from .nogit/env.json using jq
cat ../../.nogit/env.json | jq -r '
{
\"upsList\": [
"upsList": [
{
\"id\": \"test-ups\",
\"name\": \"Test UPS\",
\"host\": \"127.0.0.1\",
\"port\": 161,
\"community\": \"public\",
\"version\": \"2c\",
\"batteryLowOID\": \"1.3.6.1.4.1.935.1.1.1.3.3.1.0\",
\"onBatteryOID\": \"1.3.6.1.4.1.935.1.1.1.3.3.2.0\",
\"shutdownCommand\": \"echo 'Shutdown triggered'\"
"id": "test-ups-v1",
"name": "Test UPS (SNMP v1)",
"host": .testConfigV1.snmp.host,
"port": .testConfigV1.snmp.port,
"community": .testConfigV1.snmp.community,
"version": (.testConfigV1.snmp.version | tostring),
"batteryLowOID": "1.3.6.1.4.1.935.1.1.1.3.3.1.0",
"onBatteryOID": "1.3.6.1.4.1.935.1.1.1.3.3.2.0",
"shutdownCommand": "echo \"Shutdown triggered for test-ups-v1\""
},
{
"id": "test-ups-v3",
"name": "Test UPS (SNMP v3)",
"host": .testConfigV3.snmp.host,
"port": .testConfigV3.snmp.port,
"version": (.testConfigV3.snmp.version | tostring),
"securityLevel": .testConfigV3.snmp.securityLevel,
"username": .testConfigV3.snmp.username,
"authProtocol": .testConfigV3.snmp.authProtocol,
"authKey": .testConfigV3.snmp.authKey,
"batteryLowOID": "1.3.6.1.4.1.935.1.1.1.3.3.1.0",
"onBatteryOID": "1.3.6.1.4.1.935.1.1.1.3.3.2.0",
"shutdownCommand": "echo \"Shutdown triggered for test-ups-v3\""
}
],
\"groups\": []
}
EOF
echo 'Dummy config created at /etc/nupst/config.json'
"
"groups": []
}' | docker exec -i ${CONTAINER_NAME} tee /etc/nupst/config.json > /dev/null
echo " ✓ Real UPS config created at /etc/nupst/config.json (from .nogit/env.json)"
echo "→ Enabling NUPST systemd service..."
docker exec ${CONTAINER_NAME} bash -c "