diff --git a/deploy/deploy-stg.sh b/deploy/deploy-stg.sh index 054eb1e2..aa1063ac 100755 --- a/deploy/deploy-stg.sh +++ b/deploy/deploy-stg.sh @@ -1,19 +1,14 @@ #!/bin/bash # Deploy staging environment for cmc-sales -# Usage: ./deploy-stg.sh [--no-cache] [--no-sync] +# Usage: ./deploy-stg.sh [--no-cache] USE_CACHE=true -RUN_SYNC=true for arg in "$@"; do if [[ "$arg" == "--no-cache" ]]; then USE_CACHE=false echo "No cache flag detected: will rebuild images without cache." fi - if [[ "$arg" == "--no-sync" ]]; then - RUN_SYNC=false - echo "No-sync flag detected: will NOT run sync_prod_to_staging.sh after deployment." - fi done if [[ "$USE_CACHE" == "true" ]]; then echo "Using cached layers for docker build." @@ -29,7 +24,7 @@ STAGING_DIR="cmc-sales-staging" echo "Connecting to server $SERVER via SSH..." # Pass variables into SSH session ssh $SERVER \ - "SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' USE_CACHE='$USE_CACHE' RUN_SYNC='$RUN_SYNC' bash -s" << 'ENDSSH' + "SERVER=$SERVER REPO='$REPO' BRANCH='$BRANCH' STAGING_DIR='$STAGING_DIR' USE_CACHE='$USE_CACHE' bash -s" << 'ENDSSH' set -e echo "Connected to $SERVER." cd /home/cmc @@ -76,40 +71,5 @@ ENVEOF fi echo "Checking running containers..." - - # 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 - 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..." - # Create sync script for staging dirs - cat > /home/cmc/sync_prod_to_staging.sh <<'EOF' -#!/bin/bash -# /home/cmc/restore_db_from_backup.sh - -# echo "Syncing PDF files..." -# rsync -av --delete --omit-dir-times --no-perms --progress /mnt/vault/pdf/ /home/cmc/cmc-sales-staging/app/webroot/pdf/ -# echo "Syncing attachments files..." -# rsync -av --delete --omit-dir-times --no-perms --progress /mnt/vault/attachments_files/ /home/cmc/cmc-sales-staging/app/webroot/attachments_files/ -# echo "Syncing emails..." -# rsync -av --delete --omit-dir-times --no-perms --progress /mnt/vault/emails/ /home/cmc/cmc-sales-staging/vault/emails/ -# echo "Syncing vaultmsgs..." -# rsync -av --delete --omit-dir-times --no-perms --progress /mnt/vault/vaultmsgs/ /home/cmc/cmc-sales-staging/vault/vaultmsgs/ -# echo "Sync complete." -EOF - chmod +x /home/cmc/sync_prod_to_staging.sh - - echo "Ensuring cron job for sync script is present..." - # Add cron job if not present - (crontab -l 2>/dev/null | grep -q '/home/cmc/sync_prod_to_staging.sh') || \ - (crontab -l 2>/dev/null; echo '0 3 * * * /home/cmc/sync_prod_to_staging.sh') | crontab - - - # if [[ "$RUN_SYNC" == "true" ]]; then - # echo "Running sync_prod_to_staging.sh now..." - # /home/cmc/sync_prod_to_staging.sh - # fi - echo "Deployment complete." ENDSSH diff --git a/deploy/scripts/run_all_migrations.sh b/deploy/scripts/run_all_migrations.sh index bf6e6bb1..7650581a 100644 --- a/deploy/scripts/run_all_migrations.sh +++ b/deploy/scripts/run_all_migrations.sh @@ -7,12 +7,13 @@ 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 + # Skip files starting with ignore_ + if [[ $(basename "$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" + docker cp "$sqlfile" cmc-db:/tmp/migration.sql + docker exec cmc-db sh -c "mariadb -u $DB_USER -p'$DB_PASS' $DB_NAME < /tmp/migration.sql" done echo "All migrations applied." diff --git a/docker-compose.stg.yml b/docker-compose.stg.yml index 5b5c3704..246ff819 100644 --- a/docker-compose.stg.yml +++ b/docker-compose.stg.yml @@ -32,6 +32,8 @@ services: networks: - cmc-stg-network restart: unless-stopped + depends_on: + - db cmc-stg-go: build: @@ -52,9 +54,13 @@ services: networks: - cmc-stg-network restart: unless-stopped + depends_on: + - db db: - image: mariadb:latest + build: + context: . + dockerfile: Dockerfile.stg.db container_name: cmc-db environment: MYSQL_ROOT_PASSWORD: secureRootPassword diff --git a/go-app/internal/cmc/email/email.go b/go-app/internal/cmc/email/email.go index 5eaabaf2..77f6fefa 100644 --- a/go-app/internal/cmc/email/email.go +++ b/go-app/internal/cmc/email/email.go @@ -53,7 +53,7 @@ func (es *EmailService) SendTemplateEmail(to string, subject string, templateNam defaultBccs := []string{"carpis@cmctechnologies.com.au", "mcarpis@cmctechnologies.com.au"} bccs = append(defaultBccs, bccs...) - const templateDir = "internal/cmc/email/templates" + const templateDir = "templates/quotes" tmplPath := fmt.Sprintf("%s/%s", templateDir, templateName) tmpl, err := template.ParseFiles(tmplPath) if err != nil { diff --git a/go-app/internal/cmc/handlers/quotes/quotes.go b/go-app/internal/cmc/handlers/quotes/quotes.go index 6e8905a2..595cdc1b 100644 --- a/go-app/internal/cmc/handlers/quotes/quotes.go +++ b/go-app/internal/cmc/handlers/quotes/quotes.go @@ -292,9 +292,9 @@ func (h *QuotesHandler) DailyQuoteExpirationCheck() { fmt.Println("Running DailyQuoteExpirationCheck...") reminderJobs := []quoteReminderJob{ - {7, FirstReminder, "Reminder: Quote %s Expires Soon", "quotes/first_reminder.html"}, - {-7, SecondReminder, "Follow-Up: Quote %s Expired", "quotes/second_reminder.html"}, - {-60, ThirdReminder, "Final Reminder: Quote %s Closed", "quotes/final_reminder.html"}, + {7, FirstReminder, "Reminder: Quote %s Expires Soon", "first_reminder.html"}, + {-7, SecondReminder, "Follow-Up: Quote %s Expired", "second_reminder.html"}, + {-60, ThirdReminder, "Final Reminder: Quote %s Closed", "final_reminder.html"}, } for _, job := range reminderJobs { diff --git a/go-app/server b/go-app/server index f66d1d27..b0db0749 100755 Binary files a/go-app/server and b/go-app/server differ diff --git a/go-app/sql/schema/014_quotes.sql b/go-app/sql/schema/014_quotes.sql index a151b970..d98b8d4d 100644 --- a/go-app/sql/schema/014_quotes.sql +++ b/go-app/sql/schema/014_quotes.sql @@ -1,6 +1,6 @@ -- cmc.quotes definition (matches existing database) -CREATE TABLE `quotes` ( +CREATE TABLE IF NOT EXISTS `quotes` ( `created` datetime NOT NULL, `modified` datetime NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, @@ -22,7 +22,7 @@ CREATE TABLE `quotes` ( ) ENGINE=MyISAM AUTO_INCREMENT=18245 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci; -- cmc.quote_reminders definition -CREATE TABLE `quote_reminders` ( +CREATE TABLE IF NOT EXISTS `quote_reminders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `quote_id` int(11) NOT NULL, `reminder_type` int(3) NOT NULL COMMENT '1=1st, 2=2nd, 3=3rd reminder', diff --git a/go-app/internal/cmc/email/templates/quotes/final_reminder.html b/go-app/templates/quotes/final_reminder.html similarity index 100% rename from go-app/internal/cmc/email/templates/quotes/final_reminder.html rename to go-app/templates/quotes/final_reminder.html diff --git a/go-app/internal/cmc/email/templates/quotes/first_reminder.html b/go-app/templates/quotes/first_reminder.html similarity index 100% rename from go-app/internal/cmc/email/templates/quotes/first_reminder.html rename to go-app/templates/quotes/first_reminder.html diff --git a/go-app/internal/cmc/email/templates/quotes/second_reminder.html b/go-app/templates/quotes/second_reminder.html similarity index 100% rename from go-app/internal/cmc/email/templates/quotes/second_reminder.html rename to go-app/templates/quotes/second_reminder.html