Add unique constraint to network analytics data and restart frontend script

Add a unique constraint to the network_analytics table in the Drizzle schema to prevent duplicate entries, and create a new script for restarting the frontend application.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 2676dcba-e26b-4eb4-b4a4-33d33d0c9b00
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/37PFEyl
This commit is contained in:
marco370 2025-11-24 09:13:11 +00:00
parent 4d7279a0ab
commit 3beb9d8782
2 changed files with 43 additions and 1 deletions

40
deployment/restart_frontend.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
#
# Restart IDS Frontend (Node.js/Express/Vite)
# Utility per restart manuale del server frontend
#
set -e
echo "🔄 Restart Frontend Node.js..."
# Kill processi Vite esistenti
echo "⏸️ Stopping existing processes..."
pkill -f "vite" 2>/dev/null || true
pkill -f "npm run dev" 2>/dev/null || true
sleep 2
# Verifica porta 5000 libera
if lsof -Pi :5000 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "⚠️ Porta 5000 occupata, killing processo..."
lsof -ti:5000 | xargs kill -9 2>/dev/null || true
sleep 1
fi
# Restart usando check_frontend.sh
echo "🚀 Starting frontend..."
/opt/ids/deployment/check_frontend.sh
# Attendi avvio
sleep 3
# Verifica
if pgrep -f "vite" > /dev/null; then
PID=$(pgrep -f "vite")
echo "✅ Frontend avviato con PID: $PID"
echo "📡 Server disponibile su: http://localhost:5000"
else
echo "❌ Errore: Frontend non avviato!"
echo "📋 Controlla log: tail -f /var/log/ids/frontend.log"
exit 1
fi

View File

@ -1,5 +1,5 @@
import { sql, relations } from "drizzle-orm";
import { pgTable, text, varchar, integer, timestamp, decimal, boolean, index, bigint } from "drizzle-orm/pg-core";
import { pgTable, text, varchar, integer, timestamp, decimal, boolean, index, bigint, unique } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
@ -121,6 +121,8 @@ export const networkAnalytics = pgTable("network_analytics", {
}, (table) => ({
dateHourIdx: index("network_analytics_date_hour_idx").on(table.date, table.hour),
dateIdx: index("network_analytics_date_idx").on(table.date),
// CRITICAL: Vincolo UNIQUE per ON CONFLICT in aggregator
dateHourUnique: unique("network_analytics_date_hour_key").on(table.date, table.hour),
}));
// Schema version tracking for database migrations