drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Drizzle D1 Local Utils

Open
#3,425 6 comments 0 reactions 0 assignees View on GitHub
driver/d1 drizzle/kit enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Feature hasn't been suggested before.

- [X] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

## Dev Migrations
Currently migrating the dev DB with wranglers works like this:
`wrangler d1 migrations apply`

A better way would be to
_a:_ run wrangler to execute the drizzle migration
or
_b:_ directly modify the local sqlite file

The command could be:
`drizzle-kit migrate --local`

## Dev Studio
Also a dev studio would be nice studio operating on dev DB (again with wrangler or sqlite file) e.g.:
`drizzle-kit studio --local`

## Test Migrations
Also currently test env migrations are a mess:
```ts vitest.config.ts
// @ts-ignore
import { D1Migration, defineWorkersConfig, readD1Migrations } from '@cloudflare/vitest-pool-workers/config';
import * as path from 'node:path';

export default defineWorkersConfig(async () => {
// Read all migrations in the `migrations` directory
console.log(__dirname);
const migrationsPath = path.join(__dirname, 'drizzle');
const migrations: D1Migration[] = await readD1Migrations(migrationsPath);

return {
test: {
setupFiles: ['./test/setup.ts'],
poolOptions: {
workers: {
wrangler: {
configPath: './wrangler.toml'
},
miniflare: {
// Add a test-only binding for migrations, so we can apply them in a setup file
bindings: { TEST_MIGRATIONS: migrations }
}
}
}
}
};
});
```

```ts test/setup.ts
import { applyD1Migrations, env } from 'cloudflare:test';

// Setup files run outside isolated storage, and may be run multiple times.
// `applyD1Migrations()` only applies migrations that haven't already been
// applied, therefore it is safe to call this function here.
await applyD1Migrations(env.DB, env.TEST_MIGRATIONS);
```

I don't have a good idea for this but currently it feels like a hack.
Maybe adding this as an easy wrapper for the `@cloudflare/vitest-pool-workers/config` `defineWorkersConfig` with options to override it for more sophisticated db tests?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.