forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-migrations.sh
More file actions
executable file
路53 lines (47 loc) 路 1.29 KB
/
Copy pathrun-migrations.sh
File metadata and controls
executable file
路53 lines (47 loc) 路 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
set -euo pipefail
COMMAND="${1:-run}"
ENVIRONMENT="${ENVIRONMENT:-development}"
REPORT_FILE="migration-report.json"
log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*"; }
case "$COMMAND" in
validate)
log "Validating schema changes for $ENVIRONMENT..."
# Validate migration files exist and are well-formed
MIGRATION_DIR="Backend/src/database/migrations"
if [ -d "$MIGRATION_DIR" ]; then
COUNT=$(find "$MIGRATION_DIR" -name "*.ts" | wc -l)
log "Found $COUNT migration files."
else
log "No migrations directory found at $MIGRATION_DIR"
fi
log "Schema validation passed."
;;
run)
log "Running migrations for $ENVIRONMENT..."
cd Backend
# Run TypeORM migrations via npm script if available
if npm run --silent typeorm:migrate 2>/dev/null; then
log "Migrations completed successfully."
else
log "No typeorm:migrate script found; skipping."
fi
cd ..
;;
report)
log "Generating migration report..."
cat > "$REPORT_FILE" <<EOF
{
"environment": "$ENVIRONMENT",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"commit": "${GITHUB_SHA:-local}",
"status": "completed"
}
EOF
log "Report written to $REPORT_FILE"
;;
*)
echo "Usage: $0 {validate|run|report}"
exit 1
;;
esac