drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: add fromDatabase for dynamic migration
- 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
**Current**
We have access to limited functions from "drizzle-kit/api" that make possible only limited cases of dynamic migration for an embedded database like pglite.
There is no available function to make a snapshot of the current version of database.
- this is perfect for a new empty database in memory
- not suitable for the same database stored as a file : drizzle-kit is not available at runtime
```typescript
private async genPgMigration(fromSchema: Record) {
const prev = generateDrizzleJson({});
const cur = generateDrizzleJson(fromSchema);
return generateMigration(prev, cur);
}
private async applyPgMigration(migrations: string[]) {
for (const migration of migrations) {
try {
await this.pglite.exec(migration);
} catch (e) {
console.error("🚨 Error executing migration:", migration, e);
throw e;
}
}
}
```
**Desired**
Make `fromDatabase` available to "drizzle-kit/api", so that it is possible to migrate on demand from the current state of the database to the new one, without relying on the json migration files.
Contributor guide
Assessment
This issue has not been assessed yet.