drizzle-team / drizzle-team/drizzle-orm

proposal: make drizzle-kit generate command smarter

Open
#3,362 2 comments 5 reactions 0 assignees View on GitHub
db/postgres drizzle/kit improvement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

let's suppose I need to change a column type from int to uuid. currently, the generated migration only changes the column type, what will break.

```sql
ALTER TABLE "users" ALTER COLUMN "id" SET DATA TYPE uuid
```

But I assume it should generate something like that:

```sql
-- Step 1: Add a new UUID column
ALTER TABLE "users" ADD COLUMN "new_id" uuid DEFAULT gen_random_uuid();

-- Step 2: Populate the new UUID column for existing rows
UPDATE "users" SET "new_id" = gen_random_uuid();

-- Step 3: Drop the original integer id column
ALTER TABLE "users" DROP COLUMN "id";

-- Step 4: Rename the new UUID column to id
ALTER TABLE "users" RENAME COLUMN "new_id" TO "id";

-- Step 5: Set the new id column as primary key (if it was previously the primary key)
ALTER TABLE "users" ADD PRIMARY KEY ("id");
```

does it make sense?

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.