drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: drizzle-seed should support automatically resetting and pushing a new schema.

Open
#4,171 0 comments 4 reactions 0 assignees View on GitHub
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

I want to be able to reset the database, push a new schema and seed it with new values. I'd expect this to work with simply calling `reset()` and then pushing database via `execSync('npx drizzle-kit push --force')`.

However, when a table is renamed(or some other schema change) and I want to call the script above to push new schema and re-seed, reset throws an error.
```
PostgresError: relation "public.RenamedTable" does not exist
│ at ErrorResponse (node_modules/.pnpm/postgres@3.4.5/node
│ _modules/postgres/src/connection.js:788:26)
│ ....
| at TCP.onStreamRead (node:internal/stream_base_commons:191:23) {
│ severity_local: 'ERROR',
│ severity: 'ERROR',
│ code: '42P01',
│ file: 'namespace.c',
│ line: '428',
│ routine: 'RangeVarGetRelidExtended'
│ }
│  ELIFECYCLE  Command failed with exit code 1.
```

Moreover, sometimes for some other schema changes (like renaming an enum, renaming a column and changing its type) doing reset works, pushing schema --force(via code) right after works, but these schema changes aren't reflected.

Right now I'm doing this hack to get around this issue:
```ts
await db.execute(sql`DROP SCHEMA IF EXISTS public CASCADE`);
await db.execute(sql`CREATE SCHEMA public`);
execSync('npx drizzle-kit push --force')
```

I believe drizzle-seed should support this out of the box.

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.