npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@farbenmeer/prisma-migrate-test

v0.3.0

Published

Factory functions for creating isolated test databases using the template-clone pattern: migrations run **once** to build a template, then each test gets a cheap clone — no repeated migration overhead.

Downloads

2,181

Readme

@farbenmeer/prisma-migrate-test

Factory functions for creating isolated test databases using the template-clone pattern: migrations run once to build a template, then each test gets a cheap clone — no repeated migration overhead.

Installation

npm install @farbenmeer/prisma-migrate-test

SQLite

Peer dependencies

npm install better-sqlite3 @prisma/adapter-better-sqlite3
npm install -D @types/better-sqlite3

Usage

import { createSqliteTestDb } from "@farbenmeer/prisma-migrate-test/sqlite";
import { PrismaClient } from "@prisma/client";
import { afterAll, afterEach, beforeAll, beforeEach } from "vitest";

let testDb: SqliteTestDb;
let prisma: PrismaClient;

beforeAll(() => {
  testDb = createSqliteTestDb({ migrationsPath: "prisma/migrations" });
});

afterAll(() => {
  testDb.cleanup();
});

beforeEach(async () => {
  prisma = new PrismaClient({ adapter: await testDb.getAdapter() });
});

afterEach(async () => {
  await prisma.$disconnect();
});

API

createSqliteTestDb(options?): SqliteTestDb

Runs all migrations once into an in-memory template, then provides cheap per-test clones written to a temp directory.

Parameters:

  • options.migrationsPath — path to the Prisma migrations folder (default: "prisma/migrations")

Returns: SqliteTestDb

  • getAdapter(): Promise<PrismaBetterSqlite3> — writes a clone of the template to disk and returns a new adapter backed by it
  • cleanup(): void — deletes the temp directory

PGlite

Peer dependencies

npm install @electric-sql/pglite pglite-prisma-adapter

Usage

Configure your Prisma schema to use the postgresql provider and generate the client with the pglite previewFeature.

import { createPgliteTestDb } from "@farbenmeer/prisma-migrate-test/pglite";
import { PrismaClient } from "@prisma/client";
import { afterAll, afterEach, beforeAll, beforeEach } from "vitest";

let testDb: PgliteTestDb;
let prisma: PrismaClient;

beforeAll(() => {
  testDb = createPgliteTestDb({ migrationsPath: "prisma/migrations" });
});

afterAll(async () => {
  await testDb.cleanup();
});

beforeEach(async () => {
  prisma = new PrismaClient({ adapter: await testDb.getAdapter() });
});

afterEach(async () => {
  await prisma.$disconnect();
});

API

createPgliteTestDb(options?): PgliteTestDb

Runs all migrations once into an in-memory PGlite instance and dumps the result, then provides cheap per-test clones restored from that dump.

Parameters:

  • options.migrationsPath — path to the Prisma migrations folder (default: "prisma/migrations")
  • options.extensions — PGlite extensions to pass to each instance (default: {})
  • options.seed — optional seed data applied after migrations. Pass a SQL string or an async function (adapter: PrismaPGlite) => Promise<void> to seed via Prisma. The seed runs once when the template is built, so every clone includes the seeded data.

Returns: PgliteTestDb

  • getAdapter(): Promise<PrismaPGlite & { reset(): Promise<void> }> — restores a clone from the dump and returns a new adapter with a reset() method that truncates all public tables
  • cleanup(): Promise<void> — closes all open PGlite instances

Seeding

// Seed with raw SQL
const testDb = createPgliteTestDb({
  seed: `INSERT INTO "User" (email, name) VALUES ('[email protected]', 'Alice')`,
});

// Seed with a function (uses the Prisma adapter)
const testDb = createPgliteTestDb({
  seed: async (adapter) => {
    const prisma = new PrismaClient({ adapter });
    await prisma.user.create({ data: { email: "[email protected]", name: "Alice" } });
    await prisma.$disconnect();
  },
});

Resetting between tests

The adapter returned by getAdapter() includes a reset() method that truncates all public tables (except _prisma_migrations):

const adapter = await testDb.getAdapter();
const prisma = new PrismaClient({ adapter });

// ... run test ...

await adapter.reset(); // truncates all tables

License

MIT