drizzle-team / drizzle-team/drizzle-orm

[BUG]: IF NOT EXISTS in Migrations leads to inconsistencies

Open
#2,356 0 comments 0 reactions 1 assignee Claimed by @AndriiSherman View on GitHub
drizzle/kit enhancement priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

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

0.30.10

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

0.21.2

### Describe the Bug

When generating postgres migrations, drizzle is adding `IF NOT EXISTS` to the `CREATE` statement:

Ex:

```sql
CREATE TABLE IF NOT EXISTS "rates" (
"id" text PRIMARY KEY NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"deleted_at" timestamp,
);
```

As a result, name collisions on tables do not error, and the migration applies "successfully" despite no changes. This punts detection of the issue further down the line and not during development/deployment.

### Expected behavior

I'd expect an error to be thrown and the migration aborted if I have table naming collisions. It's much easier to catch these mistakes early than waiting for errors like "unknown column YYYY in table XXXX" to be thrown from the app at runtime.

### Environment & setup

postgres, create two tables with the same name

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.