A GitHub Action to create Prisma Postgres databases in your CI/CD workflows.
- 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 }}
- name: Use Database
env:
DATABASE_URL: ${{ steps.create.outputs.database_url }}
run: |
echo "Database ready: ${{ steps.create.outputs.database_name }}"
# Use the DATABASE_URL in your application
- name: Create Database
uses: prisma/create-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: 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 | ❌ | Auto-generated |
region |
Database region | ❌ | us-east-1 |
Output | Description |
---|---|
database_id |
The ID of the created/existing database |
database_name |
The name of the database |
database_url |
The DATABASE_URL for the database |
- 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.
Auto-generated names:
- PR context:
pr_{pr_number}_{branch_name}
- Other contexts:
test_{run_number}
This action only provisions the database and provides a connection string. You can use it with any database tool:
- name: Setup with Prisma
env:
DATABASE_URL: ${{ steps.provision.outputs.database_url }}
run: |
npx prisma generate
npx prisma db push
- Delete Prisma Postgres Database Action - Delete Prisma Postgres database
For issues and questions:
Apache License - see LICENSE file for details.