Skip to content

Commit afaa277

Browse files
committed
feat: Added final clean up db step
1 parent 3f1747b commit afaa277

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

.github/workflows/cd-base.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
run: |
151151
# if something fails stop
152152
set -e
153-
for file in $(ls src/db/scripts/*.sql | sort -V); do
153+
for file in $(ls src/db/scripts/init/*.sql | sort -V); do
154154
echo "> Executing: $file"
155155
psql -h ${{ steps.db.outputs.public_ip }} \
156156
-U ${{ secrets.DB_USER }} \
@@ -171,4 +171,31 @@ jobs:
171171
deployment_env: ${{ inputs.deployment_env }}
172172
db_host: ${{ needs.deploy.outputs.db_host }}
173173
api_url: ${{ needs.deploy.outputs.api_url }}
174-
secrets: inherit # pragma: allowlist secret
174+
secrets: inherit # pragma: allowlist secret
175+
176+
cleanup-database:
177+
needs: run-integration-tests
178+
runs-on: ubuntu-latest
179+
secrets: inherit # pragma: allowlist secret
180+
if: always() && github.event.inputs.deployment_env != 'local' # run even if integration test fail
181+
steps:
182+
- uses: actions/checkout@v4
183+
184+
- name: Cleanup SPs and tables
185+
env:
186+
PGPASSWORD: ${{ secrets.DB_PASSWORD }}
187+
run: |
188+
# install postgres client
189+
sudo apt-get update && sudo apt-get install -y postgresql-client
190+
191+
# if something fails stop
192+
set -e
193+
for file in $(ls src/db/scripts/cleanup/*.sql | sort -V); do
194+
echo "> Executing: $file"
195+
psql -h ${{ steps.db.outputs.public_ip }} \
196+
-U ${{ secrets.DB_USER }} \
197+
-d ${{ secrets.DB_NAME }} \
198+
-f "$file" \
199+
-v DB_NAME=${{ secrets.DB_NAME }} \
200+
-v ON_ERROR_STOP=1
201+
done

0 commit comments

Comments
 (0)