drizzle-team / drizzle-team/drizzle-orm
[BUG]: Modifying a column causes WARNING DATA LOSS
- 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.29.4
### What version of `drizzle-kit` are you using?
0.20.14
### Describe the Bug
When I change a column in the schema and then run the ‘drizzle-kit push:mysql’ command, I receive an error message saying that the migration will cause data loss.”
Schema File
I altered de column user_id from varchar(28) to varchar(30)
Warning message:
THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED
Do you still want to push changes?
❯ No, abort
Yes, I want to truncate 1 table
### Expected behavior
The expected behavior was for the migration to be executed without requesting user action. I understand this to be a bug, as this migration does not cause any side effects on the database since the column was already nullable, and when I run the generated SQL directly on the database, no errors occur.
As shown:
Generated migration:
Running the generated SQL directly on the database:
### Environment & setup
Create schema:
```ts
export const assistants = mysqlTable(
"assistants",
{
id: varchar("id", { length: 29 })
.notNull()
.primaryKey()
.$defaultFn(() => createPrimaryKey("asst")),
abilities: json("abilities")
.$type()
.default([AssistantAbilities["TEXT"]]),
promptExamples: json("examples_prompt")
.$type<{ id: string; text: string }[]>()
.default([]),
createdBy: varchar("user_id", { length: 28 }).references(
() => users.id,
{ onDelete: "set null" },
),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow(),
},
(t) => ({
nameOrganizationUnique: unique().on(t.organizationId, t.name),
}),
);
```
Run commands:
`npx drizzle-kit generate:mysql`
`npx drizzle-kit push:mysql`
Alter schema:
```ts
export const assistants = mysqlTable(
"assistants",
{
id: varchar("id", { length: 29 })
.notNull()
.primaryKey()
.$defaultFn(() => createPrimaryKey("asst")),
abilities: json("abilities")
.$type()
.default([AssistantAbilities["TEXT"]]),
promptExamples: json("examples_prompt")
.$type<{ id: string; text: string }[]>()
.default([]),
createdBy: varchar("user_id", { length: 30 }).references(
() => users.id,
{ onDelete: "set null" },
),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow().onUpdateNow(),
},
(t) => ({
nameOrganizationUnique: unique().on(t.organizationId, t.name),
}),
);
```
Run commands:
`npx drizzle-kit generate:mysql`
`npx drizzle-kit push:mysql`
Contributor guide
Assessment
This issue has not been assessed yet.