drizzle-team / drizzle-team/drizzle-orm
proposal: make drizzle-kit generate command smarter
- 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
Assessment
This issue has not been assessed yet.