drizzle-team / drizzle-team/drizzle-orm
[BUG]: When renaming a varchar column and changing its length, drizzle generate only detect the name change and ignore the length change
- 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?
0.45.1
### What version of `drizzle-kit` are you using?
0.31.8
### Other packages
_No response_
### Describe the Bug
When renaming a varchar column and changing its length, drizzle generate only detect the name change and ignore the length change.
# How to reproduce
Create a schema like below
```ts
export const posts = pgTable(
'posts',
{
id: uuid('id').primaryKey().defaultRandom(),
name: varchar('name', { length: 255 }).notNull(),
}
)
```
Migrate with `drizzle-kit generate` & `drizzle-kit migrate`
Edit the schema.(Rename name to title and remove the length)
```ts
export const posts = pgTable(
'posts',
{
id: uuid('id').primaryKey().defaultRandom(),
title: varchar('title').notNull(),
}
)
```
Migrate with `drizzle-kit generate` & `drizzle-kit migrate`
Generated migration file
```sql
ALTER TABLE "posts" RENAME COLUMN "name" TO "title";
```
No length changes
Snapshot file
```json
{
"name": "user_api_tokens",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"title": {
"name": "token_hint",
"type": "varchar",
"primaryKey": false,
"notNull": true
},
}
}
```
Snapshot misunderstand that the length has been changed.
So the drizzle state and the actual dbtable becomes unsynced.
# Expected behavior
Generated sql should change the type of the column like the below.
```sql
ALTER TABLE "posts" RENAME COLUMN "name" TO "title";
ALTER TABLE "posts" ALTER COLUMN "title" SET DATA TYPE varchar;
```
Contributor guide
Assessment
This issue has not been assessed yet.