Skip to content

How to use PGLite with "drizzle-kit migrate"? #2532

Answered by daltonkyemiller
Vishtar asked this question in Q&A
Discussion options

You must be logged in to vote

Server Implementation

There is a migrate function exported from drizzle-orm/pglite/migrator that suffices if you're not in a browser environment.

// db.ts

import { PGlite } from "@electric-sql/pglite";
import { drizzle } from "drizzle-orm/pglite";

const client = new PGlite();

const db = drizzle(client);

export { db };
// migrate.ts

import { migrate } from "drizzle-orm/pglite/migrator"
import { db } from "./db"

await migrate(db, {
  migrationsFolder: "./drizzle/",
});

console.log("Migration complete")

Browser Implementation

However, this migrate function uses node APIs. So, if you're in the browser, you can compile the migrations to a json file and read them. Which is what I ended …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@zhanglun
Comment options

@alex-sherwin
Comment options

Answer selected by Vishtar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants