drizzle-team / drizzle-team/drizzle-orm

[BUG]: "migrate" command fails when schema already exists: Failed query CREATE SCHEMA "example"

Open
#5,274 10 comments 5 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

Beta 11

### What version of `drizzle-kit` are you using?

Beta 11

### Other packages

_No response_

### Describe the Bug

I'm running Drizzle with a self-hosted Supabase DB, where I have created schema "example" in advance and made my DB user the owner of it. I then run `drizzle-kit migrate` and get the following error: `Failed query CREATE SCHEMA "example"`. It's unsurprising that this command would fail, since the schema already exists. This should either have `IF NOT EXISTS` or there should be a config option to prevent creating the schema.

My config:

```ts
export default defineConfig({
out: "./server/db/drizzle",
schema: "./server/db/schema",
schemaFilter: ["example"],
migrations: { schema: "example" },
dialect: "postgresql",
dbCredentials: { url: process.env.DATABASE_URL },
casing: "snake_case",
strict: true,
});
```

I have checked this is not a connection issue, since `drizzle-kit push` runs just fine.

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.