|
| 1 | +--- |
| 2 | +title: Prisma Postgres |
| 3 | +description: Provision and manage Prisma Postgres databases for your Deno Deploy applications. |
| 4 | +--- |
| 5 | + |
| 6 | +Prisma Postgres is a serverless PostgreSQL database that is instantly responsive |
| 7 | +and effortlessly scalable. Built on bare metal infrastructure with zero cold |
| 8 | +starts and built-in global caching, it scales to zero when idle and handles |
| 9 | +traffic spikes seamlessly. Through Deno Deploy's database provisioning feature, |
| 10 | +you can create and manage Prisma Postgres instances that automatically integrate |
| 11 | +with your applications and their deployment environments. |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +When you provision a Prisma Postgres database and assign it to an app, Deno |
| 16 | +Deploy automatically creates separate databases for each deployment environment: |
| 17 | + |
| 18 | +- Production deployments use `{app-id}-production` |
| 19 | +- Git branches get `{app-id}--{branch-name}` |
| 20 | +- Preview deployments use `{app-id}-preview` |
| 21 | + |
| 22 | +Your code automatically connects to the correct database for each environment |
| 23 | +without requiring timeline detection or manual configuration. |
| 24 | + |
| 25 | +## Provisioning a Prisma Postgres Database |
| 26 | + |
| 27 | +### Creating the Instance |
| 28 | + |
| 29 | +1. Navigate to your organization dashboard and click "Databases" in the |
| 30 | + navigation bar. |
| 31 | +2. Click "Provision Database". |
| 32 | +3. Select "Prisma Postgres" from the available options. |
| 33 | +4. Give your database instance a name. |
| 34 | +5. Complete the provisioning flow. |
| 35 | + |
| 36 | +### Assigning to an App |
| 37 | + |
| 38 | +Once your Prisma Postgres instance is provisioned: |
| 39 | + |
| 40 | +1. From the database instances list, click "Assign" next to your Prisma Postgres |
| 41 | + instance. |
| 42 | +2. Select the app from the dropdown. |
| 43 | +3. Deno Deploy will automatically provision separate databases for production, |
| 44 | + Git branches, and preview environments. |
| 45 | +4. Monitor the provisioning status as it changes to "Connected". |
| 46 | + |
| 47 | +## Using Prisma Postgres in Your Code |
| 48 | + |
| 49 | +### Zero Configuration Required |
| 50 | + |
| 51 | +Once assigned, your code automatically connects to the correct Prisma Postgres |
| 52 | +database for each environment. Deno Deploy injects standard PostgreSQL |
| 53 | +environment variables into your runtime: |
| 54 | + |
| 55 | +- `PGHOST` - Database host (db.prisma.io) |
| 56 | +- `PGPORT` - Database port (5432) |
| 57 | +- `PGDATABASE` - Database name (automatically selected for your environment) |
| 58 | +- `PGUSER` - Database username |
| 59 | +- `PGPASSWORD` - Database password |
| 60 | +- `PGSSLMODE` - SSL mode configuration |
| 61 | +- `DATABASE_URL` - Standard PostgreSQL connection string |
| 62 | + (`postgresql://user:password@db.prisma.io:5432/database`) |
| 63 | +- `PRISMA_ACCELERATE_URL` - Connection URL for Prisma Accelerate, a global |
| 64 | + connection pooling and caching layer that provides optimized database access |
| 65 | + with reduced latency |
| 66 | + |
| 67 | +### Example with pg |
| 68 | + |
| 69 | +```typescript |
| 70 | +import { Pool } from "npm:pg"; |
| 71 | + |
| 72 | +// No configuration needed - Deno Deploy handles this automatically |
| 73 | +const pool = new Pool(); |
| 74 | + |
| 75 | +Deno.serve(async () => { |
| 76 | + const result = await pool.query("SELECT * FROM users WHERE id = $1", [123]); |
| 77 | + |
| 78 | + return new Response(JSON.stringify(result.rows), { |
| 79 | + headers: { "content-type": "application/json" }, |
| 80 | + }); |
| 81 | +}); |
| 82 | +``` |
| 83 | + |
| 84 | +### Example with Prisma ORM |
| 85 | + |
| 86 | +```typescript |
| 87 | +import { PrismaClient } from "@prisma/client"; |
| 88 | + |
| 89 | +// Prisma Client automatically uses DATABASE_URL environment variable |
| 90 | +const prisma = new PrismaClient(); |
| 91 | + |
| 92 | +Deno.serve(async () => { |
| 93 | + const users = await prisma.user.findMany(); |
| 94 | + |
| 95 | + return new Response(JSON.stringify(users), { |
| 96 | + headers: { "content-type": "application/json" }, |
| 97 | + }); |
| 98 | +}); |
| 99 | +``` |
| 100 | + |
| 101 | +## Environment-Specific Databases |
| 102 | + |
| 103 | +Each environment automatically receives its own isolated database: |
| 104 | + |
| 105 | +- **Production**: When code is deployed to production, it connects to |
| 106 | + `{app-id}-production` |
| 107 | +- **Git Branches**: Branch deployments connect to `{app-id}--{branch-name}` |
| 108 | +- **Preview Deployments**: Preview timelines connect to `{app-id}-preview` |
| 109 | + |
| 110 | +This isolation ensures production data stays safe while developing and testing. |
| 111 | + |
| 112 | +## Schema Management and Migrations |
| 113 | + |
| 114 | +Since each environment has its own database, you can safely test schema changes |
| 115 | +and migrations without affecting production data. |
| 116 | + |
| 117 | +### Using Prisma Tooling |
| 118 | + |
| 119 | +To manage your database schema with Prisma, you'll need the connection string |
| 120 | +for the specific environment database you want to work with. You can find the |
| 121 | +connection string in the database table on your database instance detail page in |
| 122 | +the Deno Deploy dashboard. |
| 123 | + |
| 124 | +#### Generate Prisma Client |
| 125 | + |
| 126 | +After defining or updating your Prisma schema, generate the Prisma Client: |
| 127 | + |
| 128 | +```bash |
| 129 | +npx prisma generate |
| 130 | +``` |
| 131 | + |
| 132 | +This creates the type-safe database client based on your schema. |
| 133 | + |
| 134 | +#### Run Migrations |
| 135 | + |
| 136 | +To apply migrations to a specific environment database, use the connection |
| 137 | +string for that environment: |
| 138 | + |
| 139 | +```bash |
| 140 | +# Apply migrations to production database |
| 141 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b-production" npx prisma migrate deploy |
| 142 | + |
| 143 | +# Apply migrations to a branch database |
| 144 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b--feature-branch" npx prisma migrate deploy |
| 145 | + |
| 146 | +# Apply migrations to preview database |
| 147 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b-preview" npx prisma migrate deploy |
| 148 | +``` |
| 149 | + |
| 150 | +For development, you can create and apply migrations interactively: |
| 151 | + |
| 152 | +```bash |
| 153 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b-dev" npx prisma migrate dev |
| 154 | +``` |
| 155 | + |
| 156 | +#### Seed the Database |
| 157 | + |
| 158 | +To populate your database with initial data using Prisma's seeding feature: |
| 159 | + |
| 160 | +```bash |
| 161 | +# Seed production database |
| 162 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b-production" npx prisma db seed |
| 163 | + |
| 164 | +# Seed branch database |
| 165 | +DATABASE_URL="postgresql://user:pass@db.prisma.io:5432/3ba03b--feature-branch" npx prisma db seed |
| 166 | +``` |
| 167 | + |
| 168 | +## Local Development |
| 169 | + |
| 170 | +When developing locally with a Prisma Postgres database from Deploy, create a |
| 171 | +`.env` file in your project root with the connection details: |
| 172 | + |
| 173 | +```bash |
| 174 | +PGHOST=db.prisma.io |
| 175 | +PGPORT=5432 |
| 176 | +PGDATABASE=3ba03b-dev |
| 177 | +PGUSER=your-username |
| 178 | +PGPASSWORD=your-password |
| 179 | +PGSSLMODE=require |
| 180 | +DATABASE_URL=postgresql://your-username:your-password@db.prisma.io:5432/3ba03b-dev |
| 181 | +``` |
| 182 | + |
| 183 | +Run your application with the `--env` flag: |
| 184 | + |
| 185 | +```bash |
| 186 | +deno run --env --allow-all main.ts |
| 187 | +``` |
| 188 | + |
| 189 | +## Managing Your Prisma Postgres Instance |
| 190 | + |
| 191 | +### Viewing Details |
| 192 | + |
| 193 | +Click on your Prisma Postgres instance in the Databases dashboard to view: |
| 194 | + |
| 195 | +- Connection information |
| 196 | +- Assigned apps |
| 197 | +- Individual databases created for each environment |
| 198 | +- Health and connection status |
| 199 | + |
| 200 | +### Claiming Your Prisma Project |
| 201 | + |
| 202 | +When you provision a Prisma Postgres database, Deno Deploy creates a free-tier |
| 203 | +project on prisma.io. This free tier includes 100K operations per month, 500 MB |
| 204 | +storage, and 5 databases. |
| 205 | + |
| 206 | +To upgrade your Prisma subscription plan and lift the free tier limits, you'll |
| 207 | +need to claim your database project on prisma.io: |
| 208 | + |
| 209 | +1. Go to your database instance detail page in the Deno Deploy dashboard. |
| 210 | +2. Click the "Claim on Prisma" button. |
| 211 | +3. You'll be guided through the Prisma project claim flow. |
| 212 | +4. Select a workspace in Prisma where you want to claim the project. |
| 213 | + |
| 214 | +Once claimed, you can manage your Prisma subscription and upgrade your plan |
| 215 | +directly through prisma.io to increase operation limits, storage capacity, and |
| 216 | +access additional features. |
| 217 | + |
| 218 | +### Status Indicators |
| 219 | + |
| 220 | +- **🟢 Connected** - All databases are ready and working |
| 221 | +- **🟡 Creating** - Databases are being provisioned |
| 222 | +- **🔴 Error** - Some databases failed to create |
| 223 | +- **⚪ Unassigned** - No apps are using this database yet |
| 224 | + |
| 225 | +### Removing App Assignments |
| 226 | + |
| 227 | +To disconnect an app from your Prisma Postgres instance: |
| 228 | + |
| 229 | +1. Go to the database detail page |
| 230 | +2. Find the app in the "Assigned Apps" table |
| 231 | +3. Click "Remove" next to the app |
| 232 | + |
| 233 | +The databases remain in your Prisma Postgres instance - only the connection |
| 234 | +between your app and the instance is removed. |
| 235 | + |
| 236 | +## Troubleshooting |
| 237 | + |
| 238 | +### Provisioning Issues |
| 239 | + |
| 240 | +**"Database creation failed"** may indicate: |
| 241 | + |
| 242 | +- Insufficient capacity or quota limits |
| 243 | +- Naming conflicts with existing databases |
| 244 | +- Temporary service issues |
| 245 | + |
| 246 | +Try using the "Fix" button to retry failed operations. |
| 247 | + |
| 248 | +### Connection Issues |
| 249 | + |
| 250 | +**"Error" status** can be resolved by: |
| 251 | + |
| 252 | +- Using the "Fix" button to retry failed operations |
| 253 | +- Checking the database detail page for more information |
| 254 | +- Verifying your app is deployed and running |
| 255 | + |
| 256 | +## Frequently Asked Questions |
| 257 | + |
| 258 | +**Q: Can multiple apps share the same Prisma Postgres instance?** |
| 259 | + |
| 260 | +Yes! Multiple apps can be assigned to the same Prisma Postgres instance. Each |
| 261 | +app gets its own isolated databases within that instance. |
| 262 | + |
| 263 | +**Q: What happens to my data when I remove an app assignment?** |
| 264 | + |
| 265 | +The databases remain in your Prisma Postgres instance. Only the connection |
| 266 | +between your app and the database is removed. |
| 267 | + |
| 268 | +**Q: How do I access my Prisma Postgres databases directly?** |
| 269 | + |
| 270 | +Use the connection details from your Deno Deploy dashboard with any PostgreSQL |
| 271 | +client tool (psql, pgAdmin, TablePlus, etc.). Connect using the specific |
| 272 | +database name shown for each environment. |
| 273 | + |
| 274 | +**Q: Can I use the same database for multiple environments?** |
| 275 | + |
| 276 | +By default, each environment gets its own database for isolation. You can |
| 277 | +override this by explicitly configuring your database connection in code, though |
| 278 | +this is not recommended for production applications. |
| 279 | + |
| 280 | +**Q: How do I delete a Prisma Postgres instance?** |
| 281 | + |
| 282 | +First remove all app assignments, then click "Delete" on the database instance. |
| 283 | +This removes the Prisma Postgres instance and all its data permanently. |
0 commit comments