Skip to content

Delete Preview Env Database #5

Delete Preview Env Database

Delete Preview Env Database #5

Workflow file for this run

name: Delete Preview Env Database
on:
# TODO Delete this after testing
workflow_dispatch:
inputs:
db-name:
required: true
type: string
description: Database name to delete
workflow_call:
inputs:
db-name:
required: true
type: string
description: Database name to drop
jobs:
drop_database:
runs-on: [self-hosted]
steps:
- name: Set Owner
run: >-
PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}"
-c "alter database ${{ inputs.db-name }} owner to rootUser;" postgres
- name: Drop Database
run: |
PGPASSWORD="${{ secrets.DB_PASSWORD }}" dropdb -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}" ${{ inputs.db-name }}
# run: |
# PGPASSWORD="${{ secrets.DB_PASSWORD }}" psql -h "${{ secrets.RDS_ENDPOINT }}" -U "${{ secrets.DB_ROOT_USERNAME }}" -c "DROP DATABASE ${{ inputs.db-name }}" postgres
# on-failure:
# runs-on: ubuntu-latest
# if: ${{ always() && (needs.drop_database.result == 'failure' || needs.drop_database.result == 'timed_out') }}
# needs:
# - drop_database
# steps:
# - uses: actions/checkout@v4
# - name: "Send Slack message on failure"
# uses: rtCamp/action-slack-notify@v2
# env:
# SLACK_COLOR: failure
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
# SLACK_TITLE: Drop Database
# SLACK_MESSAGE: 'Error during database deletion!'
#
# on-success:
# runs-on: ubuntu-latest
# if: ${{ always() && (needs.drop_database.result == 'success') }}
# needs:
# - drop_database
# steps:
# - uses: actions/checkout@v4
# - name: "Send Slack message on success"
# uses: rtCamp/action-slack-notify@v2
# env:
# SLACK_COLOR: success
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL_TEST_WORKFLOW }}
# SLACK_TITLE: Drop Database
# SLACK_MESSAGE: 'Database deleted successfully!'