Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Last active April 21, 2024 16:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewIngram/ae233ecd58596fd32a7ff1edcc76229a to your computer and use it in GitHub Desktop.
Save AndrewIngram/ae233ecd58596fd32a7ff1edcc76229a to your computer and use it in GitHub Desktop.
Drizzle Migration with Vercel Postgres

Generate migrations with:

pnpm drizzle-kit generate:pg

Run with:

pnpm tsx ./migrate.ts
import "dotenv/config";
import type { Config } from "drizzle-kit";
export default {
schema: "./path/to/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.POSTGRES_URL!,
},
} satisfies Config;
import { loadEnvConfig } from "@next/env";
import { drizzle } from "drizzle-orm/vercel-postgres";
import { migrate } from "drizzle-orm/vercel-postgres/migrator";
import { sql } from "@vercel/postgres";
const dev = process.env.NODE_ENV !== "production";
loadEnvConfig("./", dev);
export const db = drizzle(sql);
migrate(db, { migrationsFolder: "./drizzle" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment