drizzle-team / drizzle-team/drizzle-orm
[FEATURE]:Support for Encrypted Sqlite DB file with Studio and drizzle-kit
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
First off, absolutely loving drizzle so far. As I'm about to move my project to production, I enabled encryption for my sqlite database. I found this breaks drizzle studio for local development and also the the ability to run drizzle-kit push. I believe the reason for this is that in drizzle.config.ts there is no parameter to specify ENCRYPTION_KEY under dbCredentials in defineConfig. So when studio launches or when you do a migration, it errors with SQLITE_NOTADB (since it can't read the encrypted db). It would be super nice if I could use all the cli commands and the studio with an encrypted db. For now this is how I'm managing migrations in a rather handfisted way in my db > index.ts
```
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import * as schema from './schema.js';
import { sql } from 'drizzle-orm';
import 'dotenv/config';
if (!process.env.DB_FILE_NAME) {
throw new Error('DB_FILE_NAME is not set');
}
if (!process.env.ENCRYPTION_KEY) {
throw new Error('ENCRYPTION_KEY is not set');
}
export const client = createClient({
url: `file:${process.env.DB_FILE_NAME}`,
encryptionKey: process.env.ENCRYPTION_KEY,
});
export const db = drizzle(client, { schema });
async function createTables() {
const { migrate } = await import('drizzle-orm/libsql/migrator');
await migrate(db, { migrationsFolder: './drizzle' });
console.log('Tables created successfully');
}
async function checkTables() {
const tables = await db.select({ name: sql`name` })
.from(sql`sqlite_master`)
.where(sql`type = 'table'`)
.all();
console.log('Tables in the database:', tables.map(t => t.name));
return tables.map(t => t.name);
}
createTables()
.then(checkTables)
.then((tables) => {
console.log('All tables created successfully:', tables);
})
.catch((error) => console.error('Error creating or checking tables:', error));
```
Contributor guide
Assessment
This issue has not been assessed yet.