Skip to content

Commit 6925651

Browse files
authored
Merge pull request #1 from prisma/feat/update-readme
docs: update example workflow to show database lifecycle for PR events
2 parents 7adb0c4 + 8632fa3 commit 6925651

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,61 @@ A GitHub Action to create Prisma Postgres databases in your CI/CD workflows.
3333
database_name: "my-test-db"
3434
```
3535
36-
### Complete Example for Pull Requests
36+
### Complete Example to Provision Prisma Postgres when PR is opened and delete when PR is closed
3737
3838
```yaml
39-
name: PR Database Testing
39+
name: Prisma Postgres Database Lifecycle
4040
on:
4141
pull_request:
42-
types: [opened, reopened, synchronize]
42+
types: [opened, reopened, synchronize, closed]
4343

4444
jobs:
45-
test:
45+
create-database:
46+
name: Create Database
47+
if: github.event.action != 'closed'
4648
runs-on: ubuntu-latest
4749
steps:
48-
- uses: actions/checkout@v4
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
4952

5053
- name: Create Database
5154
id: create
5255
uses: prisma/create-prisma-postgres-database-action@v1
5356
with:
5457
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
5558
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
59+
database_name: "pr-${{ github.event.pull_request.number }}"
5660

57-
- name: Setup Database Schema
58-
env:
59-
DATABASE_URL: ${{ steps.create.outputs.database_url }}
61+
- name: Verify database creation
6062
run: |
61-
npx prisma generate
62-
npx prisma db push
63+
echo "✅ Database created successfully!"
64+
echo "Database ID: ${{ steps.create.outputs.database_id }}"
65+
echo "Database Name: ${{ steps.create.outputs.database_name }}"
66+
echo "Database URL is available in steps.create.outputs.database_url"
67+
68+
cleanup-database:
69+
name: Cleanup Database
70+
if: always() && github.event.action == 'closed'
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout repository
74+
uses: actions/checkout@v4
6375

64-
- name: Run Tests
65-
env:
66-
DATABASE_URL: ${{ steps.create.outputs.database_url }}
67-
run: npm test
76+
- name: Delete Database
77+
id: delete
78+
uses: prisma/delete-prisma-postgres-database-action@v1
79+
with:
80+
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
81+
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
82+
database_name: "pr-${{ github.event.pull_request.number }}"
83+
84+
- name: Verify database deletion
85+
run: |
86+
if [ "${{ steps.delete.outputs.deleted }}" == "true" ]; then
87+
echo "✅ Database ${{ steps.delete.outputs.database_name }} was deleted"
88+
else
89+
echo "ℹ️ No database found to delete"
90+
fi
6891
```
6992
7093
## Inputs

0 commit comments

Comments
 (0)