NeonDbError: db error: ERROR: permission denied for schema drizzle

Created a new database on neon.tech today and trying to run migrations
// src/db/migrate.ts
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import { resolve } from 'node:path';

export async function migrateLatest() {
console.log('Running migrations...');
const dbUrl: string = process.env.DATABASE_URL!;
const client = neon(dbUrl);
// const client = postgres(dbUrl, { max: 1 });

const db = drizzle(client);
// XXX(Phong): if you change `process.cwd()`, you need to change Dockerfile
const dbDir = resolve(
process.env.NODE_ENV === 'production' ? process.cwd() : __dirname,
'migrations',
);
await migrate(db, {
migrationsFolder: dbDir,
});
console.log('Migrations completed successfully');
// client.end();
}
// src/db/migrate.ts
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import { resolve } from 'node:path';

export async function migrateLatest() {
console.log('Running migrations...');
const dbUrl: string = process.env.DATABASE_URL!;
const client = neon(dbUrl);
// const client = postgres(dbUrl, { max: 1 });

const db = drizzle(client);
// XXX(Phong): if you change `process.cwd()`, you need to change Dockerfile
const dbDir = resolve(
process.env.NODE_ENV === 'production' ? process.cwd() : __dirname,
'migrations',
);
await migrate(db, {
migrationsFolder: dbDir,
});
console.log('Migrations completed successfully');
// client.end();
}
Running migrations with:
tsx src/db/migrate.ts --config=drizzle.config.ts
tsx src/db/migrate.ts --config=drizzle.config.ts
Error:
> [email protected] migrate /Users/pthieu/www/p-stack-fs
> tsx src/db/migrate.ts --config=drizzle.config.ts

Running migrations...
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/pthieu/www/p-stack-fs/node_modules/.pnpm/@[email protected]/node_modules/@neondatabase/serverless/index.js:1518
if(C===400){let{message:Q,code:j}=await S.json(),V=new Ve(Q);throw V.code=j,V}else{
^


NeonDbError: db error: ERROR: permission denied for schema drizzle

Caused by:
ERROR: permission denied for schema drizzle
...
Node.js v18.9.0
> [email protected] migrate /Users/pthieu/www/p-stack-fs
> tsx src/db/migrate.ts --config=drizzle.config.ts

Running migrations...
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/pthieu/www/p-stack-fs/node_modules/.pnpm/@[email protected]/node_modules/@neondatabase/serverless/index.js:1518
if(C===400){let{message:Q,code:j}=await S.json(),V=new Ve(Q);throw V.code=j,V}else{
^


NeonDbError: db error: ERROR: permission denied for schema drizzle

Caused by:
ERROR: permission denied for schema drizzle
...
Node.js v18.9.0
2 Replies
PGT
PGTOP17mo ago
hm so turns out if you create a new user on neon, you need to grant a bunch of permissions it's easier to use the owner user if you are doing a small/side project
Ben
Ben3mo ago
Has anyone found a solution to this? Ive switched to using the master neondb account but it still errors when i try and run the migration, telling me that i dont have permission to access the drizzle schema
Want results from more Discord servers?
Add your server