Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
livingforjesus opened this issue Feb 25, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@livingforjesus
Copy link
Contributor

livingforjesus commented Feb 25, 2025

Feature hasn't been suggested before.

  • 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/[email protected]/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:

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.

@livingforjesus livingforjesus added the enhancement New feature or request label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant