Prisma
Use an evertap PostgreSQL or MySQL database with Prisma ORM 7. migrate dev creates its shadow database by itself, with no second URL to set.
Each evertap database runs on a PostgreSQL or MySQL instance of its own, and the user in its URL can
create and drop databases there. Prisma Migrate works as it does on a database you run yourself:
migrate dev creates its shadow database next to yours and drops it when done, so there is no
shadowDatabaseUrl to set.
Create the database
evertap create postgres myapp # or: evertap create mysql myapp
evertap env myapp >> .env.env gains the URL:
DATABASE_URL=postgres://evertap_k3x9q2m7v1ab:…@ev.internal:5432/evertap_k3x9q2m7v1abIf .env already has a DATABASE_URL, such as the sample one prisma init writes, replace that
line with the one evertap env myapp prints instead. The sample ends without a line break, so
appending to it joins the two lines into one URL Prisma cannot read.
On a laptop that reaches evertap on another machine, keep evertap connect running while you work
(Connect from your laptop).
Point Prisma at it
prisma init writes a config file, prisma7.config.ts or prisma.config.ts depending on the
version, that loads .env and reads DATABASE_URL:
import "dotenv/config";
import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: { path: "prisma/migrations" },
datasource: { url: process.env["DATABASE_URL"] },
});Set provider in schema.prisma to postgresql or mysql to match, and give the client the same
URL through its driver adapter:
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client";
export const prisma = new PrismaClient({
adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
});Migrate
npx prisma migrate dev --name initmigrate dev creates a shadow database named prisma_migrate_shadow_db_<id> on the same instance,
checks your migrations there, and drops it. prisma migrate reset empties your database and applies
every migration again. On MySQL, it empties the database but stops with "No database selected"
before applying them; run npx prisma migrate deploy after it.
Tests
Prisma has no test database of its own. Create a second database for tests and run them with its
URL; dotenv leaves a variable you set on the command line as it is.
evertap create postgres myapp-test
DATABASE_URL="$(evertap url myapp-test)" npx prisma migrate deploy
DATABASE_URL="$(evertap url myapp-test)" npm testIn CI, create it with --temporary and an API key
(CI with an API key).
Good to know
- evertap does not offer PostgreSQL's own TLS. Leave
sslmodeout of the URL, or set it todisable;sslmode=requirefails. - Through
evertap connect, connections can drop when evertap restarts or your network changes. Have the pool replace them after about 30 minutes:new PrismaPg({ connectionString: process.env.DATABASE_URL, maxLifetimeSeconds: 1800 })(Connection pools).
The evertap name and logo are not licensed with the code (section 6 of the license). You may use them to refer to evertap, but not to name or brand your own product or service, or in a way that suggests evertap made or endorses it, without permission.
evertap is an independent project. It is not affiliated with, endorsed, sponsored, supported, or certified by the owners of the software it runs, and it uses their names only to say which software that is.
- Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.
- MySQL is a registered trademark of Oracle and/or its affiliates.
- Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd.
- Other names, including Garage and Cloudflare, may be trademarks of their respective owners.