From dba8c9672ea3968ab7541ca4f8f22f13ce479d27 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:11:37 +0200 Subject: [PATCH] fix: escape default values properly in generated code --- packages/db-sqlite/src/columnToCodeConverter.ts | 2 +- packages/drizzle/src/postgres/columnToCodeConverter.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/db-sqlite/src/columnToCodeConverter.ts b/packages/db-sqlite/src/columnToCodeConverter.ts index 7bbad9a9177..bdcdba6129c 100644 --- a/packages/db-sqlite/src/columnToCodeConverter.ts +++ b/packages/db-sqlite/src/columnToCodeConverter.ts @@ -98,7 +98,7 @@ export const columnToCodeConverter: ColumnToCodeConverter = ({ if (column.type === 'jsonb' || column.type === 'geometry') { sanitizedDefault = `'${JSON.stringify(column.default)}'` } else if (typeof column.default === 'string' || column.type === 'numeric') { - sanitizedDefault = `'${column.default}'` + sanitizedDefault = JSON.stringify(column.default) } code = `${code}.default(${sanitizedDefault})` diff --git a/packages/drizzle/src/postgres/columnToCodeConverter.ts b/packages/drizzle/src/postgres/columnToCodeConverter.ts index 18b1d1143c5..1c23f104cf6 100644 --- a/packages/drizzle/src/postgres/columnToCodeConverter.ts +++ b/packages/drizzle/src/postgres/columnToCodeConverter.ts @@ -67,9 +67,9 @@ export const columnToCodeConverter: ColumnToCodeConverter = ({ } else if (column.type === 'jsonb') { sanitizedDefault = `sql\`'${JSON.stringify(column.default)}'::jsonb\`` } else if (column.type === 'numeric') { - sanitizedDefault = `sql\`${column.default}\`` - } else if (typeof column.default === 'string') { sanitizedDefault = `'${column.default}'` + } else if (typeof column.default === 'string') { + sanitizedDefault = `${JSON.stringify(column.default)}` } code = `${code}.default(${sanitizedDefault})`