Migrations work but Studio returns 401?

I searched github issues, discord search, SO, etc. No luck. fresh install of the boilerplate from here: https://github.com/ixartz/Next-js-Boilerplate/
No description
4 Replies
vikialbion
vikialbionOP•11mo ago
logs from https://local.drizzle.studio/ is not working:
> [email protected] db:studio
> dotenv -c -- drizzle-kit studio

drizzle-kit: v0.20.14
drizzle-orm: v0.29.3

No config path provided, using default path
Reading config file '/Users/code/vikialbion/vday-weekend/drizzle.config.ts'

Drizzle Studio is up and running on https://local.drizzle.studio
LibsqlError: SERVER_ERROR: Server returned HTTP status 401
at mapHranaError (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/client/lib-esm/hrana.js:257:16)
at HttpClient.execute (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/client/lib-esm/http.js:53:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at LibSQLPreparedQuery.all (/Users/code/vikialbion/vday-weekend/node_modules/src/libsql/session.ts:167:16)
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/index.js:248:24
at async Promise.all (index 0)
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:8293:19
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:703:9
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:6557:7
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:5808:62 {
code: 'SERVER_ERROR',
rawCode: undefined,
[cause]: HttpServerError: Server returned HTTP status 401
at errorFromResponse (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:363:12)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
status: 401
}
}
> [email protected] db:studio
> dotenv -c -- drizzle-kit studio

drizzle-kit: v0.20.14
drizzle-orm: v0.29.3

No config path provided, using default path
Reading config file '/Users/code/vikialbion/vday-weekend/drizzle.config.ts'

Drizzle Studio is up and running on https://local.drizzle.studio
LibsqlError: SERVER_ERROR: Server returned HTTP status 401
at mapHranaError (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/client/lib-esm/hrana.js:257:16)
at HttpClient.execute (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/client/lib-esm/http.js:53:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at LibSQLPreparedQuery.all (/Users/code/vikialbion/vday-weekend/node_modules/src/libsql/session.ts:167:16)
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/index.js:248:24
at async Promise.all (index 0)
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:8293:19
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:703:9
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:6557:7
at async /Users/code/vikialbion/vday-weekend/node_modules/@drizzle-team/studio/server.js:5808:62 {
code: 'SERVER_ERROR',
rawCode: undefined,
[cause]: HttpServerError: Server returned HTTP status 401
at errorFromResponse (file:///Users/code/vikialbion/vday-weekend/node_modules/@libsql/hrana-client/lib-esm/http/stream.js:363:12)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
status: 401
}
}
.env looks like this:
DATABASE_URL=libsql://[DB-NAME]-[ORG-NAME].turso.io
DATABASE_URL=libsql://[DB-NAME]-[ORG-NAME].turso.io
.env.local looks like this:
DATABASE_URL=libsql://[DB-NAME]-[ORG-NAME].turso.io
DATABASE_AUTH_TOKEN=eyxxx.eyxxx.mgxxx
DATABASE_URL=libsql://[DB-NAME]-[ORG-NAME].turso.io
DATABASE_AUTH_TOKEN=eyxxx.eyxxx.mgxxx
config:
import type { Config } from 'drizzle-kit';

/** @type {import('drizzle-kit').Config} */
export default {
schema: './src/models/Schema.ts',
out: './migrations',
driver: 'libsql',
dbCredentials: {
url: process.env.DATABASE_URL ?? '',
},
} satisfies Config;
import type { Config } from 'drizzle-kit';

/** @type {import('drizzle-kit').Config} */
export default {
schema: './src/models/Schema.ts',
out: './migrations',
driver: 'libsql',
dbCredentials: {
url: process.env.DATABASE_URL ?? '',
},
} satisfies Config;
Meanwhile, migrate works when I build using this:
/* eslint-disable no-console */
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';

async function main() {
console.log('Migration started');

const client = createClient({
url: process.env.DATABASE_URL ?? '',
authToken: process.env.DATABASE_AUTH_TOKEN ?? '',
});

const db = drizzle(client);

await migrate(db, { migrationsFolder: './migrations' });

console.log('Migration completed');

process.exit(0);
}

main().catch((error) => {
console.error('Migration failed');
console.log(error);
process.exit(1);
});
/* eslint-disable no-console */
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';

async function main() {
console.log('Migration started');

const client = createClient({
url: process.env.DATABASE_URL ?? '',
authToken: process.env.DATABASE_AUTH_TOKEN ?? '',
});

const db = drizzle(client);

await migrate(db, { migrationsFolder: './migrations' });

console.log('Migration completed');

process.exit(0);
}

main().catch((error) => {
console.error('Migration failed');
console.log(error);
process.exit(1);
});
Reaching back out
Mykhailo
Mykhailo•11mo ago
Hi, @vikialbion! I think you should update your drizzle.config.ts with turso driver and add authToken to dbCredentials:
// other params
driver: 'turso',
dbCredentials: {
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
},
// other params
driver: 'turso',
dbCredentials: {
url: process.env.TURSO_CONNECTION_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
},
vikialbion
vikialbionOP•11mo ago
Thank you! Will try that now 🙂 Perfect! Issue solved 😄 Thank you @solo
Mykhailo
Mykhailo•11mo ago
super!
Want results from more Discord servers?
Add your server