chore: improve DX scripts, fix test suite, and harden tooling
All checks were successful
Deploy to Production / test (push) Successful in 32s
All checks were successful
Deploy to Production / test (push) Successful in 32s
Scripts: - remote.sh: remove unused open_browser() function - deploy-remote.sh: add DB backup before deploy, --skip-backup flag, step numbering - db-backup.sh: fix macOS compat (xargs -r is GNU-only), use portable approach - db-restore.sh: add safety backup before restore, SQL file validation, file size display - logs.sh: default to no-follow with --tail=100, order-independent arg parsing - docker-cleanup.sh: add Docker health check, colored output - test-sequential.sh: exclude *.integration.test.ts by default, add --integration flag - simulate-ci.sh: pass --integration flag (has real DB) Tests: - db.test.ts: fix mock path from ./DrizzleClient to @shared/db/DrizzleClient - server.settings.test.ts: rewrite mocks for gameSettingsService (old config/saveConfig removed) - server.test.ts: add missing config.lootdrop and BotClient mocks, complete DrizzleClient chain - indexes.test.ts: rename to indexes.integration.test.ts (requires live DB) Config: - package.json: test script uses sequential runner, add test:ci and db:restore aliases - deploy.yml: use --integration flag in CI (has Postgres service)
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
# =============================================================================
|
||||
# Aurora Database Restore Script
|
||||
# =============================================================================
|
||||
# Usage: ./db-restore.sh [path/to/backup.sql]
|
||||
# Restores the database from a SQL backup file.
|
||||
# Automatically creates a safety backup before overwriting.
|
||||
#
|
||||
# Usage: ./db-restore.sh <path-to-backup.sql>
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
@@ -14,6 +17,8 @@ if [ -f .env ]; then
|
||||
set +a
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
@@ -23,6 +28,7 @@ NC='\033[0m'
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "${RED}Error: Please specify the backup file to restore.${NC}"
|
||||
echo "Usage: ./db-restore.sh <path-to-sql-file>"
|
||||
echo ""
|
||||
echo "Available backups:"
|
||||
ls -lh shared/db/backups/*.sql 2>/dev/null || echo " (No backups found in shared/db/backups)"
|
||||
exit 1
|
||||
@@ -35,29 +41,42 @@ if [ ! -f "$BACKUP_FILE" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate the backup file looks like SQL
|
||||
if ! head -1 "$BACKUP_FILE" | grep -qiE '(^--|^SET|^CREATE|^INSERT|^\\\\connect|^pg_dump)'; then
|
||||
echo -e "${YELLOW}⚠️ Warning: File does not appear to be a SQL dump.${NC}"
|
||||
read -p "Continue anyway? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Operation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}⚠️ WARNING: This will OVERWRITE the current database!${NC}"
|
||||
echo -e "Target Database: ${DB_NAME:-auroradev}"
|
||||
echo -e "Backup File: $BACKUP_FILE"
|
||||
echo -e "Backup File: $BACKUP_FILE"
|
||||
echo -e "File Size: $(du -h "$BACKUP_FILE" | cut -f1)"
|
||||
echo ""
|
||||
read -p "Are you sure you want to proceed? (y/N): " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -e "${YELLOW}♻️ Restoring database...${NC}"
|
||||
|
||||
if docker ps | grep -q aurora_db; then
|
||||
# Drop and recreate public schema to ensure clean slate, then restore
|
||||
# Note: dependent on how the dump was created. Standard pg_dump usually includes CREATE commands if configured,
|
||||
# but often it's data only or structure+data.
|
||||
# For safety, we'll just pipe the file to psql.
|
||||
|
||||
cat "$BACKUP_FILE" | docker exec -i aurora_db psql -U "${DB_USER:-auroradev}" -d "${DB_NAME:-auroradev}"
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Restore complete!"
|
||||
else
|
||||
echo -e "${RED}Error: Database container (aurora_db) is not running!${NC}"
|
||||
exit 1
|
||||
if ! docker ps | grep -q aurora_db; then
|
||||
echo -e "${RED}Error: Database container (aurora_db) is not running!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a safety backup before restoring
|
||||
echo -e "${YELLOW}💾 Creating safety backup before restore...${NC}"
|
||||
bash "$SCRIPT_DIR/db-backup.sh" || {
|
||||
echo -e "${RED}⚠️ Safety backup failed. Aborting restore.${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo -e "${YELLOW}♻️ Restoring database...${NC}"
|
||||
cat "$BACKUP_FILE" | docker exec -i aurora_db psql -U "${DB_USER:-auroradev}" -d "${DB_NAME:-auroradev}"
|
||||
|
||||
echo -e " ${GREEN}✓${NC} Restore complete!"
|
||||
else
|
||||
echo "Operation cancelled."
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user