This project demonstrates automated database provisioning and management using Prisma Postgres Management API integrated with GitHub Actions workflows.
The project automatically provisions temporary Prisma Postgres databases for pull requests and provides manual database management capabilities through GitHub Actions. This is useful for:
- Creating isolated database environments for each PR
- Testing database schemas and migrations
- Seeding databases with sample data
- Automatic cleanup when PRs are closed
- Automatic Database Provisioning: Creates a new Prisma Postgres database when a PR is opened
- Database Seeding: Automatically seeds the database with sample data using Prisma queries
- Automatic Cleanup: Deletes the database when a PR is closed or merged
- Manual Control: Trigger database creation/deletion manually from GitHub UI
- Smart Naming: Uses sanitized PR-based naming for databases
├── .github/workflows/
│ └── prisma-postgres-management.yml # GitHub Actions workflow
├── prisma/
│ └── schema.prisma # Prisma database schema
├── src/
│ ├── seed.ts # Database seeding script
├── package.json # Node.js dependencies
└── README.md # This file
- Prisma Postgres account
- GitHub repository with Actions enabled
- Node.js and npm
Configure the following secrets in your GitHub repository:
- PRISMA_POSTGRES_SERVICE_TOKEN: Your Prisma Postgres service token
- PRISMA_PROJECT_ID: Your Prisma project ID
- Clone the repository
- Install dependencies:
npm install
- Configure your Prisma schema in
prisma/schema.prisma
- Set up your GitHub secrets
The workflow automatically triggers on PR events:
- PR Opened/Reopened: Creates and seeds a new database
- PR Closed/Merged: Deletes the associated database
- Go to the Actions tab in your GitHub repository
- Select "Prisma Postgres Management API Workflow"
- Click "Run workflow"
- Choose your action:
- provision: Create and seed a new database
- cleanup: Delete an existing database
- Optionally specify a custom database name
The project uses a simple blog-style schema with Users and Posts:
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}
The database is automatically seeded with sample data using src/seed.ts
:
- Creates sample users (Alice and Bob)
- Creates sample posts for each user
- Demonstrates various Prisma operations
Databases are named using the format:
- PR-based:
pr-{pr_number}-{branch_name}
(sanitized) - Manual: Custom name or
test-{run_number}
- Uses GitHub secrets for sensitive tokens
- Sanitizes database names to prevent injection
- Implements proper authorization headers
- Fork the repository
- Create a feature branch
- Make your changes
- Test with the manual workflow
- Submit a pull request