Repopulate Demo Data #373
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Repopulate Demo Data | |
| on: | |
| schedule: | |
| - cron: "0 2 * * *" # Runs at 2 AM UTC every day | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| repopulate: | |
| name: Repopulate Demo Data | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| with: | |
| submodules: "true" | |
| - uses: actions/setup-node@v2 | |
| with: | |
| node-version: "20" | |
| - name: Install Dependencies | |
| run: npm ci | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }} | |
| aws-region: us-east-2 | |
| - name: Truncate and Repopulate Demo Data | |
| run: | | |
| # Define all modules in correct initialization order | |
| MODULES=("membership" "attendance" "content" "giving" "messaging" "doing") | |
| echo "π Truncating and repopulating demo data for all modules..." | |
| echo "π Module order: ${MODULES[*]}" | |
| # Create base .env file | |
| echo "APP_ENV=Demo" > .env | |
| # Process each module | |
| for MODULE in "${MODULES[@]}"; do | |
| echo "" | |
| echo "π§ Processing $MODULE module..." | |
| # Get module-specific connection string from Parameter Store | |
| PARAM_NAME="/demo/${MODULE}Api/connectionString" | |
| echo " π‘ Fetching connection string from $PARAM_NAME" | |
| if CONNECTION_STRING=$(aws ssm get-parameter --name "$PARAM_NAME" --with-decryption --query "Parameter.Value" --output text 2>/dev/null); then | |
| echo " β Connection string retrieved for $MODULE" | |
| # Extract database details from connection string | |
| DB_NAME=$(echo $CONNECTION_STRING | sed -n 's/.*\/\/[^:]*:[^@]*@[^:]*:[0-9]*\/\([^?]*\).*/\1/p') | |
| DB_HOST=$(echo $CONNECTION_STRING | sed -n 's/.*@\([^:]*\):[0-9]*\/.*/\1/p') | |
| DB_USER=$(echo $CONNECTION_STRING | sed -n 's/.*:\/\/\([^:]*\):.*/\1/p') | |
| DB_PASS=$(echo $CONNECTION_STRING | sed -n 's/.*:\/\/[^:]*:\([^@]*\)@.*/\1/p') | |
| echo " π§Ή Truncating data tables in database: $DB_NAME" | |
| # Truncate all tables instead of dropping the database | |
| mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e " | |
| USE \`${DB_NAME}\`; | |
| SET FOREIGN_KEY_CHECKS=0; | |
| SHOW TABLES;" | tail -n +2 | xargs -I {} mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "USE \`${DB_NAME}\`; TRUNCATE TABLE \`{}\`;" | |
| mysql -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "USE \`${DB_NAME}\`; SET FOREIGN_KEY_CHECKS=1;" | |
| # Add connection string to .env for this module | |
| echo "${MODULE^^}_CONNECTION_STRING=$CONNECTION_STRING" >> .env | |
| echo " π Populating $MODULE demo data only..." | |
| npm run populateDemo:$MODULE | |
| echo " β $MODULE module completed successfully" | |
| else | |
| echo " β οΈ No connection string found for $MODULE, skipping..." | |
| fi | |
| done | |
| echo "" | |
| echo "π All demo data has been repopulated successfully!" |