Quote column names in indexes (#13938)

* quote column names in indexes

* quote column names in created indexes

* fix tests
This commit is contained in:
Pedro Guzman
2025-11-03 10:58:40 +01:00
committed by GitHub
parent 37563987b8
commit e66f7cf59e
4 changed files with 44 additions and 31 deletions

View File

@@ -37,7 +37,7 @@ describe("createPsqlIndexStatementHelper", function () {
expect(indexStatement.expression).toEqual(
`CREATE INDEX IF NOT EXISTS "${options.name}" ON "${
options.tableName
}" (${options.columns.join(", ")})`
}" (${options.columns.map((column) => `"${column}"`).join(", ")})`
)
})
@@ -53,7 +53,9 @@ describe("createPsqlIndexStatementHelper", function () {
expect(indexStatement.expression).toEqual(
`CREATE INDEX IF NOT EXISTS "${options.name}" ON "${
options.tableName
}" (${options.columns.join(", ")}) WHERE ${options.where}`
}" (${options.columns.map((column) => `"${column}"`).join(", ")}) WHERE ${
options.where
}`
)
})
@@ -70,7 +72,9 @@ describe("createPsqlIndexStatementHelper", function () {
expect(indexStatement.toString()).toEqual(
`CREATE INDEX IF NOT EXISTS "${options.name}" ON "${
options.tableName
}" USING GIN (${options.columns.join(", ")}) WHERE ${options.where}`
}" USING GIN (${options.columns
.map((column) => `"${column}"`)
.join(", ")}) WHERE ${options.where}`
)
})
@@ -86,7 +90,9 @@ describe("createPsqlIndexStatementHelper", function () {
expect(indexStatement.expression).toEqual(
`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_table_name_column_name_1_column_name_2_unique" ON "${
options.tableName
}" (${options.columns.join(", ")}) WHERE ${options.where}`
}" (${options.columns.map((column) => `"${column}"`).join(", ")}) WHERE ${
options.where
}`
)
})

View File

@@ -60,7 +60,9 @@ export function createPsqlIndexStatementHelper({
tableReference = `"${tableName}"`
}
columns = Array.isArray(columns) ? columns.join(", ") : columns
columns = Array.isArray(columns)
? columns.map((column) => `"${column}"`).join(", ")
: columns
name = name || `IDX_${tableName}_${columnsName}${unique ? "_unique" : ""}`
const typeStr = type ? ` USING ${type}` : ""