A GitHub Action to delete Prisma Postgres databases in your CI/CD workflows.
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
- name: Check Result
run: |
echo "Database deleted: ${{ steps.delete.outputs.deleted }}"
echo "Database name: ${{ steps.delete.outputs.database_name }}"
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
database_name: "my-test-db"
- name: Check Result
run: echo "Database deleted: ${{ steps.delete.outputs.deleted }}"
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
database_id: "db_123456789"
- name: Check Result
run: echo "Database deleted: ${{ steps.delete.outputs.deleted }}"
name: PR Database Cleanup
on:
pull_request:
types: [closed]
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
- name: Report Results
run: |
if [ "${{ steps.delete.outputs.deleted }}" == "true" ]; then
echo "✅ Database ${{ steps.delete.outputs.database_name }} was deleted"
else
echo "ℹ️ No database found to delete"
fi
name: Prisma Postgres Database Lifecycle
on:
pull_request:
types: [opened, reopened, synchronize, closed]
jobs:
create-database:
name: Create Database
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Database
id: create
uses: prisma/create-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
database_name: "pr-${{ github.event.pull_request.number }}"
- name: Verify database creation
run: |
echo "✅ Database created successfully!"
echo "Database ID: ${{ steps.create.outputs.database_id }}"
echo "Database Name: ${{ steps.create.outputs.database_name }}"
echo "Database URL is available in steps.create.outputs.database_url"
cleanup-database:
name: Cleanup Database
if: always() && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
database_name: "pr-${{ github.event.pull_request.number }}"
- name: Verify database deletion
run: |
if [ "${{ steps.delete.outputs.deleted }}" == "true" ]; then
echo "✅ Database ${{ steps.delete.outputs.database_name }} was deleted"
else
echo "ℹ️ No database found to delete"
fi
Input | Description | Required | Default |
---|---|---|---|
service_token |
Prisma Postgres service token | ✅ | |
project_id |
Prisma project ID | ✅ | |
database_name |
Database name to delete | ❌ | Auto-generated |
database_id |
Database ID to delete (alternative to database_name) | ❌ |
Note: You can specify either database_name
or database_id
. If both are provided, database_id
takes precedence. If neither is provided, the database name will be auto-generated based on the GitHub context.
Output | Description |
---|---|
deleted |
Whether the database was deleted (true or false ) |
database_name |
The name of the database that was processed |
This action supports two ways to specify which database to delete:
- Searches for databases by name within the project
- Supports auto-detection based on GitHub context
- Names are sanitized (special characters replaced with underscores)
- Directly deletes a database using its unique ID
- Faster deletion as it skips the search step
- Useful when you have the exact database ID from previous actions
Auto-generated names:
- PR context:
pr_{pr_number}_{branch_name}
- Other contexts:
test_{run_number}
- Sign up for Prisma Postgres
- Generate a service token
To avoid conflicts with your development databases, create a dedicated project specifically for CI workflows. Use the following curl command to create a new Prisma Postgres project:
curl -X POST https://api.prisma.io/v1/projects \
-H "Authorization: Bearer $PRISMA_POSTGRES_SERVICE_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"region\": \"us-east-1\", \"name\": \"$PROJECT_NAME\"}"
Note the project ID from the response.
Go to your repository settings → Secrets and variables → Actions, and add:
PRISMA_POSTGRES_SERVICE_TOKEN
: Your Prisma Postgres service tokenPRISMA_PROJECT_ID
: Your Prisma project ID
Add the action to your workflow as shown in the examples above.
- Finds the database by name
- Deletes the database
- Returns
deleted: true
- Logs success message
- Searches for database by name
- Finds no matching database
- Returns
deleted: false
- Logs informational message
- Does not fail the workflow
Automatically clean up databases when PRs are closed:
on:
pull_request:
types: [closed]
Clean up databases when feature branches are deleted:
on:
delete:
branches: ["feature/*"]
Regular cleanup of old test databases:
on:
schedule:
- cron: "0 2 * * *" # Daily at 2 AM
On-demand database cleanup using workflow inputs:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Delete Database
id: delete
uses: prisma/delete-prisma-postgres-database-action@v1
with:
service_token: ${{ secrets.PRISMA_POSTGRES_SERVICE_TOKEN }}
project_id: ${{ secrets.PRISMA_PROJECT_ID }}
database_name: ${{ github.event.inputs.database_name }}
database_id: ${{ github.event.inputs.database_id }}
- name: Report cleanup result
run: |
if [ "${{ steps.delete.outputs.deleted }}" == "true" ]; then
echo "✅ Database ${{ steps.delete.outputs.database_name }} was deleted"
else
echo "ℹ️ No database found to delete"
fi
- Create Prisma Postgres Database Action - Create Prisma Postgres database
For issues and questions:
Apache License - see LICENSE file for details.