|
15 | 15 | BUCKET_PROJECT_ID: ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }} |
16 | 16 | GCP_REGION: ${{ vars.MOBILITY_FEEDS_REGION }} |
17 | 17 | DB_INSTANCE_NAME: ${{ secrets.DB_INSTANCE_NAME }} |
| 18 | + DEST_DATABASE_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }} |
18 | 19 | DUMP_FILE_NAME: "prod-db-dump.sql" |
19 | | - DATABASE_NAME: "MobilityDatabase" |
| 20 | + SOURCE_DATABASE_NAME: ${{ secrets.PROD_POSTGRE_SQL_DB_NAME }} |
| 21 | + DEST_DATABASE_NAME: "testDB" |
| 22 | + DEST_DATABASE_USER: ${{ QA_POSTGRE_USER_NAME }} |
| 23 | + |
20 | 24 |
|
21 | 25 | steps: |
22 | 26 | - name: Checkout code |
|
46 | 50 | - name: GCloud Setup 2 |
47 | 51 | uses: google-github-actions/setup-gcloud@v2 |
48 | 52 |
|
49 | | - - name: Create DB dump bucket and backup QA DB |
| 53 | + - name: Create DB dump bucket and give permissions |
50 | 54 | run: | |
51 | 55 | BUCKET_PROJECT_ID=$DEST_PROJECT_ID |
52 | 56 |
|
|
68 | 72 | # Give read-write permission on the bucket to the destination sql instance |
69 | 73 | gsutil iam ch serviceAccount:$DEST_SQL_SERVICE_ACCOUNT:objectAdmin gs://$DUMP_BUCKET_NAME |
70 | 74 |
|
71 | | - # Dump the QA database as a backup |
72 | | - # According to chatgpt, |
73 | | - # This is Google's recommended, safe method and doesn’t require direct access to the DB. It runs the export |
74 | | - # in a way that avoids locking the database and works from GCP itself (so no traffic leaves GCP). |
75 | | - gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/qa-db-dump-backup.sql --database=$DATABASE_NAME --quiet |
76 | | -
|
77 | 75 | - name: Authenticate to Google Cloud PROD project Again |
78 | 76 | uses: google-github-actions/auth@v2 |
79 | 77 | with: |
|
84 | 82 |
|
85 | 83 | - name: Dump the PROD DB |
86 | 84 | run: | |
87 | | - gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$DATABASE_NAME --quiet |
| 85 | + gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$SOURCE_DATABASE_NAME --quiet |
| 86 | +
|
| 87 | + - name: Authenticate to Google Cloud QA project Again Again |
| 88 | + uses: google-github-actions/auth@v2 |
| 89 | + with: |
| 90 | + credentials_json: ${{ secrets.QA_GCP_MOBILITY_FEEDS_SA_KEY }} |
| 91 | + |
| 92 | + - name: GCloud Setup 3 |
| 93 | + uses: google-github-actions/setup-gcloud@v2 |
| 94 | + run: | |
| 95 | + # Dump the QA database as a backup |
| 96 | + # According to chatgpt, |
| 97 | + # This is Google's recommended, safe method and doesn’t require direct access to the DB. It runs the export |
| 98 | + # in a way that avoids locking the database and works from GCP itself (so no traffic leaves GCP). |
| 99 | + gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/qa-db-dump-backup.sql --database=$SOURCE_DATABASE_NAME --quiet |
| 100 | + |
| 101 | + # Import the dump into the QA database |
| 102 | + export PGPASSWORD=$DEST_DATABASE_PASSWORD |
| 103 | + gcloud sql import sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$DEST_DATABASE_NAME --user=$DEST_DATABASE_USER --quiet |
0 commit comments