drizzle-team / drizzle-team/drizzle-orm

[BUG]: unnecessary migrations generated for default values after upgrading to rc-3

Open
#5,661 1 comment 0 reactions 0 assignees View on GitHub
bug
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?

1.0.0-beta.22

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

1.0.0-beta.22

### Other packages

_No response_

### Describe the Bug

After updating to `beta-22`, running `drizzle-kit generate` creates unnecessary migrations that try to recreate unchanged tables. `drizzle-kit ` seemed to be misinterpreting the default values for SQLite in the schema for integer() and text columns

- **Tools:** `drizzle-kit` and `drizzle-orm`
- **Version:** Upgrading from `beta-4` to `beta-22`
- **Database engine:** SQLite (D1)

I have 2 types of columns affected, here's small snippets of it.

```typescript
const citext = customType<{ data: string }>({
dataType() {
return 'text COLLATE NOCASE';
},
});

export const sampleTable = sqliteTable(
'sample',
{
isDeleted: integer({ mode: 'boolean' }).notNull().default(false),
context: citext().notNull().default(''),
}
);
```

What is the undesired behavior?
Migrations were generated with unchanged schema.
Missing/ incorrect default values for `false` / empty string in migration.sql & snapshot.json

snapshot.json diff from previous migration

**For the Boolean column:**

```diff
- "default": "0",
+ "default": "false",
```

**For the Custom Type column:**

```diff
- "default": "''",
+ "default": "",
```

and the migrations.sql is has
```sql
CREATE TABLE `__new_sample` (
`is_deleted` integer DEFAULT false NOT NULL,
`context` text COLLATE NOCASE NOT NULL
);
INSERT INTO `__new_sample` --......
DROP TABLE `sample`;
ALTER TABLE `__new_sample` RENAME TO `sample`;
```

What is the desired result?
drizzle-kit shouldn't have generated migrations
the default values of the snapshot and migration should be 0 for is_deleted, empty string for text column

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.