prod #123

Merged
finley merged 122 commits from prod into master 2025-11-22 17:52:40 -08:00
18 changed files with 34 additions and 31 deletions
Showing only changes of commit 52ac142907 - Show all commits

View file

@ -76,39 +76,11 @@ ENVEOF
fi
echo "Checking running containers..."
# Check containers
docker compose -f docker-compose.stg.yml ps
echo "Creating migration runner script..."
cat > /home/cmc/run_all_migrations.sh <<'EOF'
#!/bin/bash
set -e
SQL_DIR="/home/cmc/cmc-sales-staging/sql/schema"
DB_USER="cmc"
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
DB_NAME="cmc"
DB_HOST="127.0.0.1"
for sqlfile in "$SQL_DIR"/*.sql; do
echo "Running migration: $sqlfile"
mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < "$sqlfile"
done
echo "All migrations applied."
EOF
# Copy migration and restore scripts to server
cp /home/cmc/cmc-sales-staging/deploy/scripts/run_all_migrations.sh /home/cmc/run_all_migrations.sh
chmod +x /home/cmc/run_all_migrations.sh
echo "Creating restore script for database from backups..."
# Create restore script for database from backups
cat > /home/cmc/restore_db_from_backup.sh <<'EOF'
#!/bin/bash
LATEST_BACKUP=$(ls -t /backups/backup_*.sql.gz | head -n1)
echo "Restoring database from latest backup: $LATEST_BACKUP"
if [ -f "$LATEST_BACKUP" ]; then
gunzip < "$LATEST_BACKUP" | mariadb -h 127.0.0.1 -u cmc -p"xVRQI&cA?7AU=hqJ!%au" cmc
echo "Database restore complete."
else
echo "No backup file found in /backups. Skipping database restore."
fi
EOF
cp /home/cmc/cmc-sales-staging/deploy/scripts/restore_db_from_backup.sh /home/cmc/restore_db_from_backup.sh
chmod +x /home/cmc/restore_db_from_backup.sh
echo "Creating sync script for staging directories..."

View file

@ -0,0 +1,13 @@
#!/bin/bash
set -e
# Sync latest backup from production
rsync -avz -e "ssh -i ~/.ssh/cmc-old" --progress cmc@sales.cmctechnologies.com.au:~/backups /home/cmc/
LATEST_BACKUP=$(ls -t /home/cmc/backups/backup_*.sql.gz | head -n1)
echo "Restoring database from latest backup: $LATEST_BACKUP"
if [ -f "$LATEST_BACKUP" ]; then
docker cp "$LATEST_BACKUP" cmc-db:/tmp/backup.sql.gz
docker exec cmc-db sh -c "gunzip < /tmp/backup.sql.gz | mariadb -u cmc -p'xVRQI&cA?7AU=hqJ!%au' cmc"
echo "Database restore complete."
else
echo "No backup file found in /home/cmc/backups. Skipping database restore."
fi

View file

@ -0,0 +1,18 @@
#!/bin/bash
set -e
SQL_DIR="/home/cmc/cmc-sales-staging/go-app/sql/schema"
DB_USER="cmc"
DB_PASS="xVRQI&cA?7AU=hqJ!%au"
DB_NAME="cmc"
DB_HOST="127.0.0.1"
for sqlfile in "$SQL_DIR"/*.sql; do
# Skip files starting with "ignore_"
if [[ "$sqlfile" == ignore_* ]]; then
echo "Skipping ignored migration: $sqlfile"
continue
fi
echo "Running migration: $sqlfile"
mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < "$sqlfile"
done
echo "All migrations applied."