Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Issue with quoted default string values #2122

Closed
realmikesolo opened this issue Apr 7, 2024 · 2 comments
Closed

[BUG]: Issue with quoted default string values #2122

realmikesolo opened this issue Apr 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working db/postgres drizzle/kit

Comments

@realmikesolo
Copy link
Collaborator

What version of drizzle-orm are you using?

0.30.7

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

Drizzle kit incorrectly handles string values with quotes for default statement which leads to syntax errors in PostgreSQL, MySQL, and SQLite.

For this schema:

export const tests = pgTable('table', {
  id: serial('id').primaryKey(),
  column: text('name').notNull().default("Column's value"), // default value with quote
});

generates this SQL:

CREATE TABLE IF NOT EXISTS "table" (
        "id" serial PRIMARY KEY NOT NULL,
        "name" text DEFAULT 'Column's value' NOT NULL
);

which leads to this error:

error: syntax error at or near "s"

Expected behavior

The expectation is for the Drizzle kit to generate correct SQL without syntax errors for all supported dialects. Currently, there is a workaround for PostgreSQL and MySQL:

export const tests = pgTable('table', {
  id: serial('id').primaryKey(),
  column: text('name').notNull().default("Column''s value"), // '' instead of '
});

The generated SQL will correctly interpret the two single quotes as a single quote in the application

CREATE TABLE IF NOT EXISTS "table" (
        "id" serial PRIMARY KEY NOT NULL,
        "name" text DEFAULT 'Column''s value' NOT NULL
);

Environment & setup

No response

@realmikesolo realmikesolo added bug Something isn't working drizzle/kit labels Apr 7, 2024
@Louisna123
Copy link

Louisna123 commented Apr 18, 2024

I got the same issue. The shema generated from SQLite should add quotes to Default value, while it didn't.
"drizzle-orm": "^0.30.8",
"drizzle-kit": "^0.20.14",

@AndriiSherman
Copy link
Member

Was fixed in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/postgres drizzle/kit
Projects
None yet
Development

No branches or pull requests

4 participants