drizzle-team / drizzle-team/drizzle-orm
Bug: `drizzle-kit pull` for SQLite Generates Constraints from Comments in Schema
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
When generating a schema using `drizzle-kit pull`, a check constraint is incorrectly generated for every table, even when it should be ignored if it originated from a comment in the SQL schema definition.
### Steps to Reproduce
1. Create a SQLite database and tables using the following code:
```javascript
import { createClient } from "@libsql/client/sqlite3";
const client = createClient({ url: "file:./db-test.sqlite" });
client.execute(`CREATE TABLE IF NOT EXISTS users
(
id TEXT PRIMARY KEY,
-- CHECK (userType IN ('anonymous', 'emailPassword'))
userType TEXT NOT NULL
);
`);
client.execute(`CREATE TABLE IF NOT EXISTS demo
(
id TEXT PRIMARY KEY
);
`);
```
2. Run the following command:
```bash
drizzle-kit pull --url file:db-test.sqlite --dialect sqlite
```
3. Observe the generated schema file:
```typescript
import { sqliteTable, AnySQLiteColumn, check, text } from "drizzle-orm/sqlite-core"
import { sql } from "drizzle-orm"
export const users = sqliteTable("users", {
id: text().primaryKey(),
userType: text().notNull(),
},
(table) => {
return {
usersCheck1: check("users_check_1", sql`userType IN ('anonymous', 'emailPassword'`),
}
});
export const demo = sqliteTable("demo", {
id: text().primaryKey(),
},
(table) => {
return {
usersCheck1: check("users_check_1", sql`userType IN ('anonymous', 'emailPassword'`),
}
});
```
### Expected Behavior
The generated schema file should not include any check constraints that are commented out in the SQL schema definition. Specifically, the `usersCheck1` check constraint should not be present in the generated schema.
### Actual Behavior
The generated schema includes the `usersCheck1` check constraint for both tables, even though it was commented out in the SQL definition. Additionally, the same check constraint is incorrectly applied to the `demo` table.
### Additional Context
The expected behavior is that comments in the SQL definition, especially those containing constraints, should be ignored and not translated into schema code. This issue causes unexpected and incorrect schema generation, which could lead to errors in application logic.
Contributor guide
Assessment
This issue has not been assessed yet.