fix(db-postgres): properly escape the ' character (#12590)
Fixes the issue when `defaultValue` contains `'` it'd double the amount of `'` for the `DEFAULT` statement in the generated migration
This commit is contained in:
@@ -7,14 +7,6 @@ export const withDefault = (column: RawColumn, field: FieldAffectingData): RawCo
|
||||
return column
|
||||
}
|
||||
|
||||
if (typeof field.defaultValue === 'string' && field.defaultValue.includes("'")) {
|
||||
const escapedString = field.defaultValue.replaceAll("'", "''")
|
||||
return {
|
||||
...column,
|
||||
default: escapedString,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...column,
|
||||
default: field.defaultValue,
|
||||
|
||||
@@ -260,6 +260,11 @@ export default buildConfigWithDefaults({
|
||||
type: 'point',
|
||||
defaultValue: [10, 20],
|
||||
},
|
||||
{
|
||||
name: 'escape',
|
||||
type: 'text',
|
||||
defaultValue: "Thanks, we're excited for you to join us.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1671,6 +1671,7 @@ describe('database', () => {
|
||||
expect(result.group.defaultValue).toStrictEqual('default value from database')
|
||||
expect(result.select).toStrictEqual('default')
|
||||
expect(result.point).toStrictEqual({ coordinates: [10, 20], type: 'Point' })
|
||||
expect(result.escape).toStrictEqual("Thanks, we're excited for you to join us.")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -239,6 +239,7 @@ export interface DefaultValue {
|
||||
* @maxItems 2
|
||||
*/
|
||||
point?: [number, number] | null;
|
||||
escape?: string | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -749,6 +750,7 @@ export interface DefaultValuesSelect<T extends boolean = true> {
|
||||
};
|
||||
select?: T;
|
||||
point?: T;
|
||||
escape?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "36a35217-e468-4780-becb-9146c56e3e54",
|
||||
"id": "945960df-cc37-406f-a343-58ea672a2286",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-postgres'
|
||||
import type { MigrateDownArgs, MigrateUpArgs} from '@payloadcms/db-postgres';
|
||||
|
||||
import { sql } from '@payloadcms/db-postgres'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as migration_20250428_121536 from './20250428_121536.js'
|
||||
import * as migration_20250528_153134 from './20250528_153134.js'
|
||||
|
||||
export const migrations = [
|
||||
{
|
||||
up: migration_20250428_121536.up,
|
||||
down: migration_20250428_121536.down,
|
||||
name: '20250428_121536',
|
||||
up: migration_20250528_153134.up,
|
||||
down: migration_20250528_153134.down,
|
||||
name: '20250528_153134',
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user