drizzle-team / drizzle-team/drizzle-orm
[FYI]: a workaround for default(') by drizzle-kit <1.0.0
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't has been filed before.
- [x] I have verified that the bug I'm about to report hasn't **has** been filed before.
### What version of `drizzle-orm` are you using?
0.45.2
### What version of `drizzle-kit` are you using?
0.31.10
### Other packages
_No response_
### Describe the Bug
`drizzle-kit pull` generates schema with incorrect syntax when text field with empty text `''` as a default value is present; note unclosed single quote `default(')` in schema. Despite knowing this report is a duplicate of https://github.com/drizzle-team/drizzle-orm/issues/5356 and https://github.com/drizzle-team/drizzle-orm/issues/5626, I decided to share a workaround for those who struggles with the issue because it is not fixed yet on `<1.0.0`.
```ts
export const videos = pgTable("videos", {
id: text().primaryKey().notNull(),
title: text().notNull(),
description: text().default('),
});
```
```sql
CREATE TABLE "videos" (
"id" text PRIMARY KEY,
"title" text NOT NULL,
"description" text DEFAULT '',
);
```
### Workaround (for PNPM and drizzle-kit@0.31.10 users)
1. Add patched dependency in `pnpm-workspace.yaml`
```yaml
patchedDependencies:
drizzle-kit@0.31.10: patches/drizzle-kit@0.31.10.patch
```
2. Create patch file to `patches/drizzle-kit@0.31.10.patch`
```diff
diff --git a/bin.cjs b/bin.cjs
--- a/bin.cjs
+++ b/bin.cjs
@@ -8079,6 +8079,7 @@ function escapeSingleQuotes(str) {
return str.replace(/'/g, "''");
}
function unescapeSingleQuotes(str, ignoreFirstAndLastChar) {
+ if (str === "''") return "''";
const regex = ignoreFirstAndLastChar ? /(?
Contributor guide
Research direction
Start with the `drizzle-kit pull` output and the reported `bin.cjs` workaround for `unescapeSingleQuotes`; compare the generated TypeScript with the SQL default value shown in the issue. Done means an empty text default generates valid schema syntax instead of `default(')` for the reported drizzle-kit version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100